summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-06-22 01:10:38 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-06-22 01:10:38 +0900
commit07d270c87e6f9184aea4ca17eb26e466712e8db2 (patch)
tree2dfbaa2e0d2ad0f38cb73098608f7d67a64320f8 /src
parent126a4bde612eb0e6c48cf2f13ebe3eac45cc71a8 (diff)
Require -std=c++11 and use std::shared_ptr instead of SharedHandle
Diffstat (limited to 'src')
-rw-r--r--src/AbstractAuthResolver.cc4
-rw-r--r--src/AbstractAuthResolver.h12
-rw-r--r--src/AbstractBtMessage.cc6
-rw-r--r--src/AbstractBtMessage.h16
-rw-r--r--src/AbstractCommand.cc56
-rw-r--r--src/AbstractCommand.h76
-rw-r--r--src/AbstractHttpServerResponseCommand.cc13
-rw-r--r--src/AbstractHttpServerResponseCommand.h14
-rw-r--r--src/AbstractProxyRequestCommand.cc12
-rw-r--r--src/AbstractProxyRequestCommand.h16
-rw-r--r--src/AbstractProxyResponseCommand.cc10
-rw-r--r--src/AbstractProxyResponseCommand.h12
-rw-r--r--src/AbstractSingleDiskAdaptor.cc16
-rw-r--r--src/AbstractSingleDiskAdaptor.h8
-rw-r--r--src/ActivePeerConnectionCommand.cc10
-rw-r--r--src/ActivePeerConnectionCommand.h20
-rw-r--r--src/AdaptiveFileAllocationIterator.cc4
-rw-r--r--src/AdaptiveFileAllocationIterator.h4
-rw-r--r--src/AdaptiveURISelector.cc18
-rw-r--r--src/AdaptiveURISelector.h9
-rw-r--r--src/AnnounceList.cc18
-rw-r--r--src/AnnounceList.h12
-rw-r--r--src/AnnounceTier.h2
-rw-r--r--src/AnonDiskWriterFactory.h4
-rw-r--r--src/AppleMessageDigestImpl.cc22
-rw-r--r--src/AppleMessageDigestImpl.h7
-rw-r--r--src/AsyncNameResolver.h1
-rw-r--r--src/AsyncNameResolverMan.cc3
-rw-r--r--src/AsyncNameResolverMan.h5
-rw-r--r--src/AuthConfig.cc2
-rw-r--r--src/AuthConfig.h5
-rw-r--r--src/AuthConfigFactory.cc36
-rw-r--r--src/AuthConfigFactory.h22
-rw-r--r--src/AuthResolver.h5
-rw-r--r--src/BackupIPv4ConnectCommand.cc15
-rw-r--r--src/BackupIPv4ConnectCommand.h10
-rw-r--r--src/BencodeParser.cc3
-rw-r--r--src/BitfieldMan.h2
-rw-r--r--src/BtAbortOutstandingRequestEvent.cc2
-rw-r--r--src/BtAbortOutstandingRequestEvent.h9
-rw-r--r--src/BtAllowedFastMessage.cc4
-rw-r--r--src/BtAnnounce.h6
-rw-r--r--src/BtCheckIntegrityEntry.cc8
-rw-r--r--src/BtChokeMessage.cc4
-rw-r--r--src/BtDependency.cc30
-rw-r--r--src/BtDependency.h7
-rw-r--r--src/BtExtendedMessage.cc8
-rw-r--r--src/BtExtendedMessage.h12
-rw-r--r--src/BtFileAllocationEntry.cc4
-rw-r--r--src/BtHandshakeMessage.cc4
-rw-r--r--src/BtHandshakeMessage.h2
-rw-r--r--src/BtInteractive.h7
-rw-r--r--src/BtInterestedMessage.cc6
-rw-r--r--src/BtInterestedMessage.h4
-rw-r--r--src/BtLeecherStateChoke.cc4
-rw-r--r--src/BtLeecherStateChoke.h8
-rw-r--r--src/BtMessageDispatcher.h10
-rw-r--r--src/BtMessageFactory.h45
-rw-r--r--src/BtMessageReceiver.h9
-rw-r--r--src/BtNotInterestedMessage.cc6
-rw-r--r--src/BtNotInterestedMessage.h4
-rw-r--r--src/BtPieceMessage.cc20
-rw-r--r--src/BtPieceMessage.h14
-rw-r--r--src/BtPortMessage.cc4
-rw-r--r--src/BtPostDownloadHandler.cc18
-rw-r--r--src/BtPostDownloadHandler.h2
-rw-r--r--src/BtRegistry.cc30
-rw-r--r--src/BtRegistry.h52
-rw-r--r--src/BtRequestFactory.h11
-rw-r--r--src/BtRequestMessage.cc4
-rw-r--r--src/BtSeederStateChoke.cc2
-rw-r--r--src/BtSeederStateChoke.h8
-rw-r--r--src/BtSetup.cc24
-rw-r--r--src/BtStopDownloadCommand.h11
-rw-r--r--src/BtUnchokeMessage.cc4
-rw-r--r--src/CheckIntegrityCommand.cc2
-rw-r--r--src/CheckIntegrityCommand.h7
-rw-r--r--src/CheckIntegrityDispatcherCommand.cc4
-rw-r--r--src/CheckIntegrityDispatcherCommand.h4
-rw-r--r--src/CheckIntegrityEntry.cc4
-rw-r--r--src/CheckIntegrityEntry.h8
-rw-r--r--src/ChecksumCheckIntegrityEntry.cc6
-rw-r--r--src/ChunkChecksum.h2
-rw-r--r--src/ChunkedDecodingStreamFilter.cc6
-rw-r--r--src/ChunkedDecodingStreamFilter.h6
-rw-r--r--src/ConnectCommand.cc16
-rw-r--r--src/ConnectCommand.h20
-rw-r--r--src/ConsoleStatCalc.cc16
-rw-r--r--src/ConsoleStatCalc.h3
-rw-r--r--src/Context.cc31
-rw-r--r--src/Context.h6
-rw-r--r--src/CookieStorage.cc8
-rw-r--r--src/CookieStorage.h4
-rw-r--r--src/CreateRequestCommand.cc6
-rw-r--r--src/DHTAbstractMessage.cc4
-rw-r--r--src/DHTAbstractMessage.h4
-rw-r--r--src/DHTAbstractNodeLookupTask.h40
-rw-r--r--src/DHTAbstractTask.cc2
-rw-r--r--src/DHTAbstractTask.h10
-rw-r--r--src/DHTAnnouncePeerMessage.cc10
-rw-r--r--src/DHTAnnouncePeerMessage.h6
-rw-r--r--src/DHTAnnouncePeerReplyMessage.cc8
-rw-r--r--src/DHTAnnouncePeerReplyMessage.h6
-rw-r--r--src/DHTAutoSaveCommand.cc14
-rw-r--r--src/DHTAutoSaveCommand.h11
-rw-r--r--src/DHTBucket.cc52
-rw-r--r--src/DHTBucket.h38
-rw-r--r--src/DHTBucketRefreshCommand.cc6
-rw-r--r--src/DHTBucketRefreshCommand.h15
-rw-r--r--src/DHTBucketRefreshTask.cc6
-rw-r--r--src/DHTBucketTree.cc22
-rw-r--r--src/DHTBucketTree.h16
-rw-r--r--src/DHTConnectionImpl.h8
-rw-r--r--src/DHTEntryPointNameResolveCommand.cc10
-rw-r--r--src/DHTEntryPointNameResolveCommand.h21
-rw-r--r--src/DHTFindNodeMessage.cc12
-rw-r--r--src/DHTFindNodeMessage.h6
-rw-r--r--src/DHTFindNodeReplyMessage.cc16
-rw-r--r--src/DHTFindNodeReplyMessage.h12
-rw-r--r--src/DHTGetPeersCommand.cc8
-rw-r--r--src/DHTGetPeersCommand.h22
-rw-r--r--src/DHTGetPeersMessage.cc14
-rw-r--r--src/DHTGetPeersMessage.h6
-rw-r--r--src/DHTGetPeersReplyMessage.cc18
-rw-r--r--src/DHTGetPeersReplyMessage.h18
-rw-r--r--src/DHTIDCloser.h4
-rw-r--r--src/DHTInteractionCommand.cc14
-rw-r--r--src/DHTInteractionCommand.h29
-rw-r--r--src/DHTMessage.cc4
-rw-r--r--src/DHTMessage.h14
-rw-r--r--src/DHTMessageCallback.h8
-rw-r--r--src/DHTMessageDispatcher.h16
-rw-r--r--src/DHTMessageDispatcherImpl.cc16
-rw-r--r--src/DHTMessageDispatcherImpl.h20
-rw-r--r--src/DHTMessageEntry.cc4
-rw-r--r--src/DHTMessageEntry.h12
-rw-r--r--src/DHTMessageFactory.h46
-rw-r--r--src/DHTMessageFactoryImpl.cc98
-rw-r--r--src/DHTMessageFactoryImpl.h60
-rw-r--r--src/DHTMessageReceiver.cc24
-rw-r--r--src/DHTMessageReceiver.h29
-rw-r--r--src/DHTMessageTracker.cc40
-rw-r--r--src/DHTMessageTracker.h26
-rw-r--r--src/DHTMessageTrackerEntry.cc4
-rw-r--r--src/DHTMessageTrackerEntry.h16
-rw-r--r--src/DHTNode.h1
-rw-r--r--src/DHTNodeLookupEntry.cc2
-rw-r--r--src/DHTNodeLookupEntry.h7
-rw-r--r--src/DHTNodeLookupTask.cc12
-rw-r--r--src/DHTNodeLookupTask.h8
-rw-r--r--src/DHTNodeLookupTaskCallback.cc2
-rw-r--r--src/DHTNodeLookupTaskCallback.h2
-rw-r--r--src/DHTPeerAnnounceCommand.cc2
-rw-r--r--src/DHTPeerAnnounceCommand.h7
-rw-r--r--src/DHTPeerAnnounceEntry.cc4
-rw-r--r--src/DHTPeerAnnounceEntry.h4
-rw-r--r--src/DHTPeerAnnounceStorage.cc22
-rw-r--r--src/DHTPeerAnnounceStorage.h21
-rw-r--r--src/DHTPeerLookupTask.cc24
-rw-r--r--src/DHTPeerLookupTask.h14
-rw-r--r--src/DHTPeerLookupTaskCallback.cc2
-rw-r--r--src/DHTPeerLookupTaskCallback.h2
-rw-r--r--src/DHTPingMessage.cc10
-rw-r--r--src/DHTPingMessage.h6
-rw-r--r--src/DHTPingReplyMessage.cc8
-rw-r--r--src/DHTPingReplyMessage.h6
-rw-r--r--src/DHTPingReplyMessageCallback.h2
-rw-r--r--src/DHTPingTask.cc8
-rw-r--r--src/DHTPingTask.h6
-rw-r--r--src/DHTQueryMessage.cc4
-rw-r--r--src/DHTQueryMessage.h6
-rw-r--r--src/DHTRegistry.h21
-rw-r--r--src/DHTReplaceNodeTask.cc10
-rw-r--r--src/DHTReplaceNodeTask.h10
-rw-r--r--src/DHTResponseMessage.cc4
-rw-r--r--src/DHTResponseMessage.h6
-rw-r--r--src/DHTRoutingTable.cc36
-rw-r--r--src/DHTRoutingTable.h37
-rw-r--r--src/DHTRoutingTableDeserializer.cc6
-rw-r--r--src/DHTRoutingTableDeserializer.h10
-rw-r--r--src/DHTRoutingTableSerializer.cc8
-rw-r--r--src/DHTRoutingTableSerializer.h11
-rw-r--r--src/DHTSetup.cc35
-rw-r--r--src/DHTTaskExecutor.cc2
-rw-r--r--src/DHTTaskExecutor.h9
-rw-r--r--src/DHTTaskFactory.h25
-rw-r--r--src/DHTTaskFactoryImpl.cc38
-rw-r--r--src/DHTTaskFactoryImpl.h28
-rw-r--r--src/DHTTaskQueue.h9
-rw-r--r--src/DHTTaskQueueImpl.cc6
-rw-r--r--src/DHTTaskQueueImpl.h6
-rw-r--r--src/DHTTokenUpdateCommand.cc2
-rw-r--r--src/DHTTokenUpdateCommand.h7
-rw-r--r--src/DHTUnknownMessage.cc4
-rw-r--r--src/DHTUnknownMessage.h2
-rw-r--r--src/DNSCache.cc8
-rw-r--r--src/DNSCache.h6
-rw-r--r--src/DefaultAuthResolver.cc2
-rw-r--r--src/DefaultAuthResolver.h2
-rw-r--r--src/DefaultBtAnnounce.cc32
-rw-r--r--src/DefaultBtAnnounce.h30
-rw-r--r--src/DefaultBtInteractive.cc58
-rw-r--r--src/DefaultBtInteractive.h62
-rw-r--r--src/DefaultBtMessageDispatcher.cc56
-rw-r--r--src/DefaultBtMessageDispatcher.h32
-rw-r--r--src/DefaultBtMessageFactory.cc108
-rw-r--r--src/DefaultBtMessageFactory.h62
-rw-r--r--src/DefaultBtMessageReceiver.cc19
-rw-r--r--src/DefaultBtMessageReceiver.h10
-rw-r--r--src/DefaultBtProgressInfoFile.cc20
-rw-r--r--src/DefaultBtProgressInfoFile.h19
-rw-r--r--src/DefaultBtRequestFactory.cc42
-rw-r--r--src/DefaultBtRequestFactory.h20
-rw-r--r--src/DefaultDiskWriterFactory.cc4
-rw-r--r--src/DefaultDiskWriterFactory.h2
-rw-r--r--src/DefaultExtensionMessageFactory.cc22
-rw-r--r--src/DefaultExtensionMessageFactory.h22
-rw-r--r--src/DefaultPeerStorage.cc40
-rw-r--r--src/DefaultPeerStorage.h36
-rw-r--r--src/DefaultPieceStorage.cc108
-rw-r--r--src/DefaultPieceStorage.h88
-rw-r--r--src/DiskAdaptor.h8
-rw-r--r--src/DiskWriterFactory.h5
-rw-r--r--src/DlAbortEx.cc4
-rw-r--r--src/DlAbortEx.h2
-rw-r--r--src/DlRetryEx.cc4
-rw-r--r--src/DlRetryEx.h2
-rw-r--r--src/DownloadCommand.cc28
-rw-r--r--src/DownloadCommand.h22
-rw-r--r--src/DownloadContext.cc32
-rw-r--r--src/DownloadContext.h28
-rw-r--r--src/DownloadEngine.cc64
-rw-r--r--src/DownloadEngine.h94
-rw-r--r--src/DownloadEngineFactory.cc22
-rw-r--r--src/DownloadEngineFactory.h7
-rw-r--r--src/DownloadFailureException.cc4
-rw-r--r--src/DownloadFailureException.h2
-rw-r--r--src/DownloadHandler.cc2
-rw-r--r--src/DownloadHandler.h7
-rw-r--r--src/DownloadHandlerFactory.cc24
-rw-r--r--src/DownloadHandlerFactory.h24
-rw-r--r--src/DownloadResult.h10
-rw-r--r--src/EpollEventPoll.cc16
-rw-r--r--src/EpollEventPoll.h16
-rw-r--r--src/Event.h22
-rw-r--r--src/EventPoll.h8
-rw-r--r--src/Exception.cc2
-rw-r--r--src/Exception.h6
-rw-r--r--src/ExtensionMessageFactory.h5
-rw-r--r--src/FatalException.cc4
-rw-r--r--src/FatalException.h2
-rw-r--r--src/FeatureConfig.cc12
-rw-r--r--src/FeedbackURISelector.cc8
-rw-r--r--src/FeedbackURISelector.h7
-rw-r--r--src/FileAllocationCommand.cc2
-rw-r--r--src/FileAllocationCommand.h8
-rw-r--r--src/FileAllocationDispatcherCommand.cc4
-rw-r--r--src/FileAllocationDispatcherCommand.h4
-rw-r--r--src/FileAllocationEntry.h4
-rw-r--r--src/FileAllocationIterator.h2
-rw-r--r--src/FileEntry.cc56
-rw-r--r--src/FileEntry.h38
-rw-r--r--src/FillRequestGroupCommand.cc2
-rw-r--r--src/FillRequestGroupCommand.h1
-rw-r--r--src/FtpConnection.cc16
-rw-r--r--src/FtpConnection.h22
-rw-r--r--src/FtpDownloadCommand.cc12
-rw-r--r--src/FtpDownloadCommand.h14
-rw-r--r--src/FtpFinishDownloadCommand.cc8
-rw-r--r--src/FtpFinishDownloadCommand.h10
-rw-r--r--src/FtpInitiateConnectionCommand.cc20
-rw-r--r--src/FtpInitiateConnectionCommand.h6
-rw-r--r--src/FtpNegotiationCommand.cc36
-rw-r--r--src/FtpNegotiationCommand.h22
-rw-r--r--src/FtpTunnelRequestCommand.cc8
-rw-r--r--src/FtpTunnelRequestCommand.h8
-rw-r--r--src/FtpTunnelResponseCommand.cc8
-rw-r--r--src/FtpTunnelResponseCommand.h8
-rw-r--r--src/GZipDecodingStreamFilter.cc6
-rw-r--r--src/GZipDecodingStreamFilter.h6
-rw-r--r--src/GenericParser.h1
-rw-r--r--src/GroupId.cc11
-rw-r--r--src/GroupId.h7
-rw-r--r--src/GrowSegment.cc4
-rw-r--r--src/GrowSegment.h6
-rw-r--r--src/HandshakeExtensionMessage.cc10
-rw-r--r--src/HandshakeExtensionMessage.h11
-rw-r--r--src/HaveEraseCommand.cc2
-rw-r--r--src/HttpConnection.cc32
-rw-r--r--src/HttpConnection.h34
-rw-r--r--src/HttpDownloadCommand.cc12
-rw-r--r--src/HttpDownloadCommand.h14
-rw-r--r--src/HttpHeader.h2
-rw-r--r--src/HttpHeaderProcessor.cc2
-rw-r--r--src/HttpHeaderProcessor.h7
-rw-r--r--src/HttpInitiateConnectionCommand.cc24
-rw-r--r--src/HttpInitiateConnectionCommand.h6
-rw-r--r--src/HttpListenCommand.cc2
-rw-r--r--src/HttpListenCommand.h5
-rw-r--r--src/HttpProxyRequestCommand.cc8
-rw-r--r--src/HttpProxyRequestCommand.h8
-rw-r--r--src/HttpProxyResponseCommand.cc8
-rw-r--r--src/HttpProxyResponseCommand.h8
-rw-r--r--src/HttpRequest.cc18
-rw-r--r--src/HttpRequest.h38
-rw-r--r--src/HttpRequestCommand.cc38
-rw-r--r--src/HttpRequestCommand.h14
-rw-r--r--src/HttpRequestConnectChain.h4
-rw-r--r--src/HttpResponse.cc14
-rw-r--r--src/HttpResponse.h20
-rw-r--r--src/HttpResponseCommand.cc68
-rw-r--r--src/HttpResponseCommand.h24
-rw-r--r--src/HttpServer.cc6
-rw-r--r--src/HttpServer.h24
-rw-r--r--src/HttpServerBodyCommand.cc18
-rw-r--r--src/HttpServerBodyCommand.h14
-rw-r--r--src/HttpServerCommand.cc10
-rw-r--r--src/HttpServerCommand.h14
-rw-r--r--src/HttpServerResponseCommand.cc6
-rw-r--r--src/HttpServerResponseCommand.h6
-rw-r--r--src/HttpSkipResponseCommand.cc16
-rw-r--r--src/HttpSkipResponseCommand.h18
-rw-r--r--src/InitiateConnectionCommand.cc18
-rw-r--r--src/InitiateConnectionCommand.h12
-rw-r--r--src/InitiateConnectionCommandFactory.cc4
-rw-r--r--src/InitiateConnectionCommandFactory.h8
-rw-r--r--src/InitiatorMSEHandshakeCommand.cc16
-rw-r--r--src/InitiatorMSEHandshakeCommand.h18
-rw-r--r--src/IteratableChecksumValidator.cc4
-rw-r--r--src/IteratableChecksumValidator.h13
-rw-r--r--src/IteratableChunkChecksumValidator.cc4
-rw-r--r--src/IteratableChunkChecksumValidator.h15
-rw-r--r--src/JsonParser.cc4
-rw-r--r--src/KqueueEventPoll.cc16
-rw-r--r--src/KqueueEventPoll.h16
-rw-r--r--src/LibgcryptMessageDigestImpl.cc8
-rw-r--r--src/LibgcryptMessageDigestImpl.h7
-rw-r--r--src/LibnettleMessageDigestImpl.cc8
-rw-r--r--src/LibnettleMessageDigestImpl.h7
-rw-r--r--src/LibsslMessageDigestImpl.cc8
-rw-r--r--src/LibsslMessageDigestImpl.h7
-rw-r--r--src/LibuvEventPoll.cc16
-rw-r--r--src/LibuvEventPoll.h16
-rw-r--r--src/LogFactory.cc8
-rw-r--r--src/LogFactory.h12
-rw-r--r--src/Logger.cc1
-rw-r--r--src/Logger.h5
-rw-r--r--src/LpdDispatchMessageCommand.cc2
-rw-r--r--src/LpdDispatchMessageCommand.h11
-rw-r--r--src/LpdMessage.cc2
-rw-r--r--src/LpdMessage.h7
-rw-r--r--src/LpdMessageDispatcher.h4
-rw-r--r--src/LpdMessageReceiver.cc8
-rw-r--r--src/LpdMessageReceiver.h13
-rw-r--r--src/LpdReceiveMessageCommand.cc14
-rw-r--r--src/LpdReceiveMessageCommand.h9
-rw-r--r--src/MSEHandshake.cc8
-rw-r--r--src/MSEHandshake.h18
-rw-r--r--src/Makefile.am1
-rw-r--r--src/MemoryPreDownloadHandler.h2
-rw-r--r--src/MessageDigest.cc8
-rw-r--r--src/MessageDigest.h9
-rw-r--r--src/MetadataInfo.cc10
-rw-r--r--src/MetadataInfo.h12
-rw-r--r--src/Metalink2RequestGroup.cc70
-rw-r--r--src/Metalink2RequestGroup.h18
-rw-r--r--src/MetalinkEntry.cc18
-rw-r--r--src/MetalinkEntry.h25
-rw-r--r--src/MetalinkParserController.cc2
-rw-r--r--src/MetalinkParserController.h21
-rw-r--r--src/MetalinkParserStateImpl.cc1
-rw-r--r--src/MetalinkParserStateMachine.h6
-rw-r--r--src/MetalinkPostDownloadHandler.cc14
-rw-r--r--src/MetalinkPostDownloadHandler.h2
-rw-r--r--src/Metalinker.cc8
-rw-r--r--src/Metalinker.h11
-rw-r--r--src/MultiDiskAdaptor.cc60
-rw-r--r--src/MultiDiskAdaptor.h22
-rw-r--r--src/MultiFileAllocationIterator.cc6
-rw-r--r--src/MultiFileAllocationIterator.h8
-rw-r--r--src/MultiUrlRequestInfo.cc24
-rw-r--r--src/MultiUrlRequestInfo.h26
-rw-r--r--src/NameResolveCommand.cc2
-rw-r--r--src/NameResolveCommand.h9
-rw-r--r--src/Netrc.cc14
-rw-r--r--src/Netrc.h13
-rw-r--r--src/NetrcAuthResolver.cc10
-rw-r--r--src/NetrcAuthResolver.h10
-rw-r--r--src/Notifier.cc4
-rw-r--r--src/Notifier.h8
-rw-r--r--src/NullHandle.h10
-rw-r--r--src/NullSinkStreamFilter.h6
-rw-r--r--src/NullWebSocketSessionMan.h7
-rw-r--r--src/Option.cc4
-rw-r--r--src/Option.h9
-rw-r--r--src/OptionHandler.h1
-rw-r--r--src/OptionHandlerException.cc4
-rw-r--r--src/OptionHandlerException.h2
-rw-r--r--src/OptionHandlerFactory.cc2
-rw-r--r--src/OptionHandlerImpl.cc2
-rw-r--r--src/OptionParser.cc5
-rw-r--r--src/OptionParser.h6
-rw-r--r--src/Peer.h1
-rw-r--r--src/PeerAbstractCommand.cc8
-rw-r--r--src/PeerAbstractCommand.h26
-rw-r--r--src/PeerChokeCommand.cc4
-rw-r--r--src/PeerChokeCommand.h11
-rw-r--r--src/PeerConnection.cc6
-rw-r--r--src/PeerConnection.h18
-rw-r--r--src/PeerInitiateConnectionCommand.cc10
-rw-r--r--src/PeerInitiateConnectionCommand.h14
-rw-r--r--src/PeerInteractionCommand.cc42
-rw-r--r--src/PeerInteractionCommand.h24
-rw-r--r--src/PeerListenCommand.cc4
-rw-r--r--src/PeerListenCommand.h6
-rw-r--r--src/PeerReceiveHandshakeCommand.cc16
-rw-r--r--src/PeerReceiveHandshakeCommand.h10
-rw-r--r--src/PeerStorage.h16
-rw-r--r--src/Piece.cc13
-rw-r--r--src/Piece.h8
-rw-r--r--src/PieceHashCheckIntegrityEntry.cc4
-rw-r--r--src/PieceStatMan.h2
-rw-r--r--src/PieceStorage.h46
-rw-r--r--src/PiecedSegment.cc4
-rw-r--r--src/PiecedSegment.h6
-rw-r--r--src/PollEventPoll.cc18
-rw-r--r--src/PollEventPoll.h16
-rw-r--r--src/PortEventPoll.cc16
-rw-r--r--src/PortEventPoll.h16
-rw-r--r--src/PostDownloadHandler.h2
-rw-r--r--src/PriorityPieceSelector.cc2
-rw-r--r--src/PriorityPieceSelector.h7
-rw-r--r--src/RarestPieceSelector.cc2
-rw-r--r--src/RarestPieceSelector.h7
-rw-r--r--src/ReceiverMSEHandshakeCommand.cc10
-rw-r--r--src/ReceiverMSEHandshakeCommand.h4
-rw-r--r--src/RecoverableException.cc4
-rw-r--r--src/RecoverableException.h2
-rw-r--r--src/Request.cc2
-rw-r--r--src/Request.h8
-rw-r--r--src/RequestGroup.cc88
-rw-r--r--src/RequestGroup.h78
-rw-r--r--src/RequestGroupCriteria.h1
-rw-r--r--src/RequestGroupMan.cc100
-rw-r--r--src/RequestGroupMan.h48
-rw-r--r--src/RequestSlot.h6
-rw-r--r--src/RpcMethod.cc6
-rw-r--r--src/RpcMethod.h10
-rw-r--r--src/RpcMethodFactory.cc82
-rw-r--r--src/RpcMethodFactory.h7
-rw-r--r--src/RpcMethodImpl.cc316
-rw-r--r--src/RpcMethodImpl.h96
-rw-r--r--src/RpcRequest.cc6
-rw-r--r--src/RpcRequest.h10
-rw-r--r--src/RpcResponse.cc14
-rw-r--r--src/RpcResponse.h8
-rw-r--r--src/SeedCheckCommand.cc8
-rw-r--r--src/SeedCheckCommand.h17
-rw-r--r--src/SeedCriteria.h1
-rw-r--r--src/Segment.h5
-rw-r--r--src/SegmentMan.cc96
-rw-r--r--src/SegmentMan.h60
-rw-r--r--src/SelectEventPoll.cc16
-rw-r--r--src/SelectEventPoll.h16
-rw-r--r--src/SequentialDispatcherCommand.h10
-rw-r--r--src/SequentialPicker.h17
-rw-r--r--src/ServerStat.h6
-rw-r--r--src/ServerStatMan.cc12
-rw-r--r--src/ServerStatMan.h10
-rw-r--r--src/SessionSerializer.cc24
-rw-r--r--src/SessionSerializer.h7
-rw-r--r--src/ShareRatioSeedCriteria.cc6
-rw-r--r--src/ShareRatioSeedCriteria.h14
-rw-r--r--src/SharedHandle.cc121
-rw-r--r--src/SharedHandle.h398
-rw-r--r--src/Signature.h2
-rw-r--r--src/SimpleRandomizer.cc4
-rw-r--r--src/SimpleRandomizer.h8
-rw-r--r--src/SingletonHolder.h12
-rw-r--r--src/SinkStreamFilter.cc7
-rw-r--r--src/SinkStreamFilter.h6
-rw-r--r--src/SocketBuffer.cc14
-rw-r--r--src/SocketBuffer.h15
-rw-r--r--src/SocketCore.cc12
-rw-r--r--src/SocketCore.h14
-rw-r--r--src/SocketRecvBuffer.cc3
-rw-r--r--src/SocketRecvBuffer.h9
-rw-r--r--src/StatCalc.h1
-rw-r--r--src/StreamCheckIntegrityEntry.cc4
-rw-r--r--src/StreamFileAllocationEntry.cc8
-rw-r--r--src/StreamFilter.cc4
-rw-r--r--src/StreamFilter.h15
-rw-r--r--src/TrackerWatcherCommand.cc46
-rw-r--r--src/TrackerWatcherCommand.h45
-rw-r--r--src/UDPTrackerClient.cc58
-rw-r--r--src/UDPTrackerClient.h22
-rw-r--r--src/UDPTrackerRequest.h4
-rw-r--r--src/UTMetadataDataExtensionMessage.cc4
-rw-r--r--src/UTMetadataDataExtensionMessage.h11
-rw-r--r--src/UTMetadataPostDownloadHandler.cc14
-rw-r--r--src/UTMetadataPostDownloadHandler.h2
-rw-r--r--src/UTMetadataRequestExtensionMessage.cc14
-rw-r--r--src/UTMetadataRequestExtensionMessage.h11
-rw-r--r--src/UTMetadataRequestFactory.cc10
-rw-r--r--src/UTMetadataRequestFactory.h14
-rw-r--r--src/UTPexExtensionMessage.cc12
-rw-r--r--src/UTPexExtensionMessage.h20
-rw-r--r--src/UnionSeedCriteria.cc8
-rw-r--r--src/UnionSeedCriteria.h7
-rw-r--r--src/UnknownLengthPieceStorage.cc56
-rw-r--r--src/UnknownLengthPieceStorage.h54
-rw-r--r--src/UnknownOptionException.cc4
-rw-r--r--src/UnknownOptionException.h2
-rw-r--r--src/UriListParser.cc2
-rw-r--r--src/UriListParser.h4
-rw-r--r--src/ValueBase.cc54
-rw-r--r--src/ValueBase.h55
-rw-r--r--src/ValueBaseDiskWriter.h2
-rw-r--r--src/ValueBaseStructParserStateImpl.cc3
-rw-r--r--src/ValueBaseStructParserStateMachine.cc8
-rw-r--r--src/ValueBaseStructParserStateMachine.h13
-rw-r--r--src/WebSocketInteractionCommand.cc8
-rw-r--r--src/WebSocketInteractionCommand.h11
-rw-r--r--src/WebSocketResponseCommand.cc8
-rw-r--r--src/WebSocketResponseCommand.h6
-rw-r--r--src/WebSocketSession.cc13
-rw-r--r--src/WebSocketSession.h11
-rw-r--r--src/WebSocketSessionMan.cc13
-rw-r--r--src/WebSocketSessionMan.h8
-rw-r--r--src/WrDiskCache.cc13
-rw-r--r--src/WrDiskCacheEntry.cc4
-rw-r--r--src/WrDiskCacheEntry.h6
-rw-r--r--src/XmlRpcDiskWriter.cc4
-rw-r--r--src/XmlRpcRequestParserController.cc4
-rw-r--r--src/XmlRpcRequestParserController.h6
-rw-r--r--src/XmlRpcRequestParserStateMachine.cc4
-rw-r--r--src/XmlRpcRequestParserStateMachine.h7
-rw-r--r--src/a2functional.h20
-rw-r--r--src/aria2api.cc120
-rw-r--r--src/aria2api.h5
-rw-r--r--src/bencode2.cc10
-rw-r--r--src/bencode2.h10
-rw-r--r--src/bittorrent_helper.cc99
-rw-r--r--src/bittorrent_helper.h68
-rw-r--r--src/console.h6
-rw-r--r--src/download_helper.cc124
-rw-r--r--src/download_helper.h41
-rw-r--r--src/json.cc2
-rw-r--r--src/json.h4
-rw-r--r--src/magnet.cc6
-rw-r--r--src/magnet.h8
-rw-r--r--src/main.cc1
-rw-r--r--src/message_digest_helper.cc6
-rw-r--r--src/message_digest_helper.h9
-rw-r--r--src/metalink_helper.cc28
-rw-r--r--src/metalink_helper.h14
-rw-r--r--src/option_processing.cc10
-rw-r--r--src/rpc_helper.cc18
-rw-r--r--src/rpc_helper.h5
-rw-r--r--src/util.cc20
-rw-r--r--src/util.h12
-rw-r--r--src/version_usage.cc3
562 files changed, 4431 insertions, 4898 deletions
diff --git a/src/AbstractAuthResolver.cc b/src/AbstractAuthResolver.cc
index 2b273cb9..a9730f3d 100644
--- a/src/AbstractAuthResolver.cc
+++ b/src/AbstractAuthResolver.cc
@@ -42,13 +42,13 @@ AbstractAuthResolver::AbstractAuthResolver() {}
AbstractAuthResolver::~AbstractAuthResolver() {}
void AbstractAuthResolver::setUserDefinedAuthConfig
-(const SharedHandle<AuthConfig>& authConfig)
+(const std::shared_ptr<AuthConfig>& authConfig)
{
userDefinedAuthConfig_ = authConfig;
}
void AbstractAuthResolver::setDefaultAuthConfig
-(const SharedHandle<AuthConfig>& authConfig)
+(const std::shared_ptr<AuthConfig>& authConfig)
{
defaultAuthConfig_ = authConfig;
}
diff --git a/src/AbstractAuthResolver.h b/src/AbstractAuthResolver.h
index 93e73b87..4801490f 100644
--- a/src/AbstractAuthResolver.h
+++ b/src/AbstractAuthResolver.h
@@ -41,24 +41,24 @@ namespace aria2 {
class AbstractAuthResolver : public AuthResolver {
private:
- SharedHandle<AuthConfig> userDefinedAuthConfig_;
+ std::shared_ptr<AuthConfig> userDefinedAuthConfig_;
- SharedHandle<AuthConfig> defaultAuthConfig_;
+ std::shared_ptr<AuthConfig> defaultAuthConfig_;
public:
AbstractAuthResolver();
virtual ~AbstractAuthResolver();
- void setUserDefinedAuthConfig(const SharedHandle<AuthConfig>& authConfig);
+ void setUserDefinedAuthConfig(const std::shared_ptr<AuthConfig>& authConfig);
- const SharedHandle<AuthConfig>& getUserDefinedAuthConfig() const
+ const std::shared_ptr<AuthConfig>& getUserDefinedAuthConfig() const
{
return userDefinedAuthConfig_;
}
- void setDefaultAuthConfig(const SharedHandle<AuthConfig>& authConfig);
+ void setDefaultAuthConfig(const std::shared_ptr<AuthConfig>& authConfig);
- const SharedHandle<AuthConfig>& getDefaultAuthConfig() const
+ const std::shared_ptr<AuthConfig>& getDefaultAuthConfig() const
{
return defaultAuthConfig_;
}
diff --git a/src/AbstractBtMessage.cc b/src/AbstractBtMessage.cc
index 55177370..f4fef342 100644
--- a/src/AbstractBtMessage.cc
+++ b/src/AbstractBtMessage.cc
@@ -54,7 +54,7 @@ AbstractBtMessage::AbstractBtMessage(uint8_t id, const char* name)
AbstractBtMessage::~AbstractBtMessage() {}
-void AbstractBtMessage::setPeer(const SharedHandle<Peer>& peer)
+void AbstractBtMessage::setPeer(const std::shared_ptr<Peer>& peer)
{
peer_ = peer;
}
@@ -67,12 +67,12 @@ void AbstractBtMessage::validate()
}
void
-AbstractBtMessage::setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator) {
+AbstractBtMessage::setBtMessageValidator(const std::shared_ptr<BtMessageValidator>& validator) {
validator_ = validator;
}
void AbstractBtMessage::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
diff --git a/src/AbstractBtMessage.h b/src/AbstractBtMessage.h
index c34269e7..49a1b2ed 100644
--- a/src/AbstractBtMessage.h
+++ b/src/AbstractBtMessage.h
@@ -56,9 +56,9 @@ private:
const char* name_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
BtMessageDispatcher* dispatcher_;
@@ -68,11 +68,11 @@ private:
PeerConnection* peerConnection_;
- SharedHandle<BtMessageValidator> validator_;
+ std::shared_ptr<BtMessageValidator> validator_;
bool metadataGetMode_;
protected:
- const SharedHandle<PieceStorage>& getPieceStorage() const
+ const std::shared_ptr<PieceStorage>& getPieceStorage() const
{
return pieceStorage_;
}
@@ -130,12 +130,12 @@ public:
cuid_ = cuid;
}
- const SharedHandle<Peer>& getPeer() const
+ const std::shared_ptr<Peer>& getPeer() const
{
return peer_;
}
- void setPeer(const SharedHandle<Peer>& peer);
+ void setPeer(const std::shared_ptr<Peer>& peer);
virtual void doReceivedAction() {}
@@ -151,9 +151,9 @@ public:
virtual void onChokingEvent(const BtChokingEvent& event) {}
- void setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator);
+ void setBtMessageValidator(const std::shared_ptr<BtMessageValidator>& validator);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc
index 9e253025..bb078495 100644
--- a/src/AbstractCommand.cc
+++ b/src/AbstractCommand.cc
@@ -79,12 +79,12 @@ namespace aria2 {
AbstractCommand::AbstractCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s,
- const SharedHandle<SocketRecvBuffer>& socketRecvBuffer,
+ const std::shared_ptr<SocketCore>& s,
+ const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer,
bool incNumConnection)
: Command(cuid), checkPoint_(global::wallclock()),
timeout_(requestGroup->getTimeout()),
@@ -125,7 +125,7 @@ AbstractCommand::~AbstractCommand() {
}
void AbstractCommand::useFasterRequest
-(const SharedHandle<Request>& fasterRequest)
+(const std::shared_ptr<Request>& fasterRequest)
{
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Use faster Request hostname=%s, port=%u",
getCuid(),
@@ -180,7 +180,7 @@ bool AbstractCommand::execute() {
if(req_ && fileEntry_->countPooledRequest() > 0 &&
requestGroup_->getTotalLength()-requestGroup_->getCompletedLength()
< calculateMinSplitSize()*2) {
- SharedHandle<Request> fasterRequest = fileEntry_->findFasterRequest(req_);
+ std::shared_ptr<Request> fasterRequest = fileEntry_->findFasterRequest(req_);
if(fasterRequest) {
useFasterRequest(fasterRequest);
return true;
@@ -197,7 +197,7 @@ bool AbstractCommand::execute() {
if(getOption()->getAsBool(PREF_SELECT_LEAST_USED_HOST)) {
getDownloadEngine()->getRequestGroupMan()->getUsedHosts(usedHosts);
}
- SharedHandle<Request> fasterRequest =
+ std::shared_ptr<Request> fasterRequest =
fileEntry_->findFasterRequest
(req_, usedHosts, e_->getRequestGroupMan()->getServerStatMan());
if(fasterRequest) {
@@ -230,7 +230,7 @@ bool AbstractCommand::execute() {
size_t maxSegments = req_?req_->getMaxPipelinedRequest():1;
size_t minSplitSize = calculateMinSplitSize();
while(segments_.size() < maxSegments) {
- SharedHandle<Segment> segment =
+ std::shared_ptr<Segment> segment =
getSegmentMan()->getSegment(getCuid(), minSplitSize);
if(!segment) {
break;
@@ -276,7 +276,7 @@ bool AbstractCommand::execute() {
} else {
if(checkPoint_.difference(global::wallclock()) >= timeout_) {
// timeout triggers ServerStat error state.
- SharedHandle<ServerStat> ss =
+ std::shared_ptr<ServerStat> ss =
e_->getRequestGroupMan()->getOrCreateServerStat(req_->getHost(),
req_->getProtocol());
ss->setError();
@@ -375,7 +375,7 @@ bool AbstractCommand::execute() {
void AbstractCommand::tryReserved() {
if(getDownloadContext()->getFileEntries().size() == 1) {
- const SharedHandle<FileEntry>& entry =
+ const std::shared_ptr<FileEntry>& entry =
getDownloadContext()->getFirstFileEntry();
// Don't create new command if currently file length is unknown
// and there are no URI left. Because file length is unknown, we
@@ -490,7 +490,7 @@ void AbstractCommand::disableReadCheckSocket() {
}
void AbstractCommand::setReadCheckSocket
-(const SharedHandle<SocketCore>& socket) {
+(const std::shared_ptr<SocketCore>& socket) {
if(!socket->isOpen()) {
disableReadCheckSocket();
} else {
@@ -509,7 +509,7 @@ void AbstractCommand::setReadCheckSocket
}
void AbstractCommand::setReadCheckSocketIf
-(const SharedHandle<SocketCore>& socket, bool pred)
+(const std::shared_ptr<SocketCore>& socket, bool pred)
{
if(pred) {
setReadCheckSocket(socket);
@@ -527,7 +527,7 @@ void AbstractCommand::disableWriteCheckSocket() {
}
void AbstractCommand::setWriteCheckSocket
-(const SharedHandle<SocketCore>& socket) {
+(const std::shared_ptr<SocketCore>& socket) {
if(!socket->isOpen()) {
disableWriteCheckSocket();
} else {
@@ -546,7 +546,7 @@ void AbstractCommand::setWriteCheckSocket
}
void AbstractCommand::setWriteCheckSocketIf
-(const SharedHandle<SocketCore>& socket, bool pred)
+(const std::shared_ptr<SocketCore>& socket, bool pred)
{
if(pred) {
setWriteCheckSocket(socket);
@@ -555,7 +555,7 @@ void AbstractCommand::setWriteCheckSocketIf
}
}
-void AbstractCommand::swapSocket(SharedHandle<SocketCore>& socket)
+void AbstractCommand::swapSocket(std::shared_ptr<SocketCore>& socket)
{
disableReadCheckSocket();
disableWriteCheckSocket();
@@ -634,7 +634,7 @@ namespace {
// Returns true if proxy is defined for the given protocol. Otherwise
// returns false.
bool isProxyRequest
-(const std::string& protocol, const SharedHandle<Option>& option)
+(const std::string& protocol, const std::shared_ptr<Option>& option)
{
std::string proxyUri = getProxyUri(protocol, option.get());
return !proxyUri.empty();
@@ -642,7 +642,7 @@ bool isProxyRequest
} // namespace
namespace {
-bool inNoProxy(const SharedHandle<Request>& req,
+bool inNoProxy(const std::shared_ptr<Request>& req,
const std::string& noProxy)
{
std::vector<Scip> entries;
@@ -685,9 +685,9 @@ bool AbstractCommand::isProxyDefined() const
!inNoProxy(req_, getOption()->get(PREF_NO_PROXY));
}
-SharedHandle<Request> AbstractCommand::createProxyRequest() const
+std::shared_ptr<Request> AbstractCommand::createProxyRequest() const
{
- SharedHandle<Request> proxyRequest;
+ std::shared_ptr<Request> proxyRequest;
if(inNoProxy(req_, getOption()->get(PREF_NO_PROXY))) {
return proxyRequest;
}
@@ -772,7 +772,7 @@ std::string AbstractCommand::resolveHostname
}
void AbstractCommand::prepareForNextAction
-(const SharedHandle<CheckIntegrityEntry>& checkEntry)
+(const std::shared_ptr<CheckIntegrityEntry>& checkEntry)
{
std::vector<Command*>* commands = new std::vector<Command*>();
auto_delete_container<std::vector<Command*> > commandsDel(commands);
@@ -783,7 +783,7 @@ void AbstractCommand::prepareForNextAction
}
bool AbstractCommand::checkIfConnectionEstablished
-(const SharedHandle<SocketCore>& socket,
+(const std::shared_ptr<SocketCore>& socket,
const std::string& connectedHostname,
const std::string& connectedAddr,
uint16_t connectedPort)
@@ -827,7 +827,7 @@ const std::string& AbstractCommand::resolveProxyMethod
}
}
-const SharedHandle<Option>& AbstractCommand::getOption() const
+const std::shared_ptr<Option>& AbstractCommand::getOption() const
{
return requestGroup_->getOption();
}
@@ -846,7 +846,7 @@ int32_t AbstractCommand::calculateMinSplitSize() const
}
}
-void AbstractCommand::setRequest(const SharedHandle<Request>& request)
+void AbstractCommand::setRequest(const std::shared_ptr<Request>& request)
{
req_ = request;
}
@@ -856,27 +856,27 @@ void AbstractCommand::resetRequest()
req_.reset();
}
-void AbstractCommand::setFileEntry(const SharedHandle<FileEntry>& fileEntry)
+void AbstractCommand::setFileEntry(const std::shared_ptr<FileEntry>& fileEntry)
{
fileEntry_ = fileEntry;
}
-void AbstractCommand::setSocket(const SharedHandle<SocketCore>& s)
+void AbstractCommand::setSocket(const std::shared_ptr<SocketCore>& s)
{
socket_ = s;
}
-const SharedHandle<DownloadContext>& AbstractCommand::getDownloadContext() const
+const std::shared_ptr<DownloadContext>& AbstractCommand::getDownloadContext() const
{
return requestGroup_->getDownloadContext();
}
-const SharedHandle<SegmentMan>& AbstractCommand::getSegmentMan() const
+const std::shared_ptr<SegmentMan>& AbstractCommand::getSegmentMan() const
{
return requestGroup_->getSegmentMan();
}
-const SharedHandle<PieceStorage>& AbstractCommand::getPieceStorage() const
+const std::shared_ptr<PieceStorage>& AbstractCommand::getPieceStorage() const
{
return requestGroup_->getPieceStorage();
}
diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h
index ac97b819..a8204b75 100644
--- a/src/AbstractCommand.h
+++ b/src/AbstractCommand.h
@@ -39,8 +39,8 @@
#include <vector>
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
namespace aria2 {
@@ -68,76 +68,76 @@ private:
time_t timeout_;
RequestGroup* requestGroup_;
- SharedHandle<Request> req_;
- SharedHandle<FileEntry> fileEntry_;
+ std::shared_ptr<Request> req_;
+ std::shared_ptr<FileEntry> fileEntry_;
DownloadEngine* e_;
- SharedHandle<SocketCore> socket_;
- SharedHandle<SocketRecvBuffer> socketRecvBuffer_;
- std::vector<SharedHandle<Segment> > segments_;
+ std::shared_ptr<SocketCore> socket_;
+ std::shared_ptr<SocketRecvBuffer> socketRecvBuffer_;
+ std::vector<std::shared_ptr<Segment> > segments_;
#ifdef ENABLE_ASYNC_DNS
- SharedHandle<AsyncNameResolverMan> asyncNameResolverMan_;
+ std::shared_ptr<AsyncNameResolverMan> asyncNameResolverMan_;
#endif // ENABLE_ASYNC_DNS
bool checkSocketIsReadable_;
bool checkSocketIsWritable_;
- SharedHandle<SocketCore> readCheckTarget_;
- SharedHandle<SocketCore> writeCheckTarget_;
+ std::shared_ptr<SocketCore> readCheckTarget_;
+ std::shared_ptr<SocketCore> writeCheckTarget_;
bool incNumConnection_;
Timer serverStatTimer_;
int32_t calculateMinSplitSize() const;
- void useFasterRequest(const SharedHandle<Request>& fasterRequest);
+ void useFasterRequest(const std::shared_ptr<Request>& fasterRequest);
public:
RequestGroup* getRequestGroup() const
{
return requestGroup_;
}
- const SharedHandle<Request>& getRequest() const
+ const std::shared_ptr<Request>& getRequest() const
{
return req_;
}
- void setRequest(const SharedHandle<Request>& request);
+ void setRequest(const std::shared_ptr<Request>& request);
// Resets request_. This method is more efficient than
- // setRequest(SharedHandle<Request>());
+ // setRequest(std::shared_ptr<Request>());
void resetRequest();
- const SharedHandle<FileEntry>& getFileEntry() const
+ const std::shared_ptr<FileEntry>& getFileEntry() const
{
return fileEntry_;
}
- void setFileEntry(const SharedHandle<FileEntry>& fileEntry);
+ void setFileEntry(const std::shared_ptr<FileEntry>& fileEntry);
DownloadEngine* getDownloadEngine() const
{
return e_;
}
- const SharedHandle<SocketCore>& getSocket() const
+ const std::shared_ptr<SocketCore>& getSocket() const
{
return socket_;
}
- SharedHandle<SocketCore>& getSocket()
+ std::shared_ptr<SocketCore>& getSocket()
{
return socket_;
}
- void setSocket(const SharedHandle<SocketCore>& s);
+ void setSocket(const std::shared_ptr<SocketCore>& s);
void createSocket();
- const SharedHandle<SocketRecvBuffer>& getSocketRecvBuffer() const
+ const std::shared_ptr<SocketRecvBuffer>& getSocketRecvBuffer() const
{
return socketRecvBuffer_;
}
- const std::vector<SharedHandle<Segment> >& getSegments() const
+ const std::vector<std::shared_ptr<Segment> >& getSegments() const
{
return segments_;
}
@@ -152,8 +152,8 @@ public:
void tryReserved();
- void setReadCheckSocket(const SharedHandle<SocketCore>& socket);
- void setWriteCheckSocket(const SharedHandle<SocketCore>& socket);
+ void setReadCheckSocket(const std::shared_ptr<SocketCore>& socket);
+ void setWriteCheckSocket(const std::shared_ptr<SocketCore>& socket);
void disableReadCheckSocket();
void disableWriteCheckSocket();
@@ -161,16 +161,16 @@ public:
* If pred == true, calls setReadCheckSocket(socket). Otherwise, calls
* disableReadCheckSocket().
*/
- void setReadCheckSocketIf(const SharedHandle<SocketCore>& socket, bool pred);
+ void setReadCheckSocketIf(const std::shared_ptr<SocketCore>& socket, bool pred);
/**
* If pred == true, calls setWriteCheckSocket(socket). Otherwise, calls
* disableWriteCheckSocket().
*/
- void setWriteCheckSocketIf(const SharedHandle<SocketCore>& socket, bool pred);
+ void setWriteCheckSocketIf(const std::shared_ptr<SocketCore>& socket, bool pred);
// Swaps socket_ with socket. This disables current read and write
// check.
- void swapSocket(SharedHandle<SocketCore>& socket);
+ void swapSocket(std::shared_ptr<SocketCore>& socket);
time_t getTimeout() const
{
@@ -180,7 +180,7 @@ public:
void setTimeout(time_t timeout) { timeout_ = timeout; }
void prepareForNextAction
- (const SharedHandle<CheckIntegrityEntry>& checkEntry);
+ (const std::shared_ptr<CheckIntegrityEntry>& checkEntry);
// Check if socket is connected. If socket is not connected and
// there are other addresses to try, command is created using
@@ -188,7 +188,7 @@ public:
// DownloadEngine and returns false. If no addresses left, DlRetryEx
// exception is thrown.
bool checkIfConnectionEstablished
- (const SharedHandle<SocketCore>& socket,
+ (const std::shared_ptr<SocketCore>& socket,
const std::string& connectedHostname,
const std::string& connectedAddr,
uint16_t connectedPort);
@@ -201,19 +201,19 @@ public:
/*
* Creates Request object for proxy URI and returns it.
- * If no valid proxy is defined, then returns SharedHandle<Request>().
+ * If no valid proxy is defined, then returns std::shared_ptr<Request>().
*/
- SharedHandle<Request> createProxyRequest() const;
+ std::shared_ptr<Request> createProxyRequest() const;
// Returns proxy method for given protocol. Either V_GET or V_TUNNEL
// is returned. For HTTPS, always returns V_TUNNEL.
const std::string& resolveProxyMethod(const std::string& protocol) const;
- const SharedHandle<Option>& getOption() const;
+ const std::shared_ptr<Option>& getOption() const;
- const SharedHandle<DownloadContext>& getDownloadContext() const;
- const SharedHandle<SegmentMan>& getSegmentMan() const;
- const SharedHandle<PieceStorage>& getPieceStorage() const;
+ const std::shared_ptr<DownloadContext>& getDownloadContext() const;
+ const std::shared_ptr<SegmentMan>& getSegmentMan() const;
+ const std::shared_ptr<PieceStorage>& getPieceStorage() const;
Timer& getCheckPoint()
{
@@ -235,12 +235,12 @@ protected:
public:
AbstractCommand
- (cuid_t cuid, const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ (cuid_t cuid, const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup, DownloadEngine* e,
- const SharedHandle<SocketCore>& s = SharedHandle<SocketCore>(),
- const SharedHandle<SocketRecvBuffer>& socketRecvBuffer
- = SharedHandle<SocketRecvBuffer>(),
+ const std::shared_ptr<SocketCore>& s = std::shared_ptr<SocketCore>(),
+ const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer
+ = std::shared_ptr<SocketRecvBuffer>(),
bool incNumConnection = true);
virtual ~AbstractCommand();
diff --git a/src/AbstractHttpServerResponseCommand.cc b/src/AbstractHttpServerResponseCommand.cc
index 5d9d8c11..e83c4c1e 100644
--- a/src/AbstractHttpServerResponseCommand.cc
+++ b/src/AbstractHttpServerResponseCommand.cc
@@ -49,9 +49,9 @@ namespace aria2 {
AbstractHttpServerResponseCommand::AbstractHttpServerResponseCommand
(cuid_t cuid,
- const SharedHandle<HttpServer>& httpServer,
+ const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket)
+ const std::shared_ptr<SocketCore>& socket)
: Command(cuid),
e_(e),
socket_(socket),
@@ -107,20 +107,21 @@ bool AbstractHttpServerResponseCommand::execute()
}
} catch(RecoverableException& e) {
A2_LOG_INFO_EX
- (fmt("CUID#%"PRId64" - Error occurred while transmitting response body.",
+ (fmt("CUID#%" PRId64
+ " - Error occurred while transmitting response body.",
getCuid()),
e);
return true;
}
if(httpServer_->sendBufferIsEmpty()) {
- A2_LOG_INFO(fmt("CUID#%"PRId64" - HttpServer: all response transmitted.",
+ A2_LOG_INFO(fmt("CUID#%" PRId64 " - HttpServer: all response transmitted.",
getCuid()));
afterSend(httpServer_, e_);
return true;
} else {
if(timeoutTimer_.difference(global::wallclock()) >= 30) {
- A2_LOG_INFO(fmt("CUID#%"PRId64" - HttpServer: Timeout while trasmitting"
- " response.",
+ A2_LOG_INFO(fmt("CUID#%" PRId64
+ " - HttpServer: Timeout while trasmitting response.",
getCuid()));
return true;
} else {
diff --git a/src/AbstractHttpServerResponseCommand.h b/src/AbstractHttpServerResponseCommand.h
index 652d6b05..f972da90 100644
--- a/src/AbstractHttpServerResponseCommand.h
+++ b/src/AbstractHttpServerResponseCommand.h
@@ -36,7 +36,9 @@
#define D_ABSTRACT_HTTP_SERVER_RESPONSE_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "TimerA2.h"
namespace aria2 {
@@ -48,8 +50,8 @@ class HttpServer;
class AbstractHttpServerResponseCommand : public Command {
private:
DownloadEngine* e_;
- SharedHandle<SocketCore> socket_;
- SharedHandle<HttpServer> httpServer_;
+ std::shared_ptr<SocketCore> socket_;
+ std::shared_ptr<HttpServer> httpServer_;
Timer timeoutTimer_;
bool readCheck_;
bool writeCheck_;
@@ -61,13 +63,13 @@ protected:
return e_;
}
// Called after content body is completely sent.
- virtual void afterSend(const SharedHandle<HttpServer>& httpServer,
+ virtual void afterSend(const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e) = 0;
public:
AbstractHttpServerResponseCommand(cuid_t cuid,
- const SharedHandle<HttpServer>& httpServer,
+ const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket);
+ const std::shared_ptr<SocketCore>& socket);
virtual ~AbstractHttpServerResponseCommand();
diff --git a/src/AbstractProxyRequestCommand.cc b/src/AbstractProxyRequestCommand.cc
index d24475b3..4d511883 100644
--- a/src/AbstractProxyRequestCommand.cc
+++ b/src/AbstractProxyRequestCommand.cc
@@ -51,18 +51,18 @@ namespace aria2 {
AbstractProxyRequestCommand::AbstractProxyRequestCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<SocketCore>& s)
:
AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
proxyRequest_(proxyRequest),
httpConnection_
(new HttpConnection
- (cuid, s, SharedHandle<SocketRecvBuffer>(new SocketRecvBuffer(s))))
+ (cuid, s, std::shared_ptr<SocketRecvBuffer>(new SocketRecvBuffer(s))))
{
setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
disableReadCheckSocket();
@@ -74,7 +74,7 @@ AbstractProxyRequestCommand::~AbstractProxyRequestCommand() {}
bool AbstractProxyRequestCommand::executeInternal() {
//socket->setBlockingMode();
if(httpConnection_->sendBufferIsEmpty()) {
- SharedHandle<HttpRequest> httpRequest(new HttpRequest());
+ std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
httpRequest->setUserAgent(getOption()->get(PREF_USER_AGENT));
httpRequest->setRequest(getRequest());
httpRequest->setProxyRequest(proxyRequest_);
diff --git a/src/AbstractProxyRequestCommand.h b/src/AbstractProxyRequestCommand.h
index 6948867a..b54b7d31 100644
--- a/src/AbstractProxyRequestCommand.h
+++ b/src/AbstractProxyRequestCommand.h
@@ -44,29 +44,29 @@ class SocketCore;
class AbstractProxyRequestCommand : public AbstractCommand {
private:
- SharedHandle<Request> proxyRequest_;
+ std::shared_ptr<Request> proxyRequest_;
- SharedHandle<HttpConnection> httpConnection_;
+ std::shared_ptr<HttpConnection> httpConnection_;
protected:
virtual bool executeInternal();
- const SharedHandle<HttpConnection>& getHttpConnection() const
+ const std::shared_ptr<HttpConnection>& getHttpConnection() const
{
return httpConnection_;
}
- const SharedHandle<Request>& getProxyRequest() const
+ const std::shared_ptr<Request>& getProxyRequest() const
{
return proxyRequest_;
}
public:
AbstractProxyRequestCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<SocketCore>& s);
virtual ~AbstractProxyRequestCommand();
diff --git a/src/AbstractProxyResponseCommand.cc b/src/AbstractProxyResponseCommand.cc
index 32c5bb0e..c490f020 100644
--- a/src/AbstractProxyResponseCommand.cc
+++ b/src/AbstractProxyResponseCommand.cc
@@ -52,19 +52,19 @@ namespace aria2 {
AbstractProxyResponseCommand::AbstractProxyResponseCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<SocketCore>& s)
:AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
httpConnection_(httpConnection) {}
AbstractProxyResponseCommand::~AbstractProxyResponseCommand() {}
bool AbstractProxyResponseCommand::executeInternal() {
- SharedHandle<HttpResponse> httpResponse = httpConnection_->receiveResponse();
+ std::shared_ptr<HttpResponse> httpResponse = httpConnection_->receiveResponse();
if(!httpResponse) {
// the server has not responded our request yet.
getDownloadEngine()->addCommand(this);
diff --git a/src/AbstractProxyResponseCommand.h b/src/AbstractProxyResponseCommand.h
index ef4c2b0d..4c85fbcc 100644
--- a/src/AbstractProxyResponseCommand.h
+++ b/src/AbstractProxyResponseCommand.h
@@ -44,23 +44,23 @@ class SocketCore;
class AbstractProxyResponseCommand : public AbstractCommand {
private:
- SharedHandle<HttpConnection> httpConnection_;
+ std::shared_ptr<HttpConnection> httpConnection_;
protected:
virtual bool executeInternal();
- const SharedHandle<HttpConnection>& getHttpConnection() const
+ const std::shared_ptr<HttpConnection>& getHttpConnection() const
{
return httpConnection_;
}
public:
AbstractProxyResponseCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<SocketCore>& s);
virtual ~AbstractProxyResponseCommand();
diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc
index d36ac66c..f3dbcd17 100644
--- a/src/AbstractSingleDiskAdaptor.cc
+++ b/src/AbstractSingleDiskAdaptor.cc
@@ -97,7 +97,7 @@ void AbstractSingleDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
for(WrDiskCacheEntry::DataCellSet::const_iterator i = dataSet.begin(),
eoi = dataSet.end(); i != eoi; ++i) {
if(start+static_cast<ssize_t>(buflen) < (*i)->goff) {
- A2_LOG_DEBUG(fmt("Cache flush goff=%"PRId64", len=%lu",
+ A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
start, static_cast<unsigned long>(buflen)));
writeData(buf+buffoffset, buflen-buffoffset, start);
start = (*i)->goff;
@@ -105,7 +105,7 @@ void AbstractSingleDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
}
if(buflen == 0 && ((*i)->goff & 0xfff) == 0 && ((*i)->len & 0xfff) == 0) {
// Already aligned. Write it without copy.
- A2_LOG_DEBUG(fmt("Cache flush goff=%"PRId64", len=%lu",
+ A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
start, static_cast<unsigned long>((*i)->len)));
writeData((*i)->data + (*i)->offset, (*i)->len, start);
start += (*i)->len;
@@ -117,7 +117,7 @@ void AbstractSingleDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
memcpy(buf+buflen, (*i)->data+(*i)->offset, wlen);
buflen += wlen;
if(buflen == sizeof(buf)) {
- A2_LOG_DEBUG(fmt("Cache flush goff=%"PRId64", len=%lu",
+ A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
start, static_cast<unsigned long>(buflen)));
writeData(buf+buffoffset, buflen-buffoffset, start);
memcpy(buf, (*i)->data + (*i)->offset + wlen, (*i)->len - wlen);
@@ -145,26 +145,26 @@ void AbstractSingleDiskAdaptor::truncate(int64_t length)
diskWriter_->truncate(length);
}
-SharedHandle<FileAllocationIterator>
+std::shared_ptr<FileAllocationIterator>
AbstractSingleDiskAdaptor::fileAllocationIterator()
{
switch(getFileAllocationMethod()) {
#ifdef HAVE_SOME_FALLOCATE
case(DiskAdaptor::FILE_ALLOC_FALLOC): {
- SharedHandle<FallocFileAllocationIterator> h
+ std::shared_ptr<FallocFileAllocationIterator> h
(new FallocFileAllocationIterator
(diskWriter_.get(), size() ,totalLength_));
return h;
}
#endif // HAVE_SOME_FALLOCATE
case(DiskAdaptor::FILE_ALLOC_TRUNC): {
- SharedHandle<TruncFileAllocationIterator> h
+ std::shared_ptr<TruncFileAllocationIterator> h
(new TruncFileAllocationIterator
(diskWriter_.get(), size(), totalLength_));
return h;
}
default: {
- SharedHandle<AdaptiveFileAllocationIterator> h
+ std::shared_ptr<AdaptiveFileAllocationIterator> h
(new AdaptiveFileAllocationIterator
(diskWriter_.get(), size(), totalLength_));
return h;
@@ -197,7 +197,7 @@ void AbstractSingleDiskAdaptor::cutTrailingGarbage()
}
void AbstractSingleDiskAdaptor::setDiskWriter
-(const SharedHandle<DiskWriter>& diskWriter)
+(const std::shared_ptr<DiskWriter>& diskWriter)
{
diskWriter_ = diskWriter;
}
diff --git a/src/AbstractSingleDiskAdaptor.h b/src/AbstractSingleDiskAdaptor.h
index 9a71fb3c..4d27b815 100644
--- a/src/AbstractSingleDiskAdaptor.h
+++ b/src/AbstractSingleDiskAdaptor.h
@@ -44,7 +44,7 @@ class FileAllocationIterator;
class AbstractSingleDiskAdaptor : public DiskAdaptor {
private:
- SharedHandle<DiskWriter> diskWriter_;
+ std::shared_ptr<DiskWriter> diskWriter_;
int64_t totalLength_;
bool readOnly_;
public:
@@ -73,7 +73,7 @@ public:
virtual void truncate(int64_t length);
- virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
+ virtual std::shared_ptr<FileAllocationIterator> fileAllocationIterator();
// Make sure that DiskWriter is set before calling this function.
virtual void enableReadOnly();
@@ -89,9 +89,9 @@ public:
virtual const std::string& getFilePath() = 0;
- void setDiskWriter(const SharedHandle<DiskWriter>& diskWriter);
+ void setDiskWriter(const std::shared_ptr<DiskWriter>& diskWriter);
- const SharedHandle<DiskWriter>& getDiskWriter() const
+ const std::shared_ptr<DiskWriter>& getDiskWriter() const
{
return diskWriter_;
}
diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc
index 4c0dbf65..07ae4d5f 100644
--- a/src/ActivePeerConnectionCommand.cc
+++ b/src/ActivePeerConnectionCommand.cc
@@ -131,7 +131,7 @@ void ActivePeerConnectionCommand::makeNewConnections(int num)
{
for(; num && peerStorage_->isPeerAvailable(); --num) {
cuid_t ncuid = e_->newCUID();
- SharedHandle<Peer> peer = peerStorage_->checkoutPeer(ncuid);
+ std::shared_ptr<Peer> peer = peerStorage_->checkoutPeer(ncuid);
// sanity check
if(!peer) {
break;
@@ -148,25 +148,25 @@ void ActivePeerConnectionCommand::makeNewConnections(int num)
}
void ActivePeerConnectionCommand::setBtRuntime
-(const SharedHandle<BtRuntime>& btRuntime)
+(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
void ActivePeerConnectionCommand::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
void ActivePeerConnectionCommand::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
void ActivePeerConnectionCommand::setBtAnnounce
-(const SharedHandle<BtAnnounce>& btAnnounce)
+(const std::shared_ptr<BtAnnounce>& btAnnounce)
{
btAnnounce_ = btAnnounce;
}
diff --git a/src/ActivePeerConnectionCommand.h b/src/ActivePeerConnectionCommand.h
index 872eec58..29730907 100644
--- a/src/ActivePeerConnectionCommand.h
+++ b/src/ActivePeerConnectionCommand.h
@@ -36,7 +36,9 @@
#define D_ACTIVE_PEER_CONNECTION_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "TimerA2.h"
namespace aria2 {
@@ -52,10 +54,10 @@ class BtAnnounce;
class ActivePeerConnectionCommand : public Command {
private:
RequestGroup* requestGroup_;
- SharedHandle<BtRuntime> btRuntime_;
- SharedHandle<PieceStorage> pieceStorage_;
- SharedHandle<PeerStorage> peerStorage_;
- SharedHandle<BtAnnounce> btAnnounce_;
+ std::shared_ptr<BtRuntime> btRuntime_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
+ std::shared_ptr<BtAnnounce> btAnnounce_;
time_t interval_; // UNIT: sec
DownloadEngine* e_;
@@ -78,13 +80,13 @@ public:
numNewConnection_ = numNewConnection;
}
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
- void setBtAnnounce(const SharedHandle<BtAnnounce>& btAnnounce);
+ void setBtAnnounce(const std::shared_ptr<BtAnnounce>& btAnnounce);
};
} // namespace aria2
diff --git a/src/AdaptiveFileAllocationIterator.cc b/src/AdaptiveFileAllocationIterator.cc
index 80874317..f4a116ef 100644
--- a/src/AdaptiveFileAllocationIterator.cc
+++ b/src/AdaptiveFileAllocationIterator.cc
@@ -70,13 +70,13 @@ void AdaptiveFileAllocationIterator::allocateChunk()
(new FallocFileAllocationIterator(stream_, offset_, totalLength_));
} catch(RecoverableException& e) {
A2_LOG_DEBUG("File system does not support fallocate.");
- SharedHandle<SingleFileAllocationIterator> salloc
+ std::shared_ptr<SingleFileAllocationIterator> salloc
(new SingleFileAllocationIterator(stream_, offset_, totalLength_));
salloc->init();
allocator_ = salloc;
}
#else // !HAVE_FALLOCATE
- SharedHandle<SingleFileAllocationIterator> salloc
+ std::shared_ptr<SingleFileAllocationIterator> salloc
(new SingleFileAllocationIterator(stream_, offset_, totalLength_));
salloc->init();
allocator_ = salloc;
diff --git a/src/AdaptiveFileAllocationIterator.h b/src/AdaptiveFileAllocationIterator.h
index 3dc6c970..6a3fd36c 100644
--- a/src/AdaptiveFileAllocationIterator.h
+++ b/src/AdaptiveFileAllocationIterator.h
@@ -37,6 +37,8 @@
#include "FileAllocationIterator.h"
+#include <memory>
+
namespace aria2 {
class BinaryStream;
@@ -44,7 +46,7 @@ class BinaryStream;
class AdaptiveFileAllocationIterator:public FileAllocationIterator
{
private:
- SharedHandle<FileAllocationIterator> allocator_;
+ std::shared_ptr<FileAllocationIterator> allocator_;
BinaryStream* stream_;
diff --git a/src/AdaptiveURISelector.cc b/src/AdaptiveURISelector.cc
index c063f8c1..cbc84057 100644
--- a/src/AdaptiveURISelector.cc
+++ b/src/AdaptiveURISelector.cc
@@ -66,7 +66,7 @@ namespace aria2 {
*/
AdaptiveURISelector::AdaptiveURISelector
-(const SharedHandle<ServerStatMan>& serverStatMan, RequestGroup* requestGroup)
+(const std::shared_ptr<ServerStatMan>& serverStatMan, RequestGroup* requestGroup)
: serverStatMan_(serverStatMan),
requestGroup_(requestGroup)
{
@@ -242,7 +242,7 @@ void AdaptiveURISelector::adjustLowestSpeedLimit
}
namespace {
-int getUriMaxSpeed(SharedHandle<ServerStat> ss)
+int getUriMaxSpeed(std::shared_ptr<ServerStat> ss)
{
return std::max(ss->getSingleConnectionAvgSpeed(),
ss->getMultiConnectionAvgSpeed());
@@ -265,7 +265,7 @@ std::string AdaptiveURISelector::getMaxDownloadSpeedUri
std::string uri = A2STR::NIL;
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
- SharedHandle<ServerStat> ss = getServerStats(*i);
+ std::shared_ptr<ServerStat> ss = getServerStats(*i);
if(!ss)
continue;
@@ -287,7 +287,7 @@ std::deque<std::string> AdaptiveURISelector::getUrisBySpeed
std::deque<std::string> bests;
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
- SharedHandle<ServerStat> ss = getServerStats(*i);
+ std::shared_ptr<ServerStat> ss = getServerStats(*i);
if(!ss)
continue;
if(ss->getSingleConnectionAvgSpeed() > min ||
@@ -312,7 +312,7 @@ std::string AdaptiveURISelector::getFirstNotTestedUri
{
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
- SharedHandle<ServerStat> ss = getServerStats(*i);
+ std::shared_ptr<ServerStat> ss = getServerStats(*i);
if(!ss)
return *i;
}
@@ -326,7 +326,7 @@ std::string AdaptiveURISelector::getFirstToTestUri
int power;
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
- SharedHandle<ServerStat> ss = getServerStats(*i);
+ std::shared_ptr<ServerStat> ss = getServerStats(*i);
if(!ss)
continue;
counter = ss->getCounter();
@@ -342,7 +342,7 @@ std::string AdaptiveURISelector::getFirstToTestUri
return A2STR::NIL;
}
-SharedHandle<ServerStat> AdaptiveURISelector::getServerStats
+std::shared_ptr<ServerStat> AdaptiveURISelector::getServerStats
(const std::string& uri) const
{
uri_split_result us;
@@ -351,7 +351,7 @@ SharedHandle<ServerStat> AdaptiveURISelector::getServerStats
std::string protocol = uri::getFieldString(us, USR_SCHEME, uri.c_str());
return serverStatMan_->find(host, protocol);
} else {
- return SharedHandle<ServerStat>();
+ return std::shared_ptr<ServerStat>();
}
}
@@ -361,7 +361,7 @@ int AdaptiveURISelector::getNbTestedServers
int counter = 0;
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
- SharedHandle<ServerStat> ss = getServerStats(*i);
+ std::shared_ptr<ServerStat> ss = getServerStats(*i);
if(!ss)
++counter;
}
diff --git a/src/AdaptiveURISelector.h b/src/AdaptiveURISelector.h
index df462e07..d4dfdab2 100644
--- a/src/AdaptiveURISelector.h
+++ b/src/AdaptiveURISelector.h
@@ -36,7 +36,8 @@
#ifndef D_ADAPTIVE_URI_SELECTOR_H
#define D_ADAPTIVE_URI_SELECTOR_H
#include "URISelector.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -46,7 +47,7 @@ class ServerStat;
class AdaptiveURISelector:public URISelector {
private:
- SharedHandle<ServerStatMan> serverStatMan_;
+ std::shared_ptr<ServerStatMan> serverStatMan_;
// No need to delete requestGroup_
RequestGroup* requestGroup_;
int nbServerToEvaluate_;
@@ -66,11 +67,11 @@ private:
std::string selectRandomUri(const std::deque<std::string>& uris) const;
std::string getFirstNotTestedUri(const std::deque<std::string>& uris) const;
std::string getFirstToTestUri(const std::deque<std::string>& uris) const;
- SharedHandle<ServerStat> getServerStats(const std::string& uri) const;
+ std::shared_ptr<ServerStat> getServerStats(const std::string& uri) const;
int getNbTestedServers(const std::deque<std::string>& uris) const;
std::string getBestMirror(const std::deque<std::string>& uris) const;
public:
- AdaptiveURISelector(const SharedHandle<ServerStatMan>& serverStatMan,
+ AdaptiveURISelector(const std::shared_ptr<ServerStatMan>& serverStatMan,
RequestGroup* requestGroup);
virtual ~AdaptiveURISelector();
diff --git a/src/AnnounceList.cc b/src/AnnounceList.cc
index e41b278e..f21634aa 100644
--- a/src/AnnounceList.cc
+++ b/src/AnnounceList.cc
@@ -51,7 +51,7 @@ AnnounceList::AnnounceList
}
AnnounceList::AnnounceList
-(const std::deque<SharedHandle<AnnounceTier> >& announceTiers):
+(const std::deque<std::shared_ptr<AnnounceTier> >& announceTiers):
tiers_(announceTiers), currentTrackerInitialized_(false) {
resetIterator();
}
@@ -67,7 +67,7 @@ void AnnounceList::reconfigure
continue;
}
std::deque<std::string> urls((*itr).begin(), (*itr).end());
- SharedHandle<AnnounceTier> tier(new AnnounceTier(urls));
+ std::shared_ptr<AnnounceTier> tier(new AnnounceTier(urls));
tiers_.push_back(tier);
}
resetIterator();
@@ -76,7 +76,7 @@ void AnnounceList::reconfigure
void AnnounceList::reconfigure(const std::string& url) {
std::deque<std::string> urls;
urls.push_back(url);
- SharedHandle<AnnounceTier> tier(new AnnounceTier(urls));
+ std::shared_ptr<AnnounceTier> tier(new AnnounceTier(urls));
tiers_.push_back(tier);
resetIterator();
}
@@ -161,7 +161,7 @@ const char* AnnounceList::getEventString() const {
namespace {
class FindStoppedAllowedTier {
public:
- bool operator()(const SharedHandle<AnnounceTier>& tier) const {
+ bool operator()(const std::shared_ptr<AnnounceTier>& tier) const {
switch(tier->event) {
case AnnounceTier::DOWNLOADING:
case AnnounceTier::STOPPED:
@@ -178,7 +178,7 @@ public:
namespace {
class FindCompletedAllowedTier {
public:
- bool operator()(const SharedHandle<AnnounceTier>& tier) const {
+ bool operator()(const std::shared_ptr<AnnounceTier>& tier) const {
switch(tier->event) {
case AnnounceTier::DOWNLOADING:
case AnnounceTier::COMPLETED:
@@ -199,7 +199,7 @@ size_t AnnounceList::countCompletedAllowedTier() const {
}
void AnnounceList::setCurrentTier
-(const std::deque<SharedHandle<AnnounceTier> >::iterator& itr) {
+(const std::deque<std::shared_ptr<AnnounceTier> >::iterator& itr) {
if(itr != tiers_.end()) {
currentTier_ = itr;
currentTracker_ = (*currentTier_)->urls.begin();
@@ -207,7 +207,7 @@ void AnnounceList::setCurrentTier
}
void AnnounceList::moveToStoppedAllowedTier() {
- std::deque<SharedHandle<AnnounceTier> >::iterator itr =
+ std::deque<std::shared_ptr<AnnounceTier> >::iterator itr =
find_wrap_if(tiers_.begin(), tiers_.end(),
currentTier_,
FindStoppedAllowedTier());
@@ -215,7 +215,7 @@ void AnnounceList::moveToStoppedAllowedTier() {
}
void AnnounceList::moveToCompletedAllowedTier() {
- std::deque<SharedHandle<AnnounceTier> >::iterator itr =
+ std::deque<std::shared_ptr<AnnounceTier> >::iterator itr =
find_wrap_if(tiers_.begin(), tiers_.end(),
currentTier_,
FindCompletedAllowedTier());
@@ -223,7 +223,7 @@ void AnnounceList::moveToCompletedAllowedTier() {
}
void AnnounceList::shuffle() {
- for(std::deque<SharedHandle<AnnounceTier> >::const_iterator itr =
+ for(std::deque<std::shared_ptr<AnnounceTier> >::const_iterator itr =
tiers_.begin(), eoi = tiers_.end(); itr != eoi; ++itr) {
std::deque<std::string>& urls = (*itr)->urls;
std::random_shuffle(urls.begin(), urls.end(),
diff --git a/src/AnnounceList.h b/src/AnnounceList.h
index 61e26c93..fc07c8d8 100644
--- a/src/AnnounceList.h
+++ b/src/AnnounceList.h
@@ -36,7 +36,9 @@
#define D_ANNOUNCE_LIST_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "AnnounceTier.h"
#include "ValueBase.h"
@@ -45,18 +47,18 @@ namespace aria2 {
class AnnounceList {
public:
private:
- std::deque<SharedHandle<AnnounceTier> > tiers_;
- std::deque<SharedHandle<AnnounceTier> >::iterator currentTier_;
+ std::deque<std::shared_ptr<AnnounceTier> > tiers_;
+ std::deque<std::shared_ptr<AnnounceTier> >::iterator currentTier_;
std::deque<std::string>::iterator currentTracker_;
bool currentTrackerInitialized_;
void resetIterator();
void setCurrentTier
- (const std::deque<SharedHandle<AnnounceTier> >::iterator& itr);
+ (const std::deque<std::shared_ptr<AnnounceTier> >::iterator& itr);
public:
AnnounceList();
AnnounceList(const std::vector<std::vector<std::string> >& announceList);
- AnnounceList(const std::deque<SharedHandle<AnnounceTier> >& tiers);
+ AnnounceList(const std::deque<std::shared_ptr<AnnounceTier> >& tiers);
~AnnounceList();
// Don't allow copying
diff --git a/src/AnnounceTier.h b/src/AnnounceTier.h
index 77de3759..44fa1abf 100644
--- a/src/AnnounceTier.h
+++ b/src/AnnounceTier.h
@@ -40,8 +40,6 @@
#include <string>
#include <deque>
-#include "SharedHandle.h"
-
namespace aria2 {
class AnnounceTier {
diff --git a/src/AnonDiskWriterFactory.h b/src/AnonDiskWriterFactory.h
index f92556d1..60146827 100644
--- a/src/AnonDiskWriterFactory.h
+++ b/src/AnonDiskWriterFactory.h
@@ -47,9 +47,9 @@ public:
AnonDiskWriterFactory() {}
virtual ~AnonDiskWriterFactory() {}
- virtual SharedHandle<DiskWriter> newDiskWriter(const std::string& filename)
+ virtual std::shared_ptr<DiskWriter> newDiskWriter(const std::string& filename)
{
- return SharedHandle<DiskWriter>(new DiskWriterType());
+ return std::shared_ptr<DiskWriter>(new DiskWriterType());
}
};
diff --git a/src/AppleMessageDigestImpl.cc b/src/AppleMessageDigestImpl.cc
index 7d8eafb1..4550d1eb 100644
--- a/src/AppleMessageDigestImpl.cc
+++ b/src/AppleMessageDigestImpl.cc
@@ -108,33 +108,33 @@ typedef MessageDigestBase<CC_SHA512_DIGEST_LENGTH,
CC_SHA512_Final>
MessageDigestSHA512;
-SharedHandle<MessageDigestImpl> MessageDigestImpl::sha1()
+std::shared_ptr<MessageDigestImpl> MessageDigestImpl::sha1()
{
- return SharedHandle<MessageDigestImpl>(new MessageDigestSHA1());
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA1());
}
-SharedHandle<MessageDigestImpl> MessageDigestImpl::create
+std::shared_ptr<MessageDigestImpl> MessageDigestImpl::create
(const std::string& hashType)
{
if (hashType == "sha-1") {
- return SharedHandle<MessageDigestImpl>(new MessageDigestSHA1());
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA1());
}
if (hashType == "sha-224") {
- return SharedHandle<MessageDigestImpl>(new MessageDigestSHA224());
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA224());
}
if (hashType == "sha-256") {
- return SharedHandle<MessageDigestImpl>(new MessageDigestSHA256());
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA256());
}
if (hashType == "sha-384") {
- return SharedHandle<MessageDigestImpl>(new MessageDigestSHA384());
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA384());
}
if (hashType == "sha-512") {
- return SharedHandle<MessageDigestImpl>(new MessageDigestSHA512());
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA512());
}
if (hashType == "md5") {
- return SharedHandle<MessageDigestImpl>(new MessageDigestMD5());
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestMD5());
}
- return SharedHandle<MessageDigestImpl>();
+ return std::shared_ptr<MessageDigestImpl>();
}
bool MessageDigestImpl::supports(const std::string& hashType)
@@ -144,7 +144,7 @@ bool MessageDigestImpl::supports(const std::string& hashType)
size_t MessageDigestImpl::getDigestLength(const std::string& hashType)
{
- SharedHandle<MessageDigestImpl> impl = create(hashType);
+ std::shared_ptr<MessageDigestImpl> impl = create(hashType);
if (!impl) {
return 0;
}
diff --git a/src/AppleMessageDigestImpl.h b/src/AppleMessageDigestImpl.h
index 91992603..de9aef83 100644
--- a/src/AppleMessageDigestImpl.h
+++ b/src/AppleMessageDigestImpl.h
@@ -38,16 +38,15 @@
#include "common.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
class MessageDigestImpl {
public:
virtual ~MessageDigestImpl() {}
- static SharedHandle<MessageDigestImpl> sha1();
- static SharedHandle<MessageDigestImpl> create(const std::string& hashType);
+ static std::shared_ptr<MessageDigestImpl> sha1();
+ static std::shared_ptr<MessageDigestImpl> create(const std::string& hashType);
static bool supports(const std::string& hashType);
static size_t getDigestLength(const std::string& hashType);
diff --git a/src/AsyncNameResolver.h b/src/AsyncNameResolver.h
index 905fe0ec..fac6df5e 100644
--- a/src/AsyncNameResolver.h
+++ b/src/AsyncNameResolver.h
@@ -42,7 +42,6 @@
#include <ares.h>
-#include "SharedHandle.h"
#include "a2netcompat.h"
namespace aria2 {
diff --git a/src/AsyncNameResolverMan.cc b/src/AsyncNameResolverMan.cc
index 89efc78f..c6ad8da6 100644
--- a/src/AsyncNameResolverMan.cc
+++ b/src/AsyncNameResolverMan.cc
@@ -33,6 +33,9 @@
*/
/* copyright --> */
#include "AsyncNameResolverMan.h"
+
+#include <cassert>
+
#include "AsyncNameResolver.h"
#include "DownloadEngine.h"
#include "Command.h"
diff --git a/src/AsyncNameResolverMan.h b/src/AsyncNameResolverMan.h
index ef1dd599..6f84434e 100644
--- a/src/AsyncNameResolverMan.h
+++ b/src/AsyncNameResolverMan.h
@@ -39,8 +39,7 @@
#include <vector>
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -97,7 +96,7 @@ private:
void disableNameResolverCheck(size_t index, DownloadEngine* e,
Command* command);
- SharedHandle<AsyncNameResolver> asyncNameResolver_[2];
+ std::shared_ptr<AsyncNameResolver> asyncNameResolver_[2];
size_t numResolver_;
int resolverCheck_;
bool ipv4_;
diff --git a/src/AuthConfig.cc b/src/AuthConfig.cc
index 78370749..ed9c465f 100644
--- a/src/AuthConfig.cc
+++ b/src/AuthConfig.cc
@@ -58,7 +58,7 @@ std::string AuthConfig::getAuthText() const
}
std::ostream& operator<<(std::ostream& o,
- const SharedHandle<AuthConfig>& authConfig)
+ const std::shared_ptr<AuthConfig>& authConfig)
{
o << authConfig->getAuthText();
return o;
diff --git a/src/AuthConfig.h b/src/AuthConfig.h
index 83d728eb..cae54a40 100644
--- a/src/AuthConfig.h
+++ b/src/AuthConfig.h
@@ -39,8 +39,7 @@
#include <string>
#include <iosfwd>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -72,7 +71,7 @@ public:
};
std::ostream& operator<<(std::ostream& o,
- const SharedHandle<AuthConfig>& authConfig);
+ const std::shared_ptr<AuthConfig>& authConfig);
} // namespace aria2
diff --git a/src/AuthConfigFactory.cc b/src/AuthConfigFactory.cc
index 525b984a..802ad367 100644
--- a/src/AuthConfigFactory.cc
+++ b/src/AuthConfigFactory.cc
@@ -56,15 +56,15 @@ AuthConfigFactory::AuthConfigFactory() {}
AuthConfigFactory::~AuthConfigFactory() {}
-SharedHandle<AuthConfig>
+std::shared_ptr<AuthConfig>
AuthConfigFactory::createAuthConfig
-(const SharedHandle<Request>& request, const Option* op)
+(const std::shared_ptr<Request>& request, const Option* op)
{
if(request->getProtocol() == "http" || request->getProtocol() == "https") {
if(op->getAsBool(PREF_HTTP_AUTH_CHALLENGE)) {
if(!request->getUsername().empty()) {
- SharedHandle<BasicCred> bc(new BasicCred(request->getUsername(),
+ std::shared_ptr<BasicCred> bc(new BasicCred(request->getUsername(),
request->getPassword(),
request->getHost(),
request->getPort(),
@@ -76,7 +76,7 @@ AuthConfigFactory::createAuthConfig
findBasicCred(request->getHost(), request->getPort(),
request->getDir());
if(i == basicCreds_.end()) {
- return SharedHandle<AuthConfig>();
+ return std::shared_ptr<AuthConfig>();
} else {
return createAuthConfig((*i)->user_, (*i)->password_);
}
@@ -99,7 +99,7 @@ AuthConfigFactory::createAuthConfig
NetrcAuthResolver authResolver;
authResolver.setNetrc(netrc_);
- SharedHandle<AuthConfig> ac =
+ std::shared_ptr<AuthConfig> ac =
authResolver.resolveAuthConfig(request->getHost());
if(ac && ac->getUser() == request->getUsername()) {
return ac;
@@ -115,21 +115,21 @@ AuthConfigFactory::createAuthConfig
createFtpAuthResolver(op)->resolveAuthConfig(request->getHost());
}
} else {
- return SharedHandle<AuthConfig>();
+ return std::shared_ptr<AuthConfig>();
}
}
-SharedHandle<AuthConfig>
+std::shared_ptr<AuthConfig>
AuthConfigFactory::createAuthConfig(const std::string& user, const std::string& password) const
{
- SharedHandle<AuthConfig> ac;
+ std::shared_ptr<AuthConfig> ac;
if(!user.empty()) {
ac.reset(new AuthConfig(user, password));
}
return ac;
}
-SharedHandle<AuthResolver> AuthConfigFactory::createHttpAuthResolver
+std::shared_ptr<AuthResolver> AuthConfigFactory::createHttpAuthResolver
(const Option* op) const
{
AbstractAuthResolver* resolver;
@@ -143,10 +143,10 @@ SharedHandle<AuthResolver> AuthConfigFactory::createHttpAuthResolver
}
resolver->setUserDefinedAuthConfig
(createAuthConfig(op->get(PREF_HTTP_USER), op->get(PREF_HTTP_PASSWD)));
- return SharedHandle<AuthResolver>(resolver);
+ return std::shared_ptr<AuthResolver>(resolver);
}
-SharedHandle<AuthResolver> AuthConfigFactory::createFtpAuthResolver
+std::shared_ptr<AuthResolver> AuthConfigFactory::createFtpAuthResolver
(const Option* op) const
{
AbstractAuthResolver* resolver;
@@ -159,19 +159,19 @@ SharedHandle<AuthResolver> AuthConfigFactory::createFtpAuthResolver
}
resolver->setUserDefinedAuthConfig
(createAuthConfig(op->get(PREF_FTP_USER), op->get(PREF_FTP_PASSWD)));
- SharedHandle<AuthConfig> defaultAuthConfig
+ std::shared_ptr<AuthConfig> defaultAuthConfig
(new AuthConfig(AUTH_DEFAULT_USER, AUTH_DEFAULT_PASSWD));
resolver->setDefaultAuthConfig(defaultAuthConfig);
- return SharedHandle<AuthResolver>(resolver);
+ return std::shared_ptr<AuthResolver>(resolver);
}
-void AuthConfigFactory::setNetrc(const SharedHandle<Netrc>& netrc)
+void AuthConfigFactory::setNetrc(const std::shared_ptr<Netrc>& netrc)
{
netrc_ = netrc;
}
void AuthConfigFactory::updateBasicCred
-(const SharedHandle<BasicCred>& basicCred)
+(const std::shared_ptr<BasicCred>& basicCred)
{
BasicCredSet::iterator i = basicCreds_.lower_bound(basicCred);
if(i != basicCreds_.end() && *(*i) == *basicCred) {
@@ -189,12 +189,12 @@ bool AuthConfigFactory::activateBasicCred
{
BasicCredSet::iterator i = findBasicCred(host, port, path);
if(i == basicCreds_.end()) {
- SharedHandle<AuthConfig> authConfig =
+ std::shared_ptr<AuthConfig> authConfig =
createHttpAuthResolver(op)->resolveAuthConfig(host);
if(!authConfig) {
return false;
} else {
- SharedHandle<BasicCred> bc
+ std::shared_ptr<BasicCred> bc
(new BasicCred(authConfig->getUser(), authConfig->getPassword(),
host, port, path, true));
basicCreds_.insert(bc);
@@ -246,7 +246,7 @@ AuthConfigFactory::findBasicCred
uint16_t port,
const std::string& path)
{
- SharedHandle<BasicCred> bc(new BasicCred("", "", host, port, path));
+ std::shared_ptr<BasicCred> bc(new BasicCred("", "", host, port, path));
BasicCredSet::iterator i = basicCreds_.lower_bound(bc);
for(; i != basicCreds_.end() && (*i)->host_ == host && (*i)->port_ == port;
++i) {
diff --git a/src/AuthConfigFactory.h b/src/AuthConfigFactory.h
index 6b520e2d..e863db6d 100644
--- a/src/AuthConfigFactory.h
+++ b/src/AuthConfigFactory.h
@@ -39,8 +39,8 @@
#include <string>
#include <set>
+#include <memory>
-#include "SharedHandle.h"
#include "SingletonHolder.h"
#include "a2functional.h"
@@ -54,14 +54,14 @@ class AuthResolver;
class AuthConfigFactory {
private:
- SharedHandle<Netrc> netrc_;
+ std::shared_ptr<Netrc> netrc_;
- SharedHandle<AuthConfig> createAuthConfig(const std::string& user,
+ std::shared_ptr<AuthConfig> createAuthConfig(const std::string& user,
const std::string& password) const;
- SharedHandle<AuthResolver> createHttpAuthResolver(const Option* op) const;
+ std::shared_ptr<AuthResolver> createHttpAuthResolver(const Option* op) const;
- SharedHandle<AuthResolver> createFtpAuthResolver(const Option* op) const;
+ std::shared_ptr<AuthResolver> createFtpAuthResolver(const Option* op) const;
public:
class BasicCred {
public:
@@ -85,8 +85,8 @@ public:
bool operator<(const BasicCred& cred) const;
};
- typedef std::set<SharedHandle<BasicCred>,
- DerefLess<SharedHandle<BasicCred> > > BasicCredSet;
+ typedef std::set<std::shared_ptr<BasicCred>,
+ DerefLess<std::shared_ptr<BasicCred> > > BasicCredSet;
private:
BasicCredSet basicCreds_;
public:
@@ -98,10 +98,10 @@ public:
// are used in this method: PREF_HTTP_USER, PREF_HTTP_PASSWD,
// PREF_FTP_USER, PREF_FTP_PASSWD, PREF_NO_NETRC and
// PREF_HTTP_AUTH_CHALLENGE.
- SharedHandle<AuthConfig> createAuthConfig
- (const SharedHandle<Request>& request, const Option* op);
+ std::shared_ptr<AuthConfig> createAuthConfig
+ (const std::shared_ptr<Request>& request, const Option* op);
- void setNetrc(const SharedHandle<Netrc>& netrc);
+ void setNetrc(const std::shared_ptr<Netrc>& netrc);
// Find a BasicCred using findBasicCred() and activate it then
// return true. If matching BasicCred is not found, AuthConfig
@@ -127,7 +127,7 @@ public:
// If the same BasicCred is already added, then it is replaced with
// given basicCred. Otherwise, insert given basicCred to
// basicCreds_.
- void updateBasicCred(const SharedHandle<BasicCred>& basicCred);
+ void updateBasicCred(const std::shared_ptr<BasicCred>& basicCred);
};
} // namespace aria2
diff --git a/src/AuthResolver.h b/src/AuthResolver.h
index ab2cccf7..e3b83449 100644
--- a/src/AuthResolver.h
+++ b/src/AuthResolver.h
@@ -38,8 +38,7 @@
#include "common.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -49,7 +48,7 @@ class AuthResolver {
public:
virtual ~AuthResolver() {}
- virtual SharedHandle<AuthConfig> resolveAuthConfig(const std::string& hostname) = 0;
+ virtual std::shared_ptr<AuthConfig> resolveAuthConfig(const std::string& hostname) = 0;
};
} // namespace aria2
diff --git a/src/BackupIPv4ConnectCommand.cc b/src/BackupIPv4ConnectCommand.cc
index 9ca2081b..5c61434b 100644
--- a/src/BackupIPv4ConnectCommand.cc
+++ b/src/BackupIPv4ConnectCommand.cc
@@ -51,7 +51,7 @@ BackupConnectInfo::BackupConnectInfo()
BackupIPv4ConnectCommand::BackupIPv4ConnectCommand
(cuid_t cuid, const std::string& ipaddr, uint16_t port,
- const SharedHandle<BackupConnectInfo>& info, Command* mainCommand,
+ const std::shared_ptr<BackupConnectInfo>& info, Command* mainCommand,
RequestGroup* requestGroup, DownloadEngine* e)
: Command(cuid),
ipaddr_(ipaddr),
@@ -83,14 +83,15 @@ bool BackupIPv4ConnectCommand::execute()
if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) {
retval = true;
} else if(info_->cancel) {
- A2_LOG_INFO(fmt("CUID#%"PRId64" - Backup connection canceled", getCuid()));
+ A2_LOG_INFO(fmt("CUID#%" PRId64 " - Backup connection canceled",
+ getCuid()));
retval = true;
} else if(socket_) {
if(writeEventEnabled()) {
try {
std::string error = socket_->getSocketError();
if(error.empty()) {
- A2_LOG_INFO(fmt("CUID#%"PRId64" - Backup connection to %s "
+ A2_LOG_INFO(fmt("CUID#%" PRId64 " - Backup connection to %s "
"established", getCuid(), ipaddr_.c_str()));
info_->ipaddr = ipaddr_;
e_->deleteSocketForWriteCheck(socket_, this);
@@ -99,12 +100,12 @@ bool BackupIPv4ConnectCommand::execute()
e_->setNoWait(true);
retval = true;
} else {
- A2_LOG_INFO(fmt("CUID#%"PRId64" - Backup connection failed: %s",
+ A2_LOG_INFO(fmt("CUID#%" PRId64 " - Backup connection failed: %s",
getCuid(), error.c_str()));
retval = true;
}
} catch(RecoverableException& e) {
- A2_LOG_INFO_EX(fmt("CUID#%"PRId64" - Backup connection failed",
+ A2_LOG_INFO_EX(fmt("CUID#%" PRId64 " - Backup connection failed",
getCuid()), e);
retval = true;
}
@@ -120,14 +121,14 @@ bool BackupIPv4ConnectCommand::execute()
e_->addSocketForWriteCheck(socket_, this);
timeoutCheck_ = global::wallclock();
} catch(RecoverableException& e) {
- A2_LOG_INFO_EX(fmt("CUID#%"PRId64" - Backup connection failed",
+ A2_LOG_INFO_EX(fmt("CUID#%" PRId64 " - Backup connection failed",
getCuid()), e);
socket_.reset();
retval = true;
}
}
} else if(timeoutCheck_.difference(global::wallclock()) >= timeout_) {
- A2_LOG_INFO(fmt("CUID#%"PRId64" - Backup connection command timeout",
+ A2_LOG_INFO(fmt("CUID#%" PRId64 " - Backup connection command timeout",
getCuid()));
retval = true;
}
diff --git a/src/BackupIPv4ConnectCommand.h b/src/BackupIPv4ConnectCommand.h
index de207bc1..b6354e7a 100644
--- a/src/BackupIPv4ConnectCommand.h
+++ b/src/BackupIPv4ConnectCommand.h
@@ -38,8 +38,8 @@
#include "Command.h"
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
namespace aria2 {
@@ -55,7 +55,7 @@ class SocketCore;
// member becomes true.
struct BackupConnectInfo {
std::string ipaddr;
- SharedHandle<SocketCore> socket;
+ std::shared_ptr<SocketCore> socket;
bool cancel;
BackupConnectInfo();
};
@@ -66,7 +66,7 @@ class BackupIPv4ConnectCommand : public Command {
public:
BackupIPv4ConnectCommand(cuid_t cuid,
const std::string& ipaddr, uint16_t port,
- const SharedHandle<BackupConnectInfo>& info,
+ const std::shared_ptr<BackupConnectInfo>& info,
Command* mainCommand,
RequestGroup* requestGroup, DownloadEngine* e);
~BackupIPv4ConnectCommand();
@@ -74,8 +74,8 @@ public:
private:
std::string ipaddr_;
uint16_t port_;
- SharedHandle<SocketCore> socket_;
- SharedHandle<BackupConnectInfo> info_;
+ std::shared_ptr<SocketCore> socket_;
+ std::shared_ptr<BackupConnectInfo> info_;
Command* mainCommand_;
RequestGroup* requestGroup_;
DownloadEngine* e_;
diff --git a/src/BencodeParser.cc b/src/BencodeParser.cc
index 9b4861f7..b04f288f 100644
--- a/src/BencodeParser.cc
+++ b/src/BencodeParser.cc
@@ -33,6 +33,9 @@
*/
/* copyright --> */
#include "BencodeParser.h"
+
+#include <cassert>
+
#include "StructParserStateMachine.h"
#include "util.h"
diff --git a/src/BitfieldMan.h b/src/BitfieldMan.h
index fa856c08..fa0ac09f 100644
--- a/src/BitfieldMan.h
+++ b/src/BitfieldMan.h
@@ -39,8 +39,6 @@
#include <vector>
-#include "SharedHandle.h"
-
namespace aria2 {
class BitfieldMan {
diff --git a/src/BtAbortOutstandingRequestEvent.cc b/src/BtAbortOutstandingRequestEvent.cc
index e015a3f3..6afc6f60 100644
--- a/src/BtAbortOutstandingRequestEvent.cc
+++ b/src/BtAbortOutstandingRequestEvent.cc
@@ -38,7 +38,7 @@
namespace aria2 {
BtAbortOutstandingRequestEvent::BtAbortOutstandingRequestEvent
-(const SharedHandle<Piece>& piece)
+(const std::shared_ptr<Piece>& piece)
: piece_(piece)
{}
diff --git a/src/BtAbortOutstandingRequestEvent.h b/src/BtAbortOutstandingRequestEvent.h
index cd58d50e..b93cd0eb 100644
--- a/src/BtAbortOutstandingRequestEvent.h
+++ b/src/BtAbortOutstandingRequestEvent.h
@@ -36,7 +36,8 @@
#define D_BT_ABORT_OUTSTANDING_REQUEST_EVENT_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -44,12 +45,12 @@ class Piece;
class BtAbortOutstandingRequestEvent {
private:
- SharedHandle<Piece> piece_;
+ std::shared_ptr<Piece> piece_;
public:
- BtAbortOutstandingRequestEvent(const SharedHandle<Piece>& piece);
+ BtAbortOutstandingRequestEvent(const std::shared_ptr<Piece>& piece);
~BtAbortOutstandingRequestEvent();
- const SharedHandle<Piece>& getPiece() const { return piece_; }
+ const std::shared_ptr<Piece>& getPiece() const { return piece_; }
};
} // namespace aria2
diff --git a/src/BtAllowedFastMessage.cc b/src/BtAllowedFastMessage.cc
index e0fa3b9b..9400f5b5 100644
--- a/src/BtAllowedFastMessage.cc
+++ b/src/BtAllowedFastMessage.cc
@@ -65,7 +65,7 @@ void BtAllowedFastMessage::doReceivedAction() {
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
- ThisProgressUpdate(const SharedHandle<Peer>& peer, size_t index)
+ ThisProgressUpdate(const std::shared_ptr<Peer>& peer, size_t index)
: peer(peer), index(index) {}
virtual void update(size_t length, bool complete)
{
@@ -73,7 +73,7 @@ struct ThisProgressUpdate : public ProgressUpdate {
peer->addAmAllowedIndex(index);
}
}
- SharedHandle<Peer> peer;
+ std::shared_ptr<Peer> peer;
size_t index;
};
} // namespace
diff --git a/src/BtAnnounce.h b/src/BtAnnounce.h
index a660b9ba..de1a0524 100644
--- a/src/BtAnnounce.h
+++ b/src/BtAnnounce.h
@@ -38,9 +38,9 @@
#include "common.h"
#include <string>
+#include <memory>
#include "a2time.h"
-#include "SharedHandle.h"
namespace aria2 {
@@ -68,7 +68,7 @@ public:
*/
virtual std::string getAnnounceUrl() = 0;
- virtual SharedHandle<UDPTrackerRequest>
+ virtual std::shared_ptr<UDPTrackerRequest>
createUDPTrackerRequest(const std::string& remoteAddr, uint16_t remotePort,
uint16_t localPort) = 0;
@@ -104,7 +104,7 @@ public:
size_t trackerResponseLength) = 0;
virtual void processUDPTrackerResponse
- (const SharedHandle<UDPTrackerRequest>& req) = 0;
+ (const std::shared_ptr<UDPTrackerRequest>& req) = 0;
/**
* Returns true if no more announce is needed.
diff --git a/src/BtCheckIntegrityEntry.cc b/src/BtCheckIntegrityEntry.cc
index f7428bff..8121d869 100644
--- a/src/BtCheckIntegrityEntry.cc
+++ b/src/BtCheckIntegrityEntry.cc
@@ -51,19 +51,19 @@ BtCheckIntegrityEntry::~BtCheckIntegrityEntry() {}
void BtCheckIntegrityEntry::onDownloadIncomplete
(std::vector<Command*>& commands, DownloadEngine* e)
{
- const SharedHandle<PieceStorage>& ps = getRequestGroup()->getPieceStorage();
+ const std::shared_ptr<PieceStorage>& ps = getRequestGroup()->getPieceStorage();
ps->onDownloadIncomplete();
if(getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY)) {
return;
}
- const SharedHandle<DiskAdaptor>& diskAdaptor = ps->getDiskAdaptor();
+ const std::shared_ptr<DiskAdaptor>& diskAdaptor = ps->getDiskAdaptor();
if(diskAdaptor->isReadOnlyEnabled()) {
// Now reopen DiskAdaptor with read only disabled.
diskAdaptor->closeFile();
diskAdaptor->disableReadOnly();
diskAdaptor->openFile();
}
- SharedHandle<BtFileAllocationEntry> entry
+ std::shared_ptr<BtFileAllocationEntry> entry
(new BtFileAllocationEntry(getRequestGroup()));
proceedFileAllocation(commands, entry, e);
}
@@ -77,7 +77,7 @@ void BtCheckIntegrityEntry::onDownloadFinished
// behavior.
if(!getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY) &&
getRequestGroup()->getOption()->getAsBool(PREF_BT_HASH_CHECK_SEED)) {
- SharedHandle<BtFileAllocationEntry> entry
+ std::shared_ptr<BtFileAllocationEntry> entry
(new BtFileAllocationEntry(getRequestGroup()));
proceedFileAllocation(commands, entry, e);
}
diff --git a/src/BtChokeMessage.cc b/src/BtChokeMessage.cc
index ac82bd0a..e8ac9bdf 100644
--- a/src/BtChokeMessage.cc
+++ b/src/BtChokeMessage.cc
@@ -67,7 +67,7 @@ bool BtChokeMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
- ThisProgressUpdate(const SharedHandle<Peer>& peer,
+ ThisProgressUpdate(const std::shared_ptr<Peer>& peer,
BtMessageDispatcher* disp)
: peer(peer), disp(disp) {}
virtual void update(size_t length, bool complete)
@@ -77,7 +77,7 @@ struct ThisProgressUpdate : public ProgressUpdate {
disp->doChokingAction();
}
}
- SharedHandle<Peer> peer;
+ std::shared_ptr<Peer> peer;
BtMessageDispatcher* disp;
};
} // namespace
diff --git a/src/BtDependency.cc b/src/BtDependency.cc
index 8862e9c3..9c9976bf 100644
--- a/src/BtDependency.cc
+++ b/src/BtDependency.cc
@@ -54,7 +54,7 @@ namespace aria2 {
BtDependency::BtDependency
(RequestGroup* dependant,
- const SharedHandle<RequestGroup>& dependee)
+ const std::shared_ptr<RequestGroup>& dependee)
: dependant_(dependant),
dependee_(dependee)
{}
@@ -62,8 +62,8 @@ BtDependency::BtDependency
BtDependency::~BtDependency() {}
namespace {
-void copyValues(const SharedHandle<FileEntry>& d,
- const SharedHandle<FileEntry>& s)
+void copyValues(const std::shared_ptr<FileEntry>& d,
+ const std::shared_ptr<FileEntry>& s)
{
d->setRequested(true);
d->setPath(s->getPath());
@@ -77,8 +77,8 @@ void copyValues(const SharedHandle<FileEntry>& d,
namespace {
struct EntryCmp {
bool operator()
- (const SharedHandle<FileEntry>& lhs,
- const SharedHandle<FileEntry>& rhs) const
+ (const std::shared_ptr<FileEntry>& lhs,
+ const std::shared_ptr<FileEntry>& rhs) const
{
return lhs->getOriginalName() < rhs->getOriginalName();
}
@@ -91,17 +91,17 @@ bool BtDependency::resolve()
return true;
}
if(dependee_->getNumCommand() == 0 && dependee_->downloadFinished()) {
- SharedHandle<RequestGroup> dependee = dependee_;
+ std::shared_ptr<RequestGroup> dependee = dependee_;
// cut reference here
dependee_.reset();
- SharedHandle<DownloadContext> context(new DownloadContext());
+ std::shared_ptr<DownloadContext> context(new DownloadContext());
try {
- SharedHandle<DiskAdaptor> diskAdaptor =
+ std::shared_ptr<DiskAdaptor> diskAdaptor =
dependee->getPieceStorage()->getDiskAdaptor();
diskAdaptor->openExistingFile();
std::string content = util::toString(diskAdaptor);
if(dependee->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
- SharedHandle<TorrentAttribute> attrs =
+ std::shared_ptr<TorrentAttribute> attrs =
bittorrent::getTorrentAttrs(dependee->getDownloadContext());
bittorrent::loadFromMemory
(bittorrent::metadata2Torrent(content, attrs), context,
@@ -115,9 +115,9 @@ bool BtDependency::resolve()
bittorrent::adjustAnnounceUri(bittorrent::getTorrentAttrs(context),
dependant_->getOption());
}
- const std::vector<SharedHandle<FileEntry> >& fileEntries =
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
context->getFileEntries();
- const std::vector<SharedHandle<FileEntry> >& dependantFileEntries =
+ const std::vector<std::shared_ptr<FileEntry> >& dependantFileEntries =
dependant_->getDownloadContext()->getFileEntries();
// If dependant's FileEntry::getOriginalName() is empty, we
// assume that torrent is single file. In Metalink3, this is
@@ -126,9 +126,9 @@ bool BtDependency::resolve()
dependantFileEntries[0]->getOriginalName().empty()) {
copyValues(fileEntries[0], dependantFileEntries[0]);
} else {
- std::vector<SharedHandle<FileEntry> > destFiles;
+ std::vector<std::shared_ptr<FileEntry> > destFiles;
destFiles.reserve(fileEntries.size());
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
(*i)->setRequested(false);
destFiles.push_back(*i);
@@ -137,10 +137,10 @@ bool BtDependency::resolve()
// Copy file path in dependant_'s FileEntries to newly created
// context's FileEntries to endorse the path structure of
// dependant_. URIs and singleHostMultiConnection are also copied.
- for(std::vector<SharedHandle<FileEntry> >::const_iterator s =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator s =
dependantFileEntries.begin(), eoi = dependantFileEntries.end();
s != eoi; ++s){
- std::vector<SharedHandle<FileEntry> >::const_iterator d =
+ std::vector<std::shared_ptr<FileEntry> >::const_iterator d =
std::lower_bound(destFiles.begin(), destFiles.end(), *s,
EntryCmp());
if(d == destFiles.end() ||
diff --git a/src/BtDependency.h b/src/BtDependency.h
index ffb9175b..5f8ba2cb 100644
--- a/src/BtDependency.h
+++ b/src/BtDependency.h
@@ -36,7 +36,8 @@
#define D_BT_DEPENDENCY_H
#include "Dependency.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -47,10 +48,10 @@ class BtDependency : public Dependency
{
private:
RequestGroup* dependant_;
- SharedHandle<RequestGroup> dependee_;
+ std::shared_ptr<RequestGroup> dependee_;
public:
BtDependency(RequestGroup* dependant,
- const SharedHandle<RequestGroup>& dependee);
+ const std::shared_ptr<RequestGroup>& dependee);
virtual ~BtDependency();
diff --git a/src/BtExtendedMessage.cc b/src/BtExtendedMessage.cc
index c9281be8..faa1934b 100644
--- a/src/BtExtendedMessage.cc
+++ b/src/BtExtendedMessage.cc
@@ -51,7 +51,7 @@ namespace aria2 {
const char BtExtendedMessage::NAME[] = "extended";
BtExtendedMessage::BtExtendedMessage
-(const SharedHandle<ExtensionMessage>& extensionMessage):
+(const std::shared_ptr<ExtensionMessage>& extensionMessage):
SimpleBtMessage(ID, NAME),
extensionMessage_(extensionMessage),
msgLength_(0)
@@ -97,14 +97,14 @@ std::string BtExtendedMessage::toString() const {
}
BtExtendedMessage*
-BtExtendedMessage::create(const SharedHandle<ExtensionMessageFactory>& factory,
- const SharedHandle<Peer>& peer,
+BtExtendedMessage::create(const std::shared_ptr<ExtensionMessageFactory>& factory,
+ const std::shared_ptr<Peer>& peer,
const unsigned char* data, size_t dataLength)
{
bittorrent::assertPayloadLengthGreater(1, dataLength, NAME);
bittorrent::assertID(ID, data, NAME);
assert(factory);
- SharedHandle<ExtensionMessage> extmsg = factory->createMessage(data+1,
+ std::shared_ptr<ExtensionMessage> extmsg = factory->createMessage(data+1,
dataLength-1);
BtExtendedMessage* message(new BtExtendedMessage(extmsg));
return message;
diff --git a/src/BtExtendedMessage.h b/src/BtExtendedMessage.h
index e4be471b..092b9df5 100644
--- a/src/BtExtendedMessage.h
+++ b/src/BtExtendedMessage.h
@@ -44,12 +44,12 @@ class ExtensionMessageFactory;
class BtExtendedMessage:public SimpleBtMessage
{
private:
- SharedHandle<ExtensionMessage> extensionMessage_;
+ std::shared_ptr<ExtensionMessage> extensionMessage_;
size_t msgLength_;
public:
- BtExtendedMessage(const SharedHandle<ExtensionMessage>& extensionMessage =
- SharedHandle<ExtensionMessage>());
+ BtExtendedMessage(const std::shared_ptr<ExtensionMessage>& extensionMessage =
+ std::shared_ptr<ExtensionMessage>());
virtual ~BtExtendedMessage();
static const uint8_t ID = 20;
@@ -57,8 +57,8 @@ public:
static const char NAME[];
static BtExtendedMessage* create
- (const SharedHandle<ExtensionMessageFactory>& factory,
- const SharedHandle<Peer>& peer,
+ (const std::shared_ptr<ExtensionMessageFactory>& factory,
+ const std::shared_ptr<Peer>& peer,
const unsigned char* data,
size_t dataLength);
@@ -72,7 +72,7 @@ public:
virtual std::string toString() const;
- const SharedHandle<ExtensionMessage>& getExtensionMessage() const
+ const std::shared_ptr<ExtensionMessage>& getExtensionMessage() const
{
return extensionMessage_;
}
diff --git a/src/BtFileAllocationEntry.cc b/src/BtFileAllocationEntry.cc
index debeacdc..7b96f1c4 100644
--- a/src/BtFileAllocationEntry.cc
+++ b/src/BtFileAllocationEntry.cc
@@ -67,7 +67,7 @@ void BtFileAllocationEntry::prepareForNextAction
// For DownloadContext::resetDownloadStartTime(), see also
// RequestGroup::createInitialCommand()
getRequestGroup()->getDownloadContext()->resetDownloadStartTime();
- const std::vector<SharedHandle<FileEntry> >& fileEntries =
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
getRequestGroup()->getDownloadContext()->getFileEntries();
if(isUriSuppliedForRequsetFileEntry
(fileEntries.begin(), fileEntries.end())) {
@@ -75,7 +75,7 @@ void BtFileAllocationEntry::prepareForNextAction
}
} else {
#ifdef __MINGW32__
- const SharedHandle<DiskAdaptor>& diskAdaptor =
+ const std::shared_ptr<DiskAdaptor>& diskAdaptor =
getRequestGroup()->getPieceStorage()->getDiskAdaptor();
if(!diskAdaptor->isReadOnlyEnabled()) {
// On Windows, if aria2 opens files with GENERIC_WRITE access
diff --git a/src/BtHandshakeMessage.cc b/src/BtHandshakeMessage.cc
index f1968f40..bdc084ce 100644
--- a/src/BtHandshakeMessage.cc
+++ b/src/BtHandshakeMessage.cc
@@ -75,10 +75,10 @@ void BtHandshakeMessage::init() {
reserved_[5] |= 0x10u;
}
-SharedHandle<BtHandshakeMessage>
+std::shared_ptr<BtHandshakeMessage>
BtHandshakeMessage::create(const unsigned char* data, size_t dataLength)
{
- SharedHandle<BtHandshakeMessage> message(new BtHandshakeMessage());
+ std::shared_ptr<BtHandshakeMessage> message(new BtHandshakeMessage());
message->pstrlen_ = data[0];
memcpy(message->pstr_, &data[1], PSTR_LENGTH);
memcpy(message->reserved_, &data[20], RESERVED_LENGTH);
diff --git a/src/BtHandshakeMessage.h b/src/BtHandshakeMessage.h
index 6da8fa2d..14d967c4 100644
--- a/src/BtHandshakeMessage.h
+++ b/src/BtHandshakeMessage.h
@@ -60,7 +60,7 @@ public:
*/
BtHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId);
- static SharedHandle<BtHandshakeMessage>
+ static std::shared_ptr<BtHandshakeMessage>
create(const unsigned char* data, size_t dataLength);
virtual ~BtHandshakeMessage() {
diff --git a/src/BtInteractive.h b/src/BtInteractive.h
index bec4069f..56cb4e2a 100644
--- a/src/BtInteractive.h
+++ b/src/BtInteractive.h
@@ -36,7 +36,8 @@
#define D_BT_INTERACTIVE_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -48,9 +49,9 @@ public:
virtual void initiateHandshake() = 0;
- virtual SharedHandle<BtMessage> receiveHandshake(bool quickReply = false) = 0;
+ virtual std::shared_ptr<BtMessage> receiveHandshake(bool quickReply = false) = 0;
- virtual SharedHandle<BtMessage> receiveAndSendHandshake() = 0;
+ virtual std::shared_ptr<BtMessage> receiveAndSendHandshake() = 0;
virtual void doPostHandshakeProcessing() = 0;
diff --git a/src/BtInterestedMessage.cc b/src/BtInterestedMessage.cc
index 8fafb399..e70b79b4 100644
--- a/src/BtInterestedMessage.cc
+++ b/src/BtInterestedMessage.cc
@@ -69,7 +69,7 @@ bool BtInterestedMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
- ThisProgressUpdate(const SharedHandle<Peer>& peer)
+ ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
: peer(peer) {}
virtual void update(size_t length, bool complete)
{
@@ -77,7 +77,7 @@ struct ThisProgressUpdate : public ProgressUpdate {
peer->amInterested(true);
}
}
- SharedHandle<Peer> peer;
+ std::shared_ptr<Peer> peer;
};
} // namespace
@@ -87,7 +87,7 @@ ProgressUpdate* BtInterestedMessage::getProgressUpdate()
}
void BtInterestedMessage::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
diff --git a/src/BtInterestedMessage.h b/src/BtInterestedMessage.h
index bc10b208..392086f3 100644
--- a/src/BtInterestedMessage.h
+++ b/src/BtInterestedMessage.h
@@ -44,7 +44,7 @@ class BtInterestedMessage;
class BtInterestedMessage : public ZeroBtMessage {
private:
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
public:
BtInterestedMessage();
virtual ~BtInterestedMessage();
@@ -62,7 +62,7 @@ public:
virtual ProgressUpdate* getProgressUpdate();
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
};
} // namespace aria2
diff --git a/src/BtLeecherStateChoke.cc b/src/BtLeecherStateChoke.cc
index 1442d46a..7707ea55 100644
--- a/src/BtLeecherStateChoke.cc
+++ b/src/BtLeecherStateChoke.cc
@@ -52,7 +52,7 @@ BtLeecherStateChoke::BtLeecherStateChoke()
BtLeecherStateChoke::~BtLeecherStateChoke() {}
-BtLeecherStateChoke::PeerEntry::PeerEntry(const SharedHandle<Peer>& peer):
+BtLeecherStateChoke::PeerEntry::PeerEntry(const std::shared_ptr<Peer>& peer):
peer_(peer), downloadSpeed_(peer->calculateDownloadSpeed()),
// peer must be interested to us and sent block in the last 30 seconds
regularUnchoker_
@@ -86,7 +86,7 @@ BtLeecherStateChoke::PeerEntry& BtLeecherStateChoke::PeerEntry::operator=
BtLeecherStateChoke::PeerEntry::~PeerEntry() {}
-const SharedHandle<Peer>& BtLeecherStateChoke::PeerEntry::getPeer() const
+const std::shared_ptr<Peer>& BtLeecherStateChoke::PeerEntry::getPeer() const
{
return peer_;
}
diff --git a/src/BtLeecherStateChoke.h b/src/BtLeecherStateChoke.h
index 64c191fe..cfe0cfc0 100644
--- a/src/BtLeecherStateChoke.h
+++ b/src/BtLeecherStateChoke.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
#include "PeerStorage.h"
@@ -55,11 +55,11 @@ private:
class PeerEntry {
private:
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
int downloadSpeed_;
bool regularUnchoker_;
public:
- PeerEntry(const SharedHandle<Peer>& peer);
+ PeerEntry(const std::shared_ptr<Peer>& peer);
PeerEntry(const PeerEntry& c);
~PeerEntry();
@@ -69,7 +69,7 @@ private:
void swap(PeerEntry& c);
- const SharedHandle<Peer>& getPeer() const;
+ const std::shared_ptr<Peer>& getPeer() const;
int getDownloadSpeed() const;
diff --git a/src/BtMessageDispatcher.h b/src/BtMessageDispatcher.h
index 24234f9a..ed4c0bb7 100644
--- a/src/BtMessageDispatcher.h
+++ b/src/BtMessageDispatcher.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "RequestSlot.h"
namespace aria2 {
@@ -51,19 +51,19 @@ class BtMessageDispatcher {
public:
virtual ~BtMessageDispatcher() {}
- virtual void addMessageToQueue(const SharedHandle<BtMessage>& btMessage) = 0;
+ virtual void addMessageToQueue(const std::shared_ptr<BtMessage>& btMessage) = 0;
virtual void
- addMessageToQueue(const std::vector<SharedHandle<BtMessage> >& btMessages) =0;
+ addMessageToQueue(const std::vector<std::shared_ptr<BtMessage> >& btMessages) =0;
virtual void sendMessages() = 0;
virtual void doCancelSendingPieceAction
(size_t index, int32_t begin, int32_t length) = 0;
- virtual void doCancelSendingPieceAction(const SharedHandle<Piece>& piece) = 0;
+ virtual void doCancelSendingPieceAction(const std::shared_ptr<Piece>& piece) = 0;
- virtual void doAbortOutstandingRequestAction(const SharedHandle<Piece>& piece) = 0;
+ virtual void doAbortOutstandingRequestAction(const std::shared_ptr<Piece>& piece) = 0;
virtual void doChokedAction() = 0;
diff --git a/src/BtMessageFactory.h b/src/BtMessageFactory.h
index 963b373c..cb244d9b 100644
--- a/src/BtMessageFactory.h
+++ b/src/BtMessageFactory.h
@@ -36,7 +36,8 @@
#define D_BT_MESSAGE_FACTORY_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -49,52 +50,52 @@ class BtMessageFactory {
public:
virtual ~BtMessageFactory() {}
- virtual SharedHandle<BtMessage>
+ virtual std::shared_ptr<BtMessage>
createBtMessage(const unsigned char* msg, size_t msgLength) = 0;
- virtual SharedHandle<BtHandshakeMessage>
+ virtual std::shared_ptr<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* msg, size_t msgLength) = 0;
- virtual SharedHandle<BtHandshakeMessage>
+ virtual std::shared_ptr<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* infoHash,
const unsigned char* peerId) = 0;
- virtual SharedHandle<BtMessage>
- createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex) = 0;
+ virtual std::shared_ptr<BtMessage>
+ createRequestMessage(const std::shared_ptr<Piece>& piece, size_t blockIndex) = 0;
- virtual SharedHandle<BtMessage>
+ virtual std::shared_ptr<BtMessage>
createCancelMessage(size_t index, int32_t begin, int32_t length) = 0;
- virtual SharedHandle<BtMessage>
+ virtual std::shared_ptr<BtMessage>
createPieceMessage(size_t index, int32_t begin, int32_t length) = 0;
- virtual SharedHandle<BtMessage> createHaveMessage(size_t index) = 0;
+ virtual std::shared_ptr<BtMessage> createHaveMessage(size_t index) = 0;
- virtual SharedHandle<BtMessage> createChokeMessage() = 0;
+ virtual std::shared_ptr<BtMessage> createChokeMessage() = 0;
- virtual SharedHandle<BtMessage> createUnchokeMessage() = 0;
+ virtual std::shared_ptr<BtMessage> createUnchokeMessage() = 0;
- virtual SharedHandle<BtMessage> createInterestedMessage() = 0;
+ virtual std::shared_ptr<BtMessage> createInterestedMessage() = 0;
- virtual SharedHandle<BtMessage> createNotInterestedMessage() = 0;
+ virtual std::shared_ptr<BtMessage> createNotInterestedMessage() = 0;
- virtual SharedHandle<BtMessage> createBitfieldMessage() = 0;
+ virtual std::shared_ptr<BtMessage> createBitfieldMessage() = 0;
- virtual SharedHandle<BtMessage> createKeepAliveMessage() = 0;
+ virtual std::shared_ptr<BtMessage> createKeepAliveMessage() = 0;
- virtual SharedHandle<BtMessage> createHaveAllMessage() = 0;
+ virtual std::shared_ptr<BtMessage> createHaveAllMessage() = 0;
- virtual SharedHandle<BtMessage> createHaveNoneMessage() = 0;
+ virtual std::shared_ptr<BtMessage> createHaveNoneMessage() = 0;
- virtual SharedHandle<BtMessage>
+ virtual std::shared_ptr<BtMessage>
createRejectMessage(size_t index, int32_t begin, int32_t length) = 0;
- virtual SharedHandle<BtMessage> createAllowedFastMessage(size_t index) = 0;
+ virtual std::shared_ptr<BtMessage> createAllowedFastMessage(size_t index) = 0;
- virtual SharedHandle<BtMessage> createPortMessage(uint16_t port) = 0;
+ virtual std::shared_ptr<BtMessage> createPortMessage(uint16_t port) = 0;
- virtual SharedHandle<BtMessage>
- createBtExtendedMessage(const SharedHandle<ExtensionMessage>& msg) = 0;
+ virtual std::shared_ptr<BtMessage>
+ createBtExtendedMessage(const std::shared_ptr<ExtensionMessage>& msg) = 0;
};
} // namespace aria2
diff --git a/src/BtMessageReceiver.h b/src/BtMessageReceiver.h
index f9500b3d..4a7ef23c 100644
--- a/src/BtMessageReceiver.h
+++ b/src/BtMessageReceiver.h
@@ -36,7 +36,8 @@
#define D_BT_MESSAGE_RECEIVER_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -47,11 +48,11 @@ class BtMessageReceiver {
public:
virtual ~BtMessageReceiver() {}
- virtual SharedHandle<BtHandshakeMessage> receiveHandshake(bool quickReply = false) = 0;
+ virtual std::shared_ptr<BtHandshakeMessage> receiveHandshake(bool quickReply = false) = 0;
- virtual SharedHandle<BtHandshakeMessage> receiveAndSendHandshake() = 0;
+ virtual std::shared_ptr<BtHandshakeMessage> receiveAndSendHandshake() = 0;
- virtual SharedHandle<BtMessage> receiveMessage() = 0;
+ virtual std::shared_ptr<BtMessage> receiveMessage() = 0;
};
} // namespace aria2
diff --git a/src/BtNotInterestedMessage.cc b/src/BtNotInterestedMessage.cc
index 60b810a4..eca078d5 100644
--- a/src/BtNotInterestedMessage.cc
+++ b/src/BtNotInterestedMessage.cc
@@ -69,7 +69,7 @@ bool BtNotInterestedMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
- ThisProgressUpdate(const SharedHandle<Peer>& peer)
+ ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
: peer(peer) {}
virtual void update(size_t length, bool complete)
{
@@ -77,7 +77,7 @@ struct ThisProgressUpdate : public ProgressUpdate {
peer->amInterested(false);
}
}
- SharedHandle<Peer> peer;
+ std::shared_ptr<Peer> peer;
};
} // namespace
@@ -87,7 +87,7 @@ ProgressUpdate* BtNotInterestedMessage::getProgressUpdate()
}
void BtNotInterestedMessage::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
diff --git a/src/BtNotInterestedMessage.h b/src/BtNotInterestedMessage.h
index fd9a5844..0a1f4fd7 100644
--- a/src/BtNotInterestedMessage.h
+++ b/src/BtNotInterestedMessage.h
@@ -44,7 +44,7 @@ class BtNotInterestedMessage;
class BtNotInterestedMessage : public ZeroBtMessage {
private:
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
public:
BtNotInterestedMessage();
virtual ~BtNotInterestedMessage();
@@ -62,7 +62,7 @@ public:
virtual ProgressUpdate* getProgressUpdate();
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
};
} // namespace aria2
diff --git a/src/BtPieceMessage.cc b/src/BtPieceMessage.cc
index 04025f48..c0abf66b 100644
--- a/src/BtPieceMessage.cc
+++ b/src/BtPieceMessage.cc
@@ -107,7 +107,7 @@ void BtPieceMessage::doReceivedAction()
downloadContext_->updateDownloadLength(blockLength_);
if(!RequestSlot::isNull(slot)) {
getPeer()->snubbing(false);
- SharedHandle<Piece> piece = getPieceStorage()->getPiece(index_);
+ std::shared_ptr<Piece> piece = getPieceStorage()->getPiece(index_);
int64_t offset =
static_cast<int64_t>(index_)*downloadContext_->getPieceLength()+begin_;
A2_LOG_DEBUG(fmt(MSG_PIECE_RECEIVED,
@@ -179,7 +179,7 @@ size_t BtPieceMessage::getMessageHeaderLength()
namespace {
struct PieceSendUpdate : public ProgressUpdate {
- PieceSendUpdate(const SharedHandle<Peer>& peer, size_t headerLength)
+ PieceSendUpdate(const std::shared_ptr<Peer>& peer, size_t headerLength)
: peer(peer), headerLength(headerLength) {}
virtual void update(size_t length, bool complete)
{
@@ -190,7 +190,7 @@ struct PieceSendUpdate : public ProgressUpdate {
}
peer->updateUploadLength(length);
}
- SharedHandle<Peer> peer;
+ std::shared_ptr<Peer> peer;
size_t headerLength;
};
} // namespace
@@ -241,7 +241,7 @@ std::string BtPieceMessage::toString() const
begin_, blockLength_);
}
-bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
+bool BtPieceMessage::checkPieceHash(const std::shared_ptr<Piece>& piece)
{
if(!getPieceStorage()->isEndGame() && piece->isHashCalculated()) {
A2_LOG_DEBUG(fmt("Hash is available!! index=%lu",
@@ -262,7 +262,7 @@ bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
}
}
-void BtPieceMessage::onNewPiece(const SharedHandle<Piece>& piece)
+void BtPieceMessage::onNewPiece(const std::shared_ptr<Piece>& piece)
{
if(piece->getWrDiskCacheEntry()) {
// We flush cached data whenever an whole piece is retrieved.
@@ -283,7 +283,7 @@ void BtPieceMessage::onNewPiece(const SharedHandle<Piece>& piece)
getPieceStorage()->advertisePiece(getCuid(), piece->getIndex());
}
-void BtPieceMessage::onWrongPiece(const SharedHandle<Piece>& piece)
+void BtPieceMessage::onWrongPiece(const std::shared_ptr<Piece>& piece)
{
A2_LOG_INFO(fmt(MSG_GOT_WRONG_PIECE,
getCuid(),
@@ -303,7 +303,7 @@ void BtPieceMessage::onChokingEvent(const BtChokingEvent& event)
begin_,
blockLength_));
if(getPeer()->isFastExtensionEnabled()) {
- SharedHandle<BtMessage> rej =
+ std::shared_ptr<BtMessage> rej =
getBtMessageFactory()->createRejectMessage
(index_, begin_, blockLength_);
getBtMessageDispatcher()->addMessageToQueue(rej);
@@ -325,7 +325,7 @@ void BtPieceMessage::onCancelSendingPieceEvent
begin_,
blockLength_));
if(getPeer()->isFastExtensionEnabled()) {
- SharedHandle<BtMessage> rej =
+ std::shared_ptr<BtMessage> rej =
getBtMessageFactory()->createRejectMessage
(index_, begin_, blockLength_);
getBtMessageDispatcher()->addMessageToQueue(rej);
@@ -335,13 +335,13 @@ void BtPieceMessage::onCancelSendingPieceEvent
}
void BtPieceMessage::setDownloadContext
-(const SharedHandle<DownloadContext>& downloadContext)
+(const std::shared_ptr<DownloadContext>& downloadContext)
{
downloadContext_ = downloadContext;
}
void BtPieceMessage::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
diff --git a/src/BtPieceMessage.h b/src/BtPieceMessage.h
index 09fef7dc..d6488ba2 100644
--- a/src/BtPieceMessage.h
+++ b/src/BtPieceMessage.h
@@ -49,16 +49,16 @@ private:
int32_t begin_;
int32_t blockLength_;
const unsigned char* data_;
- SharedHandle<DownloadContext> downloadContext_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<DownloadContext> downloadContext_;
+ std::shared_ptr<PeerStorage> peerStorage_;
static size_t MESSAGE_HEADER_LENGTH;
- bool checkPieceHash(const SharedHandle<Piece>& piece);
+ bool checkPieceHash(const std::shared_ptr<Piece>& piece);
- void onNewPiece(const SharedHandle<Piece>& piece);
+ void onNewPiece(const std::shared_ptr<Piece>& piece);
- void onWrongPiece(const SharedHandle<Piece>& piece);
+ void onWrongPiece(const std::shared_ptr<Piece>& piece);
void pushPieceData(int64_t offset, int32_t length) const;
public:
@@ -88,9 +88,9 @@ public:
void setBlockLength(int32_t blockLength) { blockLength_ = blockLength; }
- void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& downloadContext);
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
static BtPieceMessage* create(const unsigned char* data, size_t dataLength);
diff --git a/src/BtPortMessage.cc b/src/BtPortMessage.cc
index 2d241d49..95e6e0bd 100644
--- a/src/BtPortMessage.cc
+++ b/src/BtPortMessage.cc
@@ -80,11 +80,11 @@ void BtPortMessage::doReceivedAction()
}
// node id is random at this point. When ping reply received, new DHTNode
// instance created with proper node ID and is added to a routing table.
- SharedHandle<DHTNode> node(new DHTNode());
+ std::shared_ptr<DHTNode> node(new DHTNode());
node->setIPAddress(getPeer()->getIPAddress());
node->setPort(port_);
{
- SharedHandle<DHTTask> task = taskFactory_->createPingTask(node);
+ std::shared_ptr<DHTTask> task = taskFactory_->createPingTask(node);
taskQueue_->addImmediateTask(task);
}
if(routingTable_->getNumBucket() == 1) {
diff --git a/src/BtPostDownloadHandler.cc b/src/BtPostDownloadHandler.cc
index 614b0c69..9c432192 100644
--- a/src/BtPostDownloadHandler.cc
+++ b/src/BtPostDownloadHandler.cc
@@ -57,7 +57,7 @@ namespace aria2 {
BtPostDownloadHandler::BtPostDownloadHandler()
{
- SharedHandle<RequestGroupCriteria> cri
+ std::shared_ptr<RequestGroupCriteria> cri
(new ContentTypeRequestGroupCriteria
(getBtContentTypes(), getBtExtensions()));
setCriteria(cri);
@@ -66,18 +66,18 @@ BtPostDownloadHandler::BtPostDownloadHandler()
BtPostDownloadHandler::~BtPostDownloadHandler() {}
void BtPostDownloadHandler::getNextRequestGroups
-(std::vector<SharedHandle<RequestGroup> >& groups,
+(std::vector<std::shared_ptr<RequestGroup> >& groups,
RequestGroup* requestGroup)
{
A2_LOG_INFO(fmt("Generating RequestGroups for Torrent file %s",
requestGroup->getFirstFilePath().c_str()));
- SharedHandle<ValueBase> torrent;
+ std::shared_ptr<ValueBase> torrent;
if(requestGroup->inMemoryDownload()) {
- const SharedHandle<DiskWriter>& dw =
- static_pointer_cast<AbstractSingleDiskAdaptor>
+ const std::shared_ptr<DiskWriter>& dw =
+ std::static_pointer_cast<AbstractSingleDiskAdaptor>
(requestGroup->getPieceStorage()->getDiskAdaptor())->getDiskWriter();
- const SharedHandle<bittorrent::BencodeDiskWriter>& bdw =
- static_pointer_cast<bittorrent::BencodeDiskWriter>(dw);
+ const std::shared_ptr<bittorrent::BencodeDiskWriter>& bdw =
+ std::static_pointer_cast<bittorrent::BencodeDiskWriter>(dw);
int error = bdw->finalize();
if(error == 0) {
torrent = bdw->getResult();
@@ -101,13 +101,13 @@ void BtPostDownloadHandler::getNextRequestGroups
throw DL_ABORT_EX2("Could not parse BitTorrent metainfo",
error_code::BENCODE_PARSE_ERROR);
}
- std::vector<SharedHandle<RequestGroup> > newRgs;
+ std::vector<std::shared_ptr<RequestGroup> > newRgs;
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
std::vector<std::string>(),
"",
torrent);
requestGroup->followedBy(newRgs.begin(), newRgs.end());
- SharedHandle<MetadataInfo> mi =
+ std::shared_ptr<MetadataInfo> mi =
createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(),
requestGroup->getDownloadContext());
if(mi) {
diff --git a/src/BtPostDownloadHandler.h b/src/BtPostDownloadHandler.h
index 7ff75520..4ddfddd6 100644
--- a/src/BtPostDownloadHandler.h
+++ b/src/BtPostDownloadHandler.h
@@ -47,7 +47,7 @@ public:
virtual ~BtPostDownloadHandler();
virtual void
- getNextRequestGroups(std::vector<SharedHandle<RequestGroup> >& groups,
+ getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
RequestGroup* requestGroup);
};
diff --git a/src/BtRegistry.cc b/src/BtRegistry.cc
index 273f0130..f38fd19f 100644
--- a/src/BtRegistry.cc
+++ b/src/BtRegistry.cc
@@ -54,10 +54,10 @@ BtRegistry::BtRegistry()
BtRegistry::~BtRegistry() {}
-const SharedHandle<DownloadContext>&
+const std::shared_ptr<DownloadContext>&
BtRegistry::getDownloadContext(a2_gid_t gid) const
{
- const SharedHandle<BtObject>& res = get(gid);
+ const std::shared_ptr<BtObject>& res = get(gid);
if(res) {
return res->downloadContext;
} else {
@@ -65,10 +65,10 @@ BtRegistry::getDownloadContext(a2_gid_t gid) const
}
}
-const SharedHandle<DownloadContext>&
+const std::shared_ptr<DownloadContext>&
BtRegistry::getDownloadContext(const std::string& infoHash) const
{
- for(std::map<a2_gid_t, SharedHandle<BtObject> >::const_iterator i =
+ for(std::map<a2_gid_t, std::shared_ptr<BtObject> >::const_iterator i =
pool_.begin(), eoi = pool_.end(); i != eoi; ++i) {
if(bittorrent::getTorrentAttrs((*i).second->downloadContext)->infoHash ==
infoHash) {
@@ -78,14 +78,14 @@ BtRegistry::getDownloadContext(const std::string& infoHash) const
return getNull<DownloadContext>();
}
-void BtRegistry::put(a2_gid_t gid, const SharedHandle<BtObject>& obj)
+void BtRegistry::put(a2_gid_t gid, const std::shared_ptr<BtObject>& obj)
{
pool_[gid] = obj;
}
-const SharedHandle<BtObject>& BtRegistry::get(a2_gid_t gid) const
+const std::shared_ptr<BtObject>& BtRegistry::get(a2_gid_t gid) const
{
- std::map<a2_gid_t, SharedHandle<BtObject> >::const_iterator i =
+ std::map<a2_gid_t, std::shared_ptr<BtObject> >::const_iterator i =
pool_.find(gid);
if(i == pool_.end()) {
return getNull<BtObject>();
@@ -104,24 +104,24 @@ void BtRegistry::removeAll() {
}
void BtRegistry::setLpdMessageReceiver
-(const SharedHandle<LpdMessageReceiver>& receiver)
+(const std::shared_ptr<LpdMessageReceiver>& receiver)
{
lpdMessageReceiver_ = receiver;
}
void BtRegistry::setUDPTrackerClient
-(const SharedHandle<UDPTrackerClient>& tracker)
+(const std::shared_ptr<UDPTrackerClient>& tracker)
{
udpTrackerClient_ = tracker;
}
BtObject::BtObject
-(const SharedHandle<DownloadContext>& downloadContext,
- const SharedHandle<PieceStorage>& pieceStorage,
- const SharedHandle<PeerStorage>& peerStorage,
- const SharedHandle<BtAnnounce>& btAnnounce,
- const SharedHandle<BtRuntime>& btRuntime,
- const SharedHandle<BtProgressInfoFile>& btProgressInfoFile)
+(const std::shared_ptr<DownloadContext>& downloadContext,
+ const std::shared_ptr<PieceStorage>& pieceStorage,
+ const std::shared_ptr<PeerStorage>& peerStorage,
+ const std::shared_ptr<BtAnnounce>& btAnnounce,
+ const std::shared_ptr<BtRuntime>& btRuntime,
+ const std::shared_ptr<BtProgressInfoFile>& btProgressInfoFile)
: downloadContext(downloadContext),
pieceStorage(pieceStorage),
peerStorage(peerStorage),
diff --git a/src/BtRegistry.h b/src/BtRegistry.h
index ea980a2a..052bcd16 100644
--- a/src/BtRegistry.h
+++ b/src/BtRegistry.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <map>
+#include <memory>
-#include "SharedHandle.h"
#include "RequestGroup.h"
namespace aria2 {
@@ -54,19 +54,19 @@ class LpdMessageReceiver;
class UDPTrackerClient;
struct BtObject {
- SharedHandle<DownloadContext> downloadContext;
- SharedHandle<PieceStorage> pieceStorage;
- SharedHandle<PeerStorage> peerStorage;
- SharedHandle<BtAnnounce> btAnnounce;
- SharedHandle<BtRuntime> btRuntime;
- SharedHandle<BtProgressInfoFile> btProgressInfoFile;
-
- BtObject(const SharedHandle<DownloadContext>& downloadContext,
- const SharedHandle<PieceStorage>& pieceStorage,
- const SharedHandle<PeerStorage>& peerStorage,
- const SharedHandle<BtAnnounce>& btAnnounce,
- const SharedHandle<BtRuntime>& btRuntime,
- const SharedHandle<BtProgressInfoFile>& btProgressInfoFile);
+ std::shared_ptr<DownloadContext> downloadContext;
+ std::shared_ptr<PieceStorage> pieceStorage;
+ std::shared_ptr<PeerStorage> peerStorage;
+ std::shared_ptr<BtAnnounce> btAnnounce;
+ std::shared_ptr<BtRuntime> btRuntime;
+ std::shared_ptr<BtProgressInfoFile> btProgressInfoFile;
+
+ BtObject(const std::shared_ptr<DownloadContext>& downloadContext,
+ const std::shared_ptr<PieceStorage>& pieceStorage,
+ const std::shared_ptr<PeerStorage>& peerStorage,
+ const std::shared_ptr<BtAnnounce>& btAnnounce,
+ const std::shared_ptr<BtRuntime>& btRuntime,
+ const std::shared_ptr<BtProgressInfoFile>& btProgressInfoFile);
BtObject();
@@ -79,31 +79,31 @@ struct BtObject {
class BtRegistry {
private:
- std::map<a2_gid_t, SharedHandle<BtObject> > pool_;
+ std::map<a2_gid_t, std::shared_ptr<BtObject> > pool_;
uint16_t tcpPort_;
// This is UDP port for DHT and UDP tracker. But currently UDP
// tracker is not supported in IPv6.
uint16_t udpPort_;
- SharedHandle<LpdMessageReceiver> lpdMessageReceiver_;
- SharedHandle<UDPTrackerClient> udpTrackerClient_;
+ std::shared_ptr<LpdMessageReceiver> lpdMessageReceiver_;
+ std::shared_ptr<UDPTrackerClient> udpTrackerClient_;
public:
BtRegistry();
~BtRegistry();
- const SharedHandle<DownloadContext>&
+ const std::shared_ptr<DownloadContext>&
getDownloadContext(a2_gid_t gid) const;
- const SharedHandle<DownloadContext>&
+ const std::shared_ptr<DownloadContext>&
getDownloadContext(const std::string& infoHash) const;
- void put(a2_gid_t gid, const SharedHandle<BtObject>& obj);
+ void put(a2_gid_t gid, const std::shared_ptr<BtObject>& obj);
- const SharedHandle<BtObject>& get(a2_gid_t gid) const;
+ const std::shared_ptr<BtObject>& get(a2_gid_t gid) const;
template<typename OutputIterator>
OutputIterator getAllDownloadContext(OutputIterator dest)
{
- for(std::map<a2_gid_t, SharedHandle<BtObject> >::const_iterator i =
+ for(std::map<a2_gid_t, std::shared_ptr<BtObject> >::const_iterator i =
pool_.begin(), eoi = pool_.end(); i != eoi; ++i) {
*dest++ = (*i).second->downloadContext;
}
@@ -132,14 +132,14 @@ public:
return udpPort_;
}
- void setLpdMessageReceiver(const SharedHandle<LpdMessageReceiver>& receiver);
- const SharedHandle<LpdMessageReceiver>& getLpdMessageReceiver() const
+ void setLpdMessageReceiver(const std::shared_ptr<LpdMessageReceiver>& receiver);
+ const std::shared_ptr<LpdMessageReceiver>& getLpdMessageReceiver() const
{
return lpdMessageReceiver_;
}
- void setUDPTrackerClient(const SharedHandle<UDPTrackerClient>& tracker);
- const SharedHandle<UDPTrackerClient>& getUDPTrackerClient() const
+ void setUDPTrackerClient(const std::shared_ptr<UDPTrackerClient>& tracker);
+ const std::shared_ptr<UDPTrackerClient>& getUDPTrackerClient() const
{
return udpTrackerClient_;
}
diff --git a/src/BtRequestFactory.h b/src/BtRequestFactory.h
index b1f58ad3..1e77f34d 100644
--- a/src/BtRequestFactory.h
+++ b/src/BtRequestFactory.h
@@ -38,8 +38,7 @@
#include "common.h"
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -50,9 +49,9 @@ class BtRequestFactory {
public:
virtual ~BtRequestFactory() {}
- virtual void addTargetPiece(const SharedHandle<Piece>& piece) = 0;
+ virtual void addTargetPiece(const std::shared_ptr<Piece>& piece) = 0;
- virtual void removeTargetPiece(const SharedHandle<Piece>& piece) = 0;
+ virtual void removeTargetPiece(const std::shared_ptr<Piece>& piece) = 0;
virtual void removeAllTargetPiece() = 0;
@@ -70,14 +69,14 @@ public:
* The number of objects returned is capped by max.
*/
virtual void createRequestMessages
- (std::vector<SharedHandle<BtMessage> >& requests, size_t max) = 0;
+ (std::vector<std::shared_ptr<BtMessage> >& requests, size_t max) = 0;
/**
* Use this method in end game mode.
*
*/
virtual void createRequestMessagesOnEndGame
- (std::vector<SharedHandle<BtMessage> >& requests, size_t max) = 0;
+ (std::vector<std::shared_ptr<BtMessage> >& requests, size_t max) = 0;
/**
* Stores the list of index of pieces added using addTargetPiece() into
diff --git a/src/BtRequestMessage.cc b/src/BtRequestMessage.cc
index 34473bf3..236b40d3 100644
--- a/src/BtRequestMessage.cc
+++ b/src/BtRequestMessage.cc
@@ -63,13 +63,13 @@ void BtRequestMessage::doReceivedAction()
(!getPeer()->amChoking() ||
(getPeer()->amChoking() &&
getPeer()->isInAmAllowedIndexSet(getIndex())))) {
- SharedHandle<BtMessage> msg =
+ std::shared_ptr<BtMessage> msg =
getBtMessageFactory()->createPieceMessage
(getIndex(), getBegin(), getLength());
getBtMessageDispatcher()->addMessageToQueue(msg);
} else {
if(getPeer()->isFastExtensionEnabled()) {
- SharedHandle<BtMessage> msg =
+ std::shared_ptr<BtMessage> msg =
getBtMessageFactory()->createRejectMessage
(getIndex(), getBegin(), getLength());
getBtMessageDispatcher()->addMessageToQueue(msg);
diff --git a/src/BtSeederStateChoke.cc b/src/BtSeederStateChoke.cc
index 57a96609..7b1439f8 100644
--- a/src/BtSeederStateChoke.cc
+++ b/src/BtSeederStateChoke.cc
@@ -53,7 +53,7 @@ BtSeederStateChoke::BtSeederStateChoke()
BtSeederStateChoke::~BtSeederStateChoke() {}
BtSeederStateChoke::PeerEntry::PeerEntry
-(const SharedHandle<Peer>& peer):
+(const std::shared_ptr<Peer>& peer):
peer_(peer),
outstandingUpload_(peer->countOutstandingUpload()),
lastAmUnchoking_(peer->getLastAmUnchoking()),
diff --git a/src/BtSeederStateChoke.h b/src/BtSeederStateChoke.h
index 5d7a6d35..c7342d52 100644
--- a/src/BtSeederStateChoke.h
+++ b/src/BtSeederStateChoke.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
#include "PeerStorage.h"
@@ -55,7 +55,7 @@ private:
class PeerEntry {
private:
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
size_t outstandingUpload_;
Timer lastAmUnchoking_;
bool recentUnchoking_;
@@ -63,7 +63,7 @@ private:
const static time_t TIME_FRAME = 20;
public:
- PeerEntry(const SharedHandle<Peer>& peer);
+ PeerEntry(const std::shared_ptr<Peer>& peer);
PeerEntry(const PeerEntry& c);
~PeerEntry();
@@ -73,7 +73,7 @@ private:
bool operator<(const PeerEntry& rhs) const;
- const SharedHandle<Peer>& getPeer() const { return peer_; }
+ const std::shared_ptr<Peer>& getPeer() const { return peer_; }
int getUploadSpeed() const { return uploadSpeed_; }
diff --git a/src/BtSetup.cc b/src/BtSetup.cc
index 50c52ef3..43457d86 100644
--- a/src/BtSetup.cc
+++ b/src/BtSetup.cc
@@ -98,15 +98,15 @@ void BtSetup::setup(std::vector<Command*>& commands,
if(!requestGroup->getDownloadContext()->hasAttribute(CTX_ATTR_BT)){
return;
}
- SharedHandle<TorrentAttribute> torrentAttrs =
+ std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(requestGroup->getDownloadContext());
bool metadataGetMode = torrentAttrs->metadata.empty();
- const SharedHandle<BtRegistry>& btReg = e->getBtRegistry();
- const SharedHandle<BtObject>& btObject = btReg->get(requestGroup->getGID());
- const SharedHandle<PieceStorage>& pieceStorage = btObject->pieceStorage;
- const SharedHandle<PeerStorage>& peerStorage = btObject->peerStorage;
- const SharedHandle<BtRuntime>& btRuntime = btObject->btRuntime;
- const SharedHandle<BtAnnounce>& btAnnounce = btObject->btAnnounce;
+ const std::shared_ptr<BtRegistry>& btReg = e->getBtRegistry();
+ const std::shared_ptr<BtObject>& btObject = btReg->get(requestGroup->getGID());
+ const std::shared_ptr<PieceStorage>& pieceStorage = btObject->pieceStorage;
+ const std::shared_ptr<PeerStorage>& peerStorage = btObject->peerStorage;
+ const std::shared_ptr<BtRuntime>& btRuntime = btObject->btRuntime;
+ const std::shared_ptr<BtAnnounce>& btAnnounce = btObject->btAnnounce;
// commands
{
TrackerWatcherCommand* c =
@@ -159,16 +159,16 @@ void BtSetup::setup(std::vector<Command*>& commands,
}
}
if(!metadataGetMode) {
- SharedHandle<UnionSeedCriteria> unionCri(new UnionSeedCriteria());
+ std::shared_ptr<UnionSeedCriteria> unionCri(new UnionSeedCriteria());
if(option->defined(PREF_SEED_TIME)) {
- SharedHandle<SeedCriteria> cri
+ std::shared_ptr<SeedCriteria> cri
(new TimeSeedCriteria(option->getAsInt(PREF_SEED_TIME)*60));
unionCri->addSeedCriteria(cri);
}
{
double ratio = option->getAsDouble(PREF_SEED_RATIO);
if(ratio > 0.0) {
- SharedHandle<ShareRatioSeedCriteria> cri
+ std::shared_ptr<ShareRatioSeedCriteria> cri
(new ShareRatioSeedCriteria(option->getAsDouble(PREF_SEED_RATIO),
requestGroup->getDownloadContext()));
cri->setPieceStorage(pieceStorage);
@@ -223,7 +223,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
(metadataGetMode || !torrentAttrs->privateTorrent)) {
if(!btReg->getLpdMessageReceiver()) {
A2_LOG_INFO("Initializing LpdMessageReceiver.");
- SharedHandle<LpdMessageReceiver> receiver
+ std::shared_ptr<LpdMessageReceiver> receiver
(new LpdMessageReceiver(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT));
bool initialized = false;
const std::string& lpdInterface =
@@ -263,7 +263,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
const unsigned char* infoHash =
bittorrent::getInfoHash(requestGroup->getDownloadContext());
A2_LOG_INFO("Initializing LpdMessageDispatcher.");
- SharedHandle<LpdMessageDispatcher> dispatcher
+ std::shared_ptr<LpdMessageDispatcher> dispatcher
(new LpdMessageDispatcher
(std::string(&infoHash[0], &infoHash[INFO_HASH_LENGTH]),
btReg->getTcpPort(),
diff --git a/src/BtStopDownloadCommand.h b/src/BtStopDownloadCommand.h
index 156ded76..b0dec361 100644
--- a/src/BtStopDownloadCommand.h
+++ b/src/BtStopDownloadCommand.h
@@ -36,7 +36,8 @@
#define D_BT_STOP_DOWNLOAD_COMMAND_H
#include "TimeBasedCommand.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -54,9 +55,9 @@ private:
Timer checkPoint_;
- SharedHandle<BtRuntime> btRuntime_;
+ std::shared_ptr<BtRuntime> btRuntime_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
public:
BtStopDownloadCommand
(cuid_t cuid,
@@ -68,12 +69,12 @@ public:
virtual void process();
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime)
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage)
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
diff --git a/src/BtUnchokeMessage.cc b/src/BtUnchokeMessage.cc
index 9dfd4a8e..36bda089 100644
--- a/src/BtUnchokeMessage.cc
+++ b/src/BtUnchokeMessage.cc
@@ -63,7 +63,7 @@ bool BtUnchokeMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
- ThisProgressUpdate(const SharedHandle<Peer>& peer)
+ ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
: peer(peer) {}
virtual void update(size_t length, bool complete)
{
@@ -71,7 +71,7 @@ struct ThisProgressUpdate : public ProgressUpdate {
peer->amChoking(false);
}
}
- SharedHandle<Peer> peer;
+ std::shared_ptr<Peer> peer;
};
} // namespace
diff --git a/src/CheckIntegrityCommand.cc b/src/CheckIntegrityCommand.cc
index c4284211..e2472496 100644
--- a/src/CheckIntegrityCommand.cc
+++ b/src/CheckIntegrityCommand.cc
@@ -50,7 +50,7 @@ namespace aria2 {
CheckIntegrityCommand::CheckIntegrityCommand
(cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e,
- const SharedHandle<CheckIntegrityEntry>& entry):
+ const std::shared_ptr<CheckIntegrityEntry>& entry):
RealtimeCommand(cuid, requestGroup, e),
entry_(entry)
{}
diff --git a/src/CheckIntegrityCommand.h b/src/CheckIntegrityCommand.h
index 6dce2ce2..3160d8d4 100644
--- a/src/CheckIntegrityCommand.h
+++ b/src/CheckIntegrityCommand.h
@@ -36,7 +36,8 @@
#define D_CHECK_INTEGRITY_COMMAND_H
#include "RealtimeCommand.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -44,12 +45,12 @@ class CheckIntegrityEntry;
class CheckIntegrityCommand : public RealtimeCommand {
private:
- SharedHandle<CheckIntegrityEntry> entry_;
+ std::shared_ptr<CheckIntegrityEntry> entry_;
public:
CheckIntegrityCommand(cuid_t cuid,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<CheckIntegrityEntry>& entry);
+ const std::shared_ptr<CheckIntegrityEntry>& entry);
virtual ~CheckIntegrityCommand();
diff --git a/src/CheckIntegrityDispatcherCommand.cc b/src/CheckIntegrityDispatcherCommand.cc
index 49fa965e..ed176cf6 100644
--- a/src/CheckIntegrityDispatcherCommand.cc
+++ b/src/CheckIntegrityDispatcherCommand.cc
@@ -45,7 +45,7 @@ namespace aria2 {
CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand
(cuid_t cuid,
- const SharedHandle<CheckIntegrityMan>& fileAllocMan,
+ const std::shared_ptr<CheckIntegrityMan>& fileAllocMan,
DownloadEngine* e)
: SequentialDispatcherCommand<CheckIntegrityEntry>(cuid, fileAllocMan, e)
{
@@ -53,7 +53,7 @@ CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand
}
Command* CheckIntegrityDispatcherCommand::createCommand
-(const SharedHandle<CheckIntegrityEntry>& entry)
+(const std::shared_ptr<CheckIntegrityEntry>& entry)
{
cuid_t newCUID = getDownloadEngine()->newCUID();
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Dispatching CheckIntegrityCommand CUID#%" PRId64 ".",
diff --git a/src/CheckIntegrityDispatcherCommand.h b/src/CheckIntegrityDispatcherCommand.h
index b491909c..4072bba1 100644
--- a/src/CheckIntegrityDispatcherCommand.h
+++ b/src/CheckIntegrityDispatcherCommand.h
@@ -47,11 +47,11 @@ class CheckIntegrityDispatcherCommand :
public:
CheckIntegrityDispatcherCommand
(cuid_t cuid,
- const SharedHandle<CheckIntegrityMan>& checkMan,
+ const std::shared_ptr<CheckIntegrityMan>& checkMan,
DownloadEngine* e);
protected:
virtual Command* createCommand
- (const SharedHandle<CheckIntegrityEntry>& entry);
+ (const std::shared_ptr<CheckIntegrityEntry>& entry);
};
} // namespace aria2
diff --git a/src/CheckIntegrityEntry.cc b/src/CheckIntegrityEntry.cc
index 3430fedb..57252118 100644
--- a/src/CheckIntegrityEntry.cc
+++ b/src/CheckIntegrityEntry.cc
@@ -86,7 +86,7 @@ void CheckIntegrityEntry::cutTrailingGarbage()
void CheckIntegrityEntry::proceedFileAllocation
(std::vector<Command*>& commands,
- const SharedHandle<FileAllocationEntry>& entry,
+ const std::shared_ptr<FileAllocationEntry>& entry,
DownloadEngine* e)
{
if(getRequestGroup()->needsFileAllocation()) {
@@ -97,7 +97,7 @@ void CheckIntegrityEntry::proceedFileAllocation
}
void CheckIntegrityEntry::setValidator
-(const SharedHandle<IteratableValidator>& validator)
+(const std::shared_ptr<IteratableValidator>& validator)
{
validator_ = validator;
}
diff --git a/src/CheckIntegrityEntry.h b/src/CheckIntegrityEntry.h
index 64fe0506..dc60bfbc 100644
--- a/src/CheckIntegrityEntry.h
+++ b/src/CheckIntegrityEntry.h
@@ -38,8 +38,8 @@
#include "RequestGroupEntry.h"
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "ProgressAwareEntry.h"
namespace aria2 {
@@ -51,12 +51,12 @@ class FileAllocationEntry;
class CheckIntegrityEntry : public RequestGroupEntry,
public ProgressAwareEntry {
private:
- SharedHandle<IteratableValidator> validator_;
+ std::shared_ptr<IteratableValidator> validator_;
protected:
- void setValidator(const SharedHandle<IteratableValidator>& validator);
+ void setValidator(const std::shared_ptr<IteratableValidator>& validator);
void proceedFileAllocation(std::vector<Command*>& commands,
- const SharedHandle<FileAllocationEntry>& entry,
+ const std::shared_ptr<FileAllocationEntry>& entry,
DownloadEngine* e);
public:
CheckIntegrityEntry(RequestGroup* requestGroup, Command* nextCommand = 0);
diff --git a/src/ChecksumCheckIntegrityEntry.cc b/src/ChecksumCheckIntegrityEntry.cc
index b02ae884..34e72635 100644
--- a/src/ChecksumCheckIntegrityEntry.cc
+++ b/src/ChecksumCheckIntegrityEntry.cc
@@ -52,14 +52,14 @@ ChecksumCheckIntegrityEntry::~ChecksumCheckIntegrityEntry() {}
bool ChecksumCheckIntegrityEntry::isValidationReady()
{
- const SharedHandle<DownloadContext>& dctx =
+ const std::shared_ptr<DownloadContext>& dctx =
getRequestGroup()->getDownloadContext();
return dctx->isChecksumVerificationAvailable();
}
void ChecksumCheckIntegrityEntry::initValidator()
{
- SharedHandle<IteratableChecksumValidator> validator
+ std::shared_ptr<IteratableChecksumValidator> validator
(new IteratableChecksumValidator(getRequestGroup()->getDownloadContext(),
getRequestGroup()->getPieceStorage()));
validator->init();
@@ -76,7 +76,7 @@ ChecksumCheckIntegrityEntry::onDownloadIncomplete
(std::vector<Command*>& commands, DownloadEngine* e)
{
if(redownload_) {
- SharedHandle<FileAllocationEntry> entry
+ std::shared_ptr<FileAllocationEntry> entry
(new StreamFileAllocationEntry(getRequestGroup(), popNextCommand()));
proceedFileAllocation(commands, entry, e);
}
diff --git a/src/ChunkChecksum.h b/src/ChunkChecksum.h
index 965840d1..f1c0580c 100644
--- a/src/ChunkChecksum.h
+++ b/src/ChunkChecksum.h
@@ -40,8 +40,6 @@
#include <string>
#include <vector>
-#include "SharedHandle.h"
-
namespace aria2 {
class ChunkChecksum {
diff --git a/src/ChunkedDecodingStreamFilter.cc b/src/ChunkedDecodingStreamFilter.cc
index 21b8502b..94334c1d 100644
--- a/src/ChunkedDecodingStreamFilter.cc
+++ b/src/ChunkedDecodingStreamFilter.cc
@@ -65,7 +65,7 @@ enum {
} // namespace
ChunkedDecodingStreamFilter::ChunkedDecodingStreamFilter
-(const SharedHandle<StreamFilter>& delegate):
+(const std::shared_ptr<StreamFilter>& delegate):
StreamFilter(delegate),
state_(PREV_CHUNK_SIZE),
chunkSize_(0),
@@ -77,8 +77,8 @@ ChunkedDecodingStreamFilter::~ChunkedDecodingStreamFilter() {}
void ChunkedDecodingStreamFilter::init() {}
ssize_t ChunkedDecodingStreamFilter::transform
-(const SharedHandle<BinaryStream>& out,
- const SharedHandle<Segment>& segment,
+(const std::shared_ptr<BinaryStream>& out,
+ const std::shared_ptr<Segment>& segment,
const unsigned char* inbuf, size_t inlen)
{
ssize_t outlen = 0;
diff --git a/src/ChunkedDecodingStreamFilter.h b/src/ChunkedDecodingStreamFilter.h
index 8aced1b3..9d0536f0 100644
--- a/src/ChunkedDecodingStreamFilter.h
+++ b/src/ChunkedDecodingStreamFilter.h
@@ -47,15 +47,15 @@ private:
size_t bytesProcessed_;
public:
ChunkedDecodingStreamFilter
- (const SharedHandle<StreamFilter>& delegate = SharedHandle<StreamFilter>());
+ (const std::shared_ptr<StreamFilter>& delegate = std::shared_ptr<StreamFilter>());
virtual ~ChunkedDecodingStreamFilter();
virtual void init();
virtual ssize_t transform
- (const SharedHandle<BinaryStream>& out,
- const SharedHandle<Segment>& segment,
+ (const std::shared_ptr<BinaryStream>& out,
+ const std::shared_ptr<Segment>& segment,
const unsigned char* inbuf, size_t inlen);
virtual bool finished();
diff --git a/src/ConnectCommand.cc b/src/ConnectCommand.cc
index cb075976..4bb6a33a 100644
--- a/src/ConnectCommand.cc
+++ b/src/ConnectCommand.cc
@@ -48,12 +48,12 @@
namespace aria2 {
ConnectCommand::ConnectCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<SocketCore>& s)
: AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
proxyRequest_(proxyRequest)
{
@@ -70,18 +70,18 @@ ConnectCommand::~ConnectCommand()
}
void ConnectCommand::setControlChain
-(const SharedHandle<ControlChain<ConnectCommand*> >& chain)
+(const std::shared_ptr<ControlChain<ConnectCommand*> >& chain)
{
chain_ = chain;
}
void ConnectCommand::setBackupConnectInfo
-(const SharedHandle<BackupConnectInfo>& info)
+(const std::shared_ptr<BackupConnectInfo>& info)
{
backupConnectionInfo_ = info;
}
-const SharedHandle<Request>& ConnectCommand::getProxyRequest() const
+const std::shared_ptr<Request>& ConnectCommand::getProxyRequest() const
{
return proxyRequest_;
}
@@ -89,7 +89,7 @@ const SharedHandle<Request>& ConnectCommand::getProxyRequest() const
bool ConnectCommand::executeInternal()
{
if(backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty()) {
- A2_LOG_INFO(fmt("CUID#%"PRId64" - Use backup connection address %s",
+ A2_LOG_INFO(fmt("CUID#%" PRId64 " - Use backup connection address %s",
getCuid(), backupConnectionInfo_->ipaddr.c_str()));
getDownloadEngine()->markBadIPAddress
(getRequest()->getConnectedHostname(),
diff --git a/src/ConnectCommand.h b/src/ConnectCommand.h
index 1f458ead..003f9b07 100644
--- a/src/ConnectCommand.h
+++ b/src/ConnectCommand.h
@@ -45,24 +45,24 @@ class BackupConnectInfo;
class ConnectCommand : public AbstractCommand {
public:
ConnectCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<SocketCore>& s);
virtual ~ConnectCommand();
void setControlChain
- (const SharedHandle<ControlChain<ConnectCommand*> >& chain);
- void setBackupConnectInfo(const SharedHandle<BackupConnectInfo>& info);
- const SharedHandle<Request>& getProxyRequest() const;
+ (const std::shared_ptr<ControlChain<ConnectCommand*> >& chain);
+ void setBackupConnectInfo(const std::shared_ptr<BackupConnectInfo>& info);
+ const std::shared_ptr<Request>& getProxyRequest() const;
protected:
virtual bool executeInternal();
virtual bool noCheck();
private:
- SharedHandle<Request> proxyRequest_;
- SharedHandle<BackupConnectInfo> backupConnectionInfo_;
- SharedHandle<ControlChain<ConnectCommand*> > chain_;
+ std::shared_ptr<Request> proxyRequest_;
+ std::shared_ptr<BackupConnectInfo> backupConnectionInfo_;
+ std::shared_ptr<ControlChain<ConnectCommand*> > chain_;
};
} // namespace aria2
diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc
index 5aa75046..b91e5410 100644
--- a/src/ConsoleStatCalc.cc
+++ b/src/ConsoleStatCalc.cc
@@ -96,7 +96,7 @@ protected:
} // namespace
namespace {
-void printSizeProgress(std::ostream& o, const SharedHandle<RequestGroup>& rg,
+void printSizeProgress(std::ostream& o, const std::shared_ptr<RequestGroup>& rg,
const TransferStat& stat,
const SizeFormatter& sizeFormatter)
{
@@ -144,7 +144,7 @@ void printProgressCompact(std::ostream& o, const DownloadEngine* e,
const size_t MAX_ITEM = 5;
for(RequestGroupList::const_iterator i = groups.begin(),
eoi = groups.end(); i != eoi && cnt < MAX_ITEM; ++i, ++cnt) {
- const SharedHandle<RequestGroup>& rg = *i;
+ const std::shared_ptr<RequestGroup>& rg = *i;
TransferStat stat = rg->calculateStat();
o << "[#" << GroupId::toAbbrevHex(rg->getGID()) << " ";
printSizeProgress(o, rg, stat, sizeFormatter);
@@ -158,7 +158,7 @@ void printProgressCompact(std::ostream& o, const DownloadEngine* e,
namespace {
void printProgress
-(std::ostream& o, const SharedHandle<RequestGroup>& rg, const DownloadEngine* e,
+(std::ostream& o, const std::shared_ptr<RequestGroup>& rg, const DownloadEngine* e,
const SizeFormatter& sizeFormatter)
{
TransferStat stat = rg->calculateStat();
@@ -171,7 +171,7 @@ void printProgress
o << " CN:"
<< rg->getNumConnection();
#ifdef ENABLE_BITTORRENT
- const SharedHandle<BtObject>& btObj = e->getBtRegistry()->get(rg->getGID());
+ const std::shared_ptr<BtObject>& btObj = e->getBtRegistry()->get(rg->getGID());
if(btObj) {
const PeerSet& peers = btObj->peerStorage->getUsedPeers();
o << " SD:"
@@ -214,7 +214,7 @@ public:
const char SEP_CHAR = '-';
std::stringstream o;
printProgress(o, rg, e_, sizeFormatter_);
- const std::vector<SharedHandle<FileEntry> >& fileEntries =
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
rg->getDownloadContext()->getFileEntries();
o << "\nFILE: ";
writeFilePath(fileEntries.begin(), fileEntries.end(),
@@ -321,7 +321,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
}
size_t numGroup = e->getRequestGroupMan()->countRequestGroup();
if(numGroup == 1) {
- const SharedHandle<RequestGroup>& rg =
+ const std::shared_ptr<RequestGroup>& rg =
*e->getRequestGroupMan()->getRequestGroups().begin();
printProgress(o, rg, e, sizeFormatter);
} else if(numGroup > 1) {
@@ -330,7 +330,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
}
{
- const SharedHandle<FileAllocationEntry>& entry =
+ const std::shared_ptr<FileAllocationEntry>& entry =
e->getFileAllocationMan()->getPickedEntry();
if(entry) {
o << " [FileAlloc:#"
@@ -350,7 +350,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
}
#ifdef ENABLE_MESSAGE_DIGEST
{
- const SharedHandle<CheckIntegrityEntry>& entry =
+ const std::shared_ptr<CheckIntegrityEntry>& entry =
e->getCheckIntegrityMan()->getPickedEntry();
if(entry) {
o << " [Checksum:#"
diff --git a/src/ConsoleStatCalc.h b/src/ConsoleStatCalc.h
index f680ac5f..d9385054 100644
--- a/src/ConsoleStatCalc.h
+++ b/src/ConsoleStatCalc.h
@@ -39,6 +39,7 @@
#include <string>
#include <functional>
+#include <memory>
#include "TimerA2.h"
@@ -62,7 +63,7 @@ private:
time_t summaryInterval_;
- SharedHandle<SizeFormatter> sizeFormatter_;
+ std::shared_ptr<SizeFormatter> sizeFormatter_;
bool readoutVisibility_;
bool truncate_;
bool isTTY_;
diff --git a/src/Context.cc b/src/Context.cc
index ad6b1af1..58f166f2 100644
--- a/src/Context.cc
+++ b/src/Context.cc
@@ -41,7 +41,6 @@
#include <vector>
#include <iostream>
-#include "SharedHandle.h"
#include "LogFactory.h"
#include "Logger.h"
#include "util.h"
@@ -86,13 +85,13 @@ extern int optind, opterr, optopt;
namespace aria2 {
-SharedHandle<StatCalc> getStatCalc(const SharedHandle<Option>& op)
+std::shared_ptr<StatCalc> getStatCalc(const std::shared_ptr<Option>& op)
{
- SharedHandle<StatCalc> statCalc;
+ std::shared_ptr<StatCalc> statCalc;
if(op->getAsBool(PREF_QUIET)) {
statCalc.reset(new NullStatCalc());
} else {
- SharedHandle<ConsoleStatCalc> impl
+ std::shared_ptr<ConsoleStatCalc> impl
(new ConsoleStatCalc(op->getAsInt(PREF_SUMMARY_INTERVAL),
op->getAsBool(PREF_HUMAN_READABLE)));
impl->setReadoutVisibility(op->getAsBool(PREF_SHOW_CONSOLE_READOUT));
@@ -102,10 +101,10 @@ SharedHandle<StatCalc> getStatCalc(const SharedHandle<Option>& op)
return statCalc;
}
-SharedHandle<OutputFile> getSummaryOut(const SharedHandle<Option>& op)
+std::shared_ptr<OutputFile> getSummaryOut(const std::shared_ptr<Option>& op)
{
if(op->getAsBool(PREF_QUIET)) {
- return SharedHandle<OutputFile>(new NullOutputFile());
+ return std::shared_ptr<OutputFile>(new NullOutputFile());
} else {
return global::cout();
}
@@ -115,8 +114,8 @@ SharedHandle<OutputFile> getSummaryOut(const SharedHandle<Option>& op)
namespace {
void showTorrentFile(const std::string& uri)
{
- SharedHandle<Option> op(new Option());
- SharedHandle<DownloadContext> dctx(new DownloadContext());
+ std::shared_ptr<Option> op(new Option());
+ std::shared_ptr<DownloadContext> dctx(new DownloadContext());
bittorrent::load(uri, dctx, op);
bittorrent::print(*global::cout(), dctx);
}
@@ -126,12 +125,12 @@ void showTorrentFile(const std::string& uri)
#ifdef ENABLE_METALINK
namespace {
void showMetalinkFile
-(const std::string& uri, const SharedHandle<Option>& op)
+(const std::string& uri, const std::shared_ptr<Option>& op)
{
- std::vector<SharedHandle<MetalinkEntry> > metalinkEntries;
+ std::vector<std::shared_ptr<MetalinkEntry> > metalinkEntries;
metalink::parseAndQuery(metalinkEntries, uri, op.get(),
op->get(PREF_METALINK_BASE_URI));
- std::vector<SharedHandle<FileEntry> > fileEntries;
+ std::vector<std::shared_ptr<FileEntry> > fileEntries;
MetalinkEntry::toFileEntry(fileEntries, metalinkEntries);
util::toStream(fileEntries.begin(), fileEntries.end(), *global::cout());
global::cout()->write("\n");
@@ -143,7 +142,7 @@ void showMetalinkFile
#if defined ENABLE_BITTORRENT || defined ENABLE_METALINK
namespace {
void showFiles
-(const std::vector<std::string>& uris, const SharedHandle<Option>& op)
+(const std::vector<std::string>& uris, const std::shared_ptr<Option>& op)
{
ProtocolDetector dt;
for(std::vector<std::string>::const_iterator i = uris.begin(),
@@ -183,7 +182,7 @@ Context::Context(bool standalone,
int argc, char** argv, const KeyVals& options)
{
std::vector<std::string> args;
- SharedHandle<Option> op(new Option());
+ std::shared_ptr<Option> op(new Option());
error_code::Value rv;
rv = option_processing(*op.get(), standalone, args, argc, argv, options);
if(rv != error_code::FINISHED) {
@@ -222,8 +221,8 @@ Context::Context(bool standalone,
std::string iface = op->get(PREF_INTERFACE);
SocketCore::bindAddress(iface);
}
- std::vector<SharedHandle<RequestGroup> > requestGroups;
- SharedHandle<UriListParser> uriListParser;
+ std::vector<std::shared_ptr<RequestGroup> > requestGroups;
+ std::shared_ptr<UriListParser> uriListParser;
#ifdef ENABLE_BITTORRENT
if(!op->blank(PREF_TORRENT_FILE)) {
if(op->get(PREF_SHOW_FILES) == A2_V_TRUE) {
@@ -266,7 +265,7 @@ Context::Context(bool standalone,
// command-line. If they are left, because op is used as a template
// for new RequestGroup(such as created in RPC command), they causes
// unintentional effect.
- for(SharedHandle<Option> i = op; i; i = i->getParent()) {
+ for(std::shared_ptr<Option> i = op; i; i = i->getParent()) {
i->remove(PREF_OUT);
i->remove(PREF_FORCE_SEQUENTIAL);
i->remove(PREF_INPUT_FILE);
diff --git a/src/Context.h b/src/Context.h
index 061c9969..3389590f 100644
--- a/src/Context.h
+++ b/src/Context.h
@@ -36,8 +36,10 @@
#define CONTEXT_H
#include "common.h"
+
+#include <memory>
+
#include <aria2/aria2.h>
-#include "SharedHandle.h"
namespace aria2 {
@@ -51,7 +53,7 @@ struct Context {
// as a part of command-line arguments.
Context(bool standalone, int argc, char** argv, const KeyVals& options);
~Context();
- SharedHandle<MultiUrlRequestInfo> reqinfo;
+ std::shared_ptr<MultiUrlRequestInfo> reqinfo;
};
} // namespace aria2
diff --git a/src/CookieStorage.cc b/src/CookieStorage.cc
index e6a22628..f5819299 100644
--- a/src/CookieStorage.cc
+++ b/src/CookieStorage.cc
@@ -192,7 +192,7 @@ const double DOMAIN_EVICTION_RATE = 0.1;
bool CookieStorage::store(const Cookie& cookie, time_t now)
{
if(domains_.size() >= DOMAIN_EVICTION_TRIGGER) {
- std::vector<SharedHandle<DomainEntry> > evictions(domains_.begin(),
+ std::vector<std::shared_ptr<DomainEntry> > evictions(domains_.begin(),
domains_.end());
std::sort(evictions.begin(), evictions.end(),
LeastRecentAccess<DomainEntry>());
@@ -200,7 +200,7 @@ bool CookieStorage::store(const Cookie& cookie, time_t now)
domains_.clear();
domains_.insert(evictions.begin()+delnum, evictions.end());
}
- SharedHandle<DomainEntry> v(new DomainEntry(cookie.getDomain()));
+ std::shared_ptr<DomainEntry> v(new DomainEntry(cookie.getDomain()));
DomainEntrySet::iterator i = domains_.lower_bound(v);
bool added = false;
if(i != domains_.end() && *(*i) == *v) {
@@ -292,7 +292,7 @@ void CookieStorage::searchCookieByDomainSuffix
const std::string& requestPath,
time_t now, bool secure)
{
- SharedHandle<DomainEntry> v(new DomainEntry(domain));
+ std::shared_ptr<DomainEntry> v(new DomainEntry(domain));
DomainEntrySet::iterator i = domains_.lower_bound(v);
if(i != domains_.end() && *(*i) == *v) {
(*i)->setLastAccessTime(now);
@@ -302,7 +302,7 @@ void CookieStorage::searchCookieByDomainSuffix
bool CookieStorage::contains(const Cookie& cookie) const
{
- SharedHandle<DomainEntry> v(new DomainEntry(cookie.getDomain()));
+ std::shared_ptr<DomainEntry> v(new DomainEntry(cookie.getDomain()));
DomainEntrySet::iterator i = domains_.find(v);
if(i != domains_.end()) {
return (*i)->contains(cookie);
diff --git a/src/CookieStorage.h b/src/CookieStorage.h
index 9febfad2..530e0d62 100644
--- a/src/CookieStorage.h
+++ b/src/CookieStorage.h
@@ -114,8 +114,8 @@ public:
bool operator<(const DomainEntry& de) const;
};
private:
- typedef std::set<SharedHandle<DomainEntry>,
- DerefLess<SharedHandle<DomainEntry> > > DomainEntrySet;
+ typedef std::set<std::shared_ptr<DomainEntry>,
+ DerefLess<std::shared_ptr<DomainEntry> > > DomainEntrySet;
DomainEntrySet domains_;
template<typename InputIterator>
diff --git a/src/CreateRequestCommand.cc b/src/CreateRequestCommand.cc
index d46936dd..1845af7c 100644
--- a/src/CreateRequestCommand.cc
+++ b/src/CreateRequestCommand.cc
@@ -55,9 +55,9 @@ CreateRequestCommand::CreateRequestCommand(cuid_t cuid,
RequestGroup* requestGroup,
DownloadEngine* e):
AbstractCommand
- (cuid, SharedHandle<Request>(), SharedHandle<FileEntry>(), requestGroup, e,
- SharedHandle<SocketCore>(),
- SharedHandle<SocketRecvBuffer>(),
+ (cuid, std::shared_ptr<Request>(), std::shared_ptr<FileEntry>(), requestGroup, e,
+ std::shared_ptr<SocketCore>(),
+ std::shared_ptr<SocketRecvBuffer>(),
false)
{
setStatus(Command::STATUS_ONESHOT_REALTIME);
diff --git a/src/DHTAbstractMessage.cc b/src/DHTAbstractMessage.cc
index 518c7e68..146fefac 100644
--- a/src/DHTAbstractMessage.cc
+++ b/src/DHTAbstractMessage.cc
@@ -46,8 +46,8 @@
namespace aria2 {
-DHTAbstractMessage::DHTAbstractMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+DHTAbstractMessage::DHTAbstractMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID):
DHTMessage(localNode, remoteNode, transactionID),
connection_(0),
diff --git a/src/DHTAbstractMessage.h b/src/DHTAbstractMessage.h
index 33f098fc..b0d7337c 100644
--- a/src/DHTAbstractMessage.h
+++ b/src/DHTAbstractMessage.h
@@ -56,8 +56,8 @@ private:
DHTRoutingTable* routingTable_;
public:
- DHTAbstractMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ DHTAbstractMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID = A2STR::NIL);
virtual ~DHTAbstractMessage();
diff --git a/src/DHTAbstractNodeLookupTask.h b/src/DHTAbstractNodeLookupTask.h
index 75994923..0d7333f3 100644
--- a/src/DHTAbstractNodeLookupTask.h
+++ b/src/DHTAbstractNodeLookupTask.h
@@ -67,31 +67,31 @@ class DHTAbstractNodeLookupTask:public DHTAbstractTask {
private:
unsigned char targetID_[DHT_ID_LENGTH];
- std::deque<SharedHandle<DHTNodeLookupEntry> > entries_;
+ std::deque<std::shared_ptr<DHTNodeLookupEntry> > entries_;
size_t inFlightMessage_;
template<typename Container>
void toEntries
- (Container& entries, const std::vector<SharedHandle<DHTNode> >& nodes) const
+ (Container& entries, const std::vector<std::shared_ptr<DHTNode> >& nodes) const
{
- for(std::vector<SharedHandle<DHTNode> >::const_iterator i = nodes.begin(),
+ for(std::vector<std::shared_ptr<DHTNode> >::const_iterator i = nodes.begin(),
eoi = nodes.end(); i != eoi; ++i) {
- SharedHandle<DHTNodeLookupEntry> e(new DHTNodeLookupEntry(*i));
+ std::shared_ptr<DHTNodeLookupEntry> e(new DHTNodeLookupEntry(*i));
entries.push_back(e);
}
}
void sendMessage()
{
- for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
+ for(std::deque<std::shared_ptr<DHTNodeLookupEntry> >::iterator i =
entries_.begin(), eoi = entries_.end();
i != eoi && inFlightMessage_ < ALPHA; ++i) {
if((*i)->used == false) {
++inFlightMessage_;
(*i)->used = true;
- SharedHandle<DHTMessage> m = createMessage((*i)->node);
- SharedHandle<DHTMessageCallback> callback(createCallback());
+ std::shared_ptr<DHTMessage> m = createMessage((*i)->node);
+ std::shared_ptr<DHTMessageCallback> callback(createCallback());
getMessageDispatcher()->addMessageToQueue(m, callback);
}
}
@@ -122,13 +122,13 @@ protected:
return targetID_;
}
- const std::deque<SharedHandle<DHTNodeLookupEntry> >& getEntries() const
+ const std::deque<std::shared_ptr<DHTNodeLookupEntry> >& getEntries() const
{
return entries_;
}
virtual void getNodesFromMessage
- (std::vector<SharedHandle<DHTNode> >& nodes,
+ (std::vector<std::shared_ptr<DHTNode> >& nodes,
const ResponseMessage* message) = 0;
virtual void onReceivedInternal
@@ -138,10 +138,10 @@ protected:
virtual void onFinish() {}
- virtual SharedHandle<DHTMessage> createMessage
- (const SharedHandle<DHTNode>& remoteNode) = 0;
+ virtual std::shared_ptr<DHTMessage> createMessage
+ (const std::shared_ptr<DHTNode>& remoteNode) = 0;
- virtual SharedHandle<DHTMessageCallback> createCallback() = 0;
+ virtual std::shared_ptr<DHTMessageCallback> createCallback() = 0;
public:
DHTAbstractNodeLookupTask(const unsigned char* targetID):
inFlightMessage_(0)
@@ -153,7 +153,7 @@ public:
virtual void startup()
{
- std::vector<SharedHandle<DHTNode> > nodes;
+ std::vector<std::shared_ptr<DHTNode> > nodes;
getRoutingTable()->getClosestKNodes(nodes, targetID_);
entries_.clear();
toEntries(entries_, nodes);
@@ -174,7 +174,7 @@ public:
{
--inFlightMessage_;
// Replace old Node ID with new Node ID.
- for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
+ for(std::deque<std::shared_ptr<DHTNodeLookupEntry> >::iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
if((*i)->node->getIPAddress() == message->getRemoteNode()->getIPAddress()
&& (*i)->node->getPort() == message->getRemoteNode()->getPort()) {
@@ -182,13 +182,13 @@ public:
}
}
onReceivedInternal(message);
- std::vector<SharedHandle<DHTNode> > nodes;
+ std::vector<std::shared_ptr<DHTNode> > nodes;
getNodesFromMessage(nodes, message);
- std::vector<SharedHandle<DHTNodeLookupEntry> > newEntries;
+ std::vector<std::shared_ptr<DHTNodeLookupEntry> > newEntries;
toEntries(newEntries, nodes);
size_t count = 0;
- for(std::vector<SharedHandle<DHTNodeLookupEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<DHTNodeLookupEntry> >::const_iterator i =
newEntries.begin(), eoi = newEntries.end(); i != eoi; ++i) {
if(memcmp(getLocalNode()->getID(), (*i)->node->getID(),
DHT_ID_LENGTH) != 0) {
@@ -205,7 +205,7 @@ public:
std::stable_sort(entries_.begin(), entries_.end(), DHTIDCloser(targetID_));
entries_.erase
(std::unique(entries_.begin(), entries_.end(),
- DerefEqualTo<SharedHandle<DHTNodeLookupEntry> >()),
+ DerefEqualTo<std::shared_ptr<DHTNodeLookupEntry> >()),
entries_.end());
A2_LOG_DEBUG(fmt("%lu node lookup entries are unique.",
static_cast<unsigned long>(entries_.size())));
@@ -215,12 +215,12 @@ public:
sendMessageAndCheckFinish();
}
- void onTimeout(const SharedHandle<DHTNode>& node)
+ void onTimeout(const std::shared_ptr<DHTNode>& node)
{
A2_LOG_DEBUG(fmt("node lookup message timeout for node ID=%s",
util::toHex(node->getID(), DHT_ID_LENGTH).c_str()));
--inFlightMessage_;
- for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
+ for(std::deque<std::shared_ptr<DHTNodeLookupEntry> >::iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
if(*(*i)->node == *node) {
entries_.erase(i);
diff --git a/src/DHTAbstractTask.cc b/src/DHTAbstractTask.cc
index 962f37a4..b7c100fd 100644
--- a/src/DHTAbstractTask.cc
+++ b/src/DHTAbstractTask.cc
@@ -78,7 +78,7 @@ void DHTAbstractTask::setTaskQueue(DHTTaskQueue* taskQueue)
taskQueue_ = taskQueue;
}
-void DHTAbstractTask::setLocalNode(const SharedHandle<DHTNode>& localNode)
+void DHTAbstractTask::setLocalNode(const std::shared_ptr<DHTNode>& localNode)
{
localNode_ = localNode;
}
diff --git a/src/DHTAbstractTask.h b/src/DHTAbstractTask.h
index 3e20c7bd..65850af7 100644
--- a/src/DHTAbstractTask.h
+++ b/src/DHTAbstractTask.h
@@ -36,7 +36,9 @@
#define D_DHT_ABSTRACT_TASK_H
#include "DHTTask.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "DHTConstants.h"
namespace aria2 {
@@ -52,7 +54,7 @@ class DHTAbstractTask:public DHTTask {
private:
bool finished_;
- SharedHandle<DHTNode> localNode_;
+ std::shared_ptr<DHTNode> localNode_;
DHTRoutingTable* routingTable_;
@@ -99,12 +101,12 @@ public:
void setTaskQueue(DHTTaskQueue* taskQueue);
- const SharedHandle<DHTNode>& getLocalNode() const
+ const std::shared_ptr<DHTNode>& getLocalNode() const
{
return localNode_;
}
- void setLocalNode(const SharedHandle<DHTNode>& localNode);
+ void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
};
} // namespace aria2
diff --git a/src/DHTAnnouncePeerMessage.cc b/src/DHTAnnouncePeerMessage.cc
index 67f48d8e..40f709b2 100644
--- a/src/DHTAnnouncePeerMessage.cc
+++ b/src/DHTAnnouncePeerMessage.cc
@@ -60,8 +60,8 @@ const std::string DHTAnnouncePeerMessage::PORT("port");
const std::string DHTAnnouncePeerMessage::TOKEN("token");
DHTAnnouncePeerMessage::DHTAnnouncePeerMessage
-(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
uint16_t tcpPort,
const std::string& token,
@@ -82,15 +82,15 @@ void DHTAnnouncePeerMessage::doReceivedAction()
peerAnnounceStorage_->addPeerAnnounce
(infoHash_, getRemoteNode()->getIPAddress(), tcpPort_);
- SharedHandle<DHTMessage> reply =
+ std::shared_ptr<DHTMessage> reply =
getMessageFactory()->createAnnouncePeerReplyMessage
(getRemoteNode(), getTransactionID());
getMessageDispatcher()->addMessageToQueue(reply);
}
-SharedHandle<Dict> DHTAnnouncePeerMessage::getArgument()
+std::shared_ptr<Dict> DHTAnnouncePeerMessage::getArgument()
{
- SharedHandle<Dict> aDict = Dict::g();
+ std::shared_ptr<Dict> aDict = Dict::g();
aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
aDict->put(INFO_HASH, String::g(infoHash_, DHT_ID_LENGTH));
aDict->put(PORT, Integer::g(tcpPort_));
diff --git a/src/DHTAnnouncePeerMessage.h b/src/DHTAnnouncePeerMessage.h
index b4fc6879..6f1161c9 100644
--- a/src/DHTAnnouncePeerMessage.h
+++ b/src/DHTAnnouncePeerMessage.h
@@ -58,8 +58,8 @@ private:
protected:
virtual std::string toStringOptional() const;
public:
- DHTAnnouncePeerMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ DHTAnnouncePeerMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
uint16_t tcpPort,
const std::string& token,
@@ -69,7 +69,7 @@ public:
virtual void doReceivedAction();
- virtual SharedHandle<Dict> getArgument();
+ virtual std::shared_ptr<Dict> getArgument();
virtual const std::string& getMessageType() const;
diff --git a/src/DHTAnnouncePeerReplyMessage.cc b/src/DHTAnnouncePeerReplyMessage.cc
index 1562d78f..3b094eb5 100644
--- a/src/DHTAnnouncePeerReplyMessage.cc
+++ b/src/DHTAnnouncePeerReplyMessage.cc
@@ -41,8 +41,8 @@ namespace aria2 {
const std::string DHTAnnouncePeerReplyMessage::ANNOUNCE_PEER("announce_peer");
DHTAnnouncePeerReplyMessage::DHTAnnouncePeerReplyMessage
-(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID):
DHTResponseMessage(localNode, remoteNode, transactionID) {}
@@ -50,9 +50,9 @@ DHTAnnouncePeerReplyMessage::~DHTAnnouncePeerReplyMessage() {}
void DHTAnnouncePeerReplyMessage::doReceivedAction() {}
-SharedHandle<Dict> DHTAnnouncePeerReplyMessage::getResponse()
+std::shared_ptr<Dict> DHTAnnouncePeerReplyMessage::getResponse()
{
- SharedHandle<Dict> rDict = Dict::g();
+ std::shared_ptr<Dict> rDict = Dict::g();
rDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
return rDict;
}
diff --git a/src/DHTAnnouncePeerReplyMessage.h b/src/DHTAnnouncePeerReplyMessage.h
index 0faaae20..1aa323c1 100644
--- a/src/DHTAnnouncePeerReplyMessage.h
+++ b/src/DHTAnnouncePeerReplyMessage.h
@@ -41,15 +41,15 @@ namespace aria2 {
class DHTAnnouncePeerReplyMessage:public DHTResponseMessage {
public:
- DHTAnnouncePeerReplyMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ DHTAnnouncePeerReplyMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID);
virtual ~DHTAnnouncePeerReplyMessage();
virtual void doReceivedAction();
- virtual SharedHandle<Dict> getResponse();
+ virtual std::shared_ptr<Dict> getResponse();
virtual const std::string& getMessageType() const;
diff --git a/src/DHTAutoSaveCommand.cc b/src/DHTAutoSaveCommand.cc
index 128b3cfd..05f04e4f 100644
--- a/src/DHTAutoSaveCommand.cc
+++ b/src/DHTAutoSaveCommand.cc
@@ -93,13 +93,13 @@ void DHTAutoSaveCommand::save()
tempFile.remove();
File(File(dhtFile).getDirname()).mkdirs();
- std::vector<SharedHandle<DHTNode> > nodes;
- std::vector<SharedHandle<DHTBucket> > buckets;
+ std::vector<std::shared_ptr<DHTNode> > nodes;
+ std::vector<std::shared_ptr<DHTBucket> > buckets;
routingTable_->getBuckets(buckets);
- for(std::vector<SharedHandle<DHTBucket> >::const_iterator i = buckets.begin(),
+ for(std::vector<std::shared_ptr<DHTBucket> >::const_iterator i = buckets.begin(),
eoi = buckets.end(); i != eoi; ++i) {
- const SharedHandle<DHTBucket>& bucket = *i;
- std::vector<SharedHandle<DHTNode> > goodNodes;
+ const std::shared_ptr<DHTBucket>& bucket = *i;
+ std::vector<std::shared_ptr<DHTNode> > goodNodes;
bucket->getGoodNodes(goodNodes);
nodes.insert(nodes.end(), goodNodes.begin(), goodNodes.end());
}
@@ -117,13 +117,13 @@ void DHTAutoSaveCommand::save()
}
}
-void DHTAutoSaveCommand::setLocalNode(const SharedHandle<DHTNode>& localNode)
+void DHTAutoSaveCommand::setLocalNode(const std::shared_ptr<DHTNode>& localNode)
{
localNode_ = localNode;
}
void DHTAutoSaveCommand::setRoutingTable
-(const SharedHandle<DHTRoutingTable>& routingTable)
+(const std::shared_ptr<DHTRoutingTable>& routingTable)
{
routingTable_ = routingTable;
}
diff --git a/src/DHTAutoSaveCommand.h b/src/DHTAutoSaveCommand.h
index b5663061..dd70040e 100644
--- a/src/DHTAutoSaveCommand.h
+++ b/src/DHTAutoSaveCommand.h
@@ -36,7 +36,8 @@
#define D_DHT_AUTO_SAVE_COMMAND_H
#include "TimeBasedCommand.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -48,9 +49,9 @@ class DHTAutoSaveCommand : public TimeBasedCommand
private:
int family_;
- SharedHandle<DHTNode> localNode_;
+ std::shared_ptr<DHTNode> localNode_;
- SharedHandle<DHTRoutingTable> routingTable_;
+ std::shared_ptr<DHTRoutingTable> routingTable_;
void save();
public:
@@ -63,9 +64,9 @@ public:
virtual void process();
- void setLocalNode(const SharedHandle<DHTNode>& localNode);
+ void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
- void setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable);
+ void setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable);
};
} // namespace aria2
diff --git a/src/DHTBucket.cc b/src/DHTBucket.cc
index a84e76a8..16292ea4 100644
--- a/src/DHTBucket.cc
+++ b/src/DHTBucket.cc
@@ -54,7 +54,7 @@ namespace aria2 {
DHTBucket::DHTBucket
(size_t prefixLength,
const unsigned char* max, const unsigned char* min,
- const SharedHandle<DHTNode>& localNode)
+ const std::shared_ptr<DHTNode>& localNode)
: prefixLength_(prefixLength),
localNode_(localNode),
lastUpdated_(global::wallclock())
@@ -63,7 +63,7 @@ DHTBucket::DHTBucket
memcpy(min_, min, DHT_ID_LENGTH);
}
-DHTBucket::DHTBucket(const SharedHandle<DHTNode>& localNode)
+DHTBucket::DHTBucket(const std::shared_ptr<DHTNode>& localNode)
: prefixLength_(0),
localNode_(localNode),
lastUpdated_(global::wallclock())
@@ -85,7 +85,7 @@ void DHTBucket::getRandomNodeID(unsigned char* nodeID) const
}
}
-bool DHTBucket::isInRange(const SharedHandle<DHTNode>& node) const
+bool DHTBucket::isInRange(const std::shared_ptr<DHTNode>& node) const
{
return isInRange(node->getID(), max_, min_);
}
@@ -107,10 +107,10 @@ bool DHTBucket::isInRange(const unsigned char* nodeID,
&nodeID[0], &nodeID[DHT_ID_LENGTH]);
}
-bool DHTBucket::addNode(const SharedHandle<DHTNode>& node)
+bool DHTBucket::addNode(const std::shared_ptr<DHTNode>& node)
{
notifyUpdate();
- std::deque<SharedHandle<DHTNode> >::iterator itr =
+ std::deque<std::shared_ptr<DHTNode> >::iterator itr =
std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
if(itr == nodes_.end()) {
if(nodes_.size() < K) {
@@ -132,19 +132,19 @@ bool DHTBucket::addNode(const SharedHandle<DHTNode>& node)
}
}
-void DHTBucket::cacheNode(const SharedHandle<DHTNode>& node)
+void DHTBucket::cacheNode(const std::shared_ptr<DHTNode>& node)
{
// cachedNodes_ are sorted by last time seen
cachedNodes_.push_front(node);
if(cachedNodes_.size() > CACHE_SIZE) {
- cachedNodes_.resize(CACHE_SIZE, SharedHandle<DHTNode>());
+ cachedNodes_.resize(CACHE_SIZE, std::shared_ptr<DHTNode>());
}
}
-void DHTBucket::dropNode(const SharedHandle<DHTNode>& node)
+void DHTBucket::dropNode(const std::shared_ptr<DHTNode>& node)
{
if(!cachedNodes_.empty()) {
- std::deque<SharedHandle<DHTNode> >::iterator itr =
+ std::deque<std::shared_ptr<DHTNode> >::iterator itr =
std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
if(itr != nodes_.end()) {
nodes_.erase(itr);
@@ -154,9 +154,9 @@ void DHTBucket::dropNode(const SharedHandle<DHTNode>& node)
}
}
-void DHTBucket::moveToHead(const SharedHandle<DHTNode>& node)
+void DHTBucket::moveToHead(const std::shared_ptr<DHTNode>& node)
{
- std::deque<SharedHandle<DHTNode> >::iterator itr =
+ std::deque<std::shared_ptr<DHTNode> >::iterator itr =
std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
if(itr != nodes_.end()) {
nodes_.erase(itr);
@@ -164,9 +164,9 @@ void DHTBucket::moveToHead(const SharedHandle<DHTNode>& node)
}
}
-void DHTBucket::moveToTail(const SharedHandle<DHTNode>& node)
+void DHTBucket::moveToTail(const std::shared_ptr<DHTNode>& node)
{
- std::deque<SharedHandle<DHTNode> >::iterator itr =
+ std::deque<std::shared_ptr<DHTNode> >::iterator itr =
std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
if(itr != nodes_.end()) {
nodes_.erase(itr);
@@ -179,7 +179,7 @@ bool DHTBucket::splitAllowed() const
return prefixLength_ < DHT_ID_LENGTH*8-1 && isInRange(localNode_);
}
-SharedHandle<DHTBucket> DHTBucket::split()
+std::shared_ptr<DHTBucket> DHTBucket::split()
{
assert(splitAllowed());
@@ -192,11 +192,11 @@ SharedHandle<DHTBucket> DHTBucket::split()
bitfield::flipBit(min_, DHT_ID_LENGTH, prefixLength_);
++prefixLength_;
- SharedHandle<DHTBucket> rBucket(new DHTBucket(prefixLength_,
+ std::shared_ptr<DHTBucket> rBucket(new DHTBucket(prefixLength_,
rMax, rMin, localNode_));
- std::deque<SharedHandle<DHTNode> > lNodes;
- for(std::deque<SharedHandle<DHTNode> >::iterator i = nodes_.begin(),
+ std::deque<std::shared_ptr<DHTNode> > lNodes;
+ for(std::deque<std::shared_ptr<DHTNode> >::iterator i = nodes_.begin(),
eoi = nodes_.end(); i != eoi; ++i) {
if(rBucket->isInRange(*i)) {
assert(rBucket->addNode(*i));
@@ -218,23 +218,23 @@ SharedHandle<DHTBucket> DHTBucket::split()
}
void DHTBucket::getGoodNodes
-(std::vector<SharedHandle<DHTNode> >& goodNodes) const
+(std::vector<std::shared_ptr<DHTNode> >& goodNodes) const
{
goodNodes.insert(goodNodes.end(), nodes_.begin(), nodes_.end());
goodNodes.erase(std::remove_if(goodNodes.begin(), goodNodes.end(),
mem_fun_sh(&DHTNode::isBad)), goodNodes.end());
}
-SharedHandle<DHTNode> DHTBucket::getNode(const unsigned char* nodeID, const std::string& ipaddr, uint16_t port) const
+std::shared_ptr<DHTNode> DHTBucket::getNode(const unsigned char* nodeID, const std::string& ipaddr, uint16_t port) const
{
- SharedHandle<DHTNode> node(new DHTNode(nodeID));
+ std::shared_ptr<DHTNode> node(new DHTNode(nodeID));
node->setIPAddress(ipaddr);
node->setPort(port);
- std::deque<SharedHandle<DHTNode> >::const_iterator itr =
+ std::deque<std::shared_ptr<DHTNode> >::const_iterator itr =
std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
if(itr == nodes_.end() ||
(*itr)->getIPAddress() != ipaddr || (*itr)->getPort() != port) {
- return SharedHandle<DHTNode>();
+ return std::shared_ptr<DHTNode>();
} else {
return *itr;
}
@@ -260,7 +260,7 @@ void DHTBucket::notifyUpdate()
namespace {
class FindQuestionableNode {
public:
- bool operator()(const SharedHandle<DHTNode>& node) const
+ bool operator()(const std::shared_ptr<DHTNode>& node) const
{
return node->isQuestionable();
}
@@ -272,12 +272,12 @@ bool DHTBucket::containsQuestionableNode() const
return std::find_if(nodes_.begin(), nodes_.end(), FindQuestionableNode()) != nodes_.end();
}
-SharedHandle<DHTNode> DHTBucket::getLRUQuestionableNode() const
+std::shared_ptr<DHTNode> DHTBucket::getLRUQuestionableNode() const
{
- std::deque<SharedHandle<DHTNode> >::const_iterator i =
+ std::deque<std::shared_ptr<DHTNode> >::const_iterator i =
std::find_if(nodes_.begin(), nodes_.end(), FindQuestionableNode());
if(i == nodes_.end()) {
- return SharedHandle<DHTNode>();
+ return std::shared_ptr<DHTNode>();
} else {
return *i;
}
diff --git a/src/DHTBucket.h b/src/DHTBucket.h
index 6c1d6a5b..3a94ecf4 100644
--- a/src/DHTBucket.h
+++ b/src/DHTBucket.h
@@ -40,8 +40,8 @@
#include <string>
#include <deque>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "DHTConstants.h"
#include "TimerA2.h"
@@ -58,25 +58,25 @@ private:
unsigned char max_[DHT_ID_LENGTH];
- SharedHandle<DHTNode> localNode_;
+ std::shared_ptr<DHTNode> localNode_;
// sorted in ascending order
- std::deque<SharedHandle<DHTNode> > nodes_;
+ std::deque<std::shared_ptr<DHTNode> > nodes_;
// a replacement cache. The maximum size is specified by CACHE_SIZE.
// This is sorted by last time seen.
- std::deque<SharedHandle<DHTNode> > cachedNodes_;
+ std::deque<std::shared_ptr<DHTNode> > cachedNodes_;
Timer lastUpdated_;
bool isInRange(const unsigned char* nodeID,
const unsigned char* max, const unsigned char* min) const;
public:
- DHTBucket(const SharedHandle<DHTNode>& localNode);
+ DHTBucket(const std::shared_ptr<DHTNode>& localNode);
DHTBucket(size_t prefixLength,
const unsigned char* max, const unsigned char* min,
- const SharedHandle<DHTNode>& localNode);
+ const std::shared_ptr<DHTNode>& localNode);
~DHTBucket();
@@ -86,15 +86,15 @@ public:
void getRandomNodeID(unsigned char* nodeID) const;
- SharedHandle<DHTBucket> split();
+ std::shared_ptr<DHTBucket> split();
- bool isInRange(const SharedHandle<DHTNode>& node) const;
+ bool isInRange(const std::shared_ptr<DHTNode>& node) const;
bool isInRange(const unsigned char* nodeID) const;
- bool addNode(const SharedHandle<DHTNode>& node);
+ bool addNode(const std::shared_ptr<DHTNode>& node);
- void cacheNode(const SharedHandle<DHTNode>& node);
+ void cacheNode(const std::shared_ptr<DHTNode>& node);
bool splitAllowed() const;
@@ -118,22 +118,22 @@ public:
return nodes_.size();
}
- const std::deque<SharedHandle<DHTNode> >& getNodes() const
+ const std::deque<std::shared_ptr<DHTNode> >& getNodes() const
{
return nodes_;
}
- void getGoodNodes(std::vector<SharedHandle<DHTNode> >& nodes) const;
+ void getGoodNodes(std::vector<std::shared_ptr<DHTNode> >& nodes) const;
- void dropNode(const SharedHandle<DHTNode>& node);
+ void dropNode(const std::shared_ptr<DHTNode>& node);
- void moveToHead(const SharedHandle<DHTNode>& node);
+ void moveToHead(const std::shared_ptr<DHTNode>& node);
- void moveToTail(const SharedHandle<DHTNode>& node);
+ void moveToTail(const std::shared_ptr<DHTNode>& node);
- bool contains(const SharedHandle<DHTNode>& node) const;
+ bool contains(const std::shared_ptr<DHTNode>& node) const;
- SharedHandle<DHTNode> getNode(const unsigned char* nodeID, const std::string& ipaddr, uint16_t port) const;
+ std::shared_ptr<DHTNode> getNode(const unsigned char* nodeID, const std::string& ipaddr, uint16_t port) const;
bool operator==(const DHTBucket& bucket) const;
@@ -143,9 +143,9 @@ public:
bool containsQuestionableNode() const;
- SharedHandle<DHTNode> getLRUQuestionableNode() const;
+ std::shared_ptr<DHTNode> getLRUQuestionableNode() const;
- const std::deque<SharedHandle<DHTNode> >& getCachedNodes() const
+ const std::deque<std::shared_ptr<DHTNode> >& getCachedNodes() const
{
return cachedNodes_;
}
diff --git a/src/DHTBucketRefreshCommand.cc b/src/DHTBucketRefreshCommand.cc
index aa155b52..e3001f78 100644
--- a/src/DHTBucketRefreshCommand.cc
+++ b/src/DHTBucketRefreshCommand.cc
@@ -62,19 +62,19 @@ void DHTBucketRefreshCommand::process()
}
void DHTBucketRefreshCommand::setRoutingTable
-(const SharedHandle<DHTRoutingTable>& routingTable)
+(const std::shared_ptr<DHTRoutingTable>& routingTable)
{
routingTable_ = routingTable;
}
void DHTBucketRefreshCommand::setTaskQueue
-(const SharedHandle<DHTTaskQueue>& taskQueue)
+(const std::shared_ptr<DHTTaskQueue>& taskQueue)
{
taskQueue_ = taskQueue;
}
void DHTBucketRefreshCommand::setTaskFactory
-(const SharedHandle<DHTTaskFactory>& taskFactory)
+(const std::shared_ptr<DHTTaskFactory>& taskFactory)
{
taskFactory_ = taskFactory;
}
diff --git a/src/DHTBucketRefreshCommand.h b/src/DHTBucketRefreshCommand.h
index 88d48fa4..d29aff7b 100644
--- a/src/DHTBucketRefreshCommand.h
+++ b/src/DHTBucketRefreshCommand.h
@@ -36,7 +36,8 @@
#define D_DHT_BUCKET_REFRESH_COMMAND_H
#include "TimeBasedCommand.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -46,11 +47,11 @@ class DHTTaskFactory;
class DHTBucketRefreshCommand:public TimeBasedCommand {
private:
- SharedHandle<DHTRoutingTable> routingTable_;
+ std::shared_ptr<DHTRoutingTable> routingTable_;
- SharedHandle<DHTTaskQueue> taskQueue_;
+ std::shared_ptr<DHTTaskQueue> taskQueue_;
- SharedHandle<DHTTaskFactory> taskFactory_;
+ std::shared_ptr<DHTTaskFactory> taskFactory_;
public:
DHTBucketRefreshCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
@@ -60,11 +61,11 @@ public:
virtual void process();
- void setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable);
+ void setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable);
- void setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue);
+ void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
- void setTaskFactory(const SharedHandle<DHTTaskFactory>& taskFactory);
+ void setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory);
};
} // namespace aria2
diff --git a/src/DHTBucketRefreshTask.cc b/src/DHTBucketRefreshTask.cc
index 7b76138c..827693c0 100644
--- a/src/DHTBucketRefreshTask.cc
+++ b/src/DHTBucketRefreshTask.cc
@@ -54,15 +54,15 @@ DHTBucketRefreshTask::~DHTBucketRefreshTask() {}
void DHTBucketRefreshTask::startup()
{
- std::vector<SharedHandle<DHTBucket> > buckets;
+ std::vector<std::shared_ptr<DHTBucket> > buckets;
getRoutingTable()->getBuckets(buckets);
- for(std::vector<SharedHandle<DHTBucket> >::iterator i = buckets.begin(),
+ for(std::vector<std::shared_ptr<DHTBucket> >::iterator i = buckets.begin(),
eoi = buckets.end(); i != eoi; ++i) {
if(forceRefresh_ || (*i)->needsRefresh()) {
(*i)->notifyUpdate();
unsigned char targetID[DHT_ID_LENGTH];
(*i)->getRandomNodeID(targetID);
- SharedHandle<DHTNodeLookupTask> task(new DHTNodeLookupTask(targetID));
+ std::shared_ptr<DHTNodeLookupTask> task(new DHTNodeLookupTask(targetID));
task->setRoutingTable(getRoutingTable());
task->setMessageDispatcher(getMessageDispatcher());
task->setMessageFactory(getMessageFactory());
diff --git a/src/DHTBucketTree.cc b/src/DHTBucketTree.cc
index 8ea7247f..80deb65b 100644
--- a/src/DHTBucketTree.cc
+++ b/src/DHTBucketTree.cc
@@ -52,7 +52,7 @@ DHTBucketTreeNode::DHTBucketTreeNode
resetRelation();
}
-DHTBucketTreeNode::DHTBucketTreeNode(const SharedHandle<DHTBucket>& bucket)
+DHTBucketTreeNode::DHTBucketTreeNode(const std::shared_ptr<DHTBucket>& bucket)
: parent_(0),
left_(0),
right_(0),
@@ -99,7 +99,7 @@ bool DHTBucketTreeNode::isInRange(const unsigned char* key) const
void DHTBucketTreeNode::split()
{
- SharedHandle<DHTBucket> leftBucket = bucket_->split();
+ std::shared_ptr<DHTBucket> leftBucket = bucket_->split();
left_ = new DHTBucketTreeNode(leftBucket);
right_ = new DHTBucketTreeNode(bucket_);
bucket_.reset();
@@ -118,7 +118,7 @@ DHTBucketTreeNode* findTreeNodeFor
}
}
-SharedHandle<DHTBucket> findBucketFor
+std::shared_ptr<DHTBucket> findBucketFor
(DHTBucketTreeNode* root, const unsigned char* key)
{
DHTBucketTreeNode* leaf = findTreeNodeFor(root, key);
@@ -127,10 +127,10 @@ SharedHandle<DHTBucket> findBucketFor
namespace {
void collectNodes
-(std::vector<SharedHandle<DHTNode> >& nodes,
- const SharedHandle<DHTBucket>& bucket)
+(std::vector<std::shared_ptr<DHTNode> >& nodes,
+ const std::shared_ptr<DHTBucket>& bucket)
{
- std::vector<SharedHandle<DHTNode> > goodNodes;
+ std::vector<std::shared_ptr<DHTNode> > goodNodes;
bucket->getGoodNodes(goodNodes);
nodes.insert(nodes.end(), goodNodes.begin(), goodNodes.end());
}
@@ -138,7 +138,7 @@ void collectNodes
namespace {
void collectDownwardLeftFirst
-(std::vector<SharedHandle<DHTNode> >& nodes, DHTBucketTreeNode* tnode)
+(std::vector<std::shared_ptr<DHTNode> >& nodes, DHTBucketTreeNode* tnode)
{
if(tnode->leaf()) {
collectNodes(nodes, tnode->getBucket());
@@ -153,7 +153,7 @@ void collectDownwardLeftFirst
namespace {
void collectDownwardRightFirst
-(std::vector<SharedHandle<DHTNode> >& nodes, DHTBucketTreeNode* tnode)
+(std::vector<std::shared_ptr<DHTNode> >& nodes, DHTBucketTreeNode* tnode)
{
if(tnode->leaf()) {
collectNodes(nodes, tnode->getBucket());
@@ -168,7 +168,7 @@ void collectDownwardRightFirst
namespace {
void collectUpward
-(std::vector<SharedHandle<DHTNode> >& nodes, DHTBucketTreeNode* from)
+(std::vector<std::shared_ptr<DHTNode> >& nodes, DHTBucketTreeNode* from)
{
while(1) {
DHTBucketTreeNode* parent = from->getParent();
@@ -189,7 +189,7 @@ void collectUpward
} // namespace
void findClosestKNodes
-(std::vector<SharedHandle<DHTNode> >& nodes,
+(std::vector<std::shared_ptr<DHTNode> >& nodes,
DHTBucketTreeNode* root,
const unsigned char* key)
{
@@ -217,7 +217,7 @@ void findClosestKNodes
}
void enumerateBucket
-(std::vector<SharedHandle<DHTBucket> >& buckets, DHTBucketTreeNode* root)
+(std::vector<std::shared_ptr<DHTBucket> >& buckets, DHTBucketTreeNode* root)
{
if(root->leaf()) {
buckets.push_back(root->getBucket());
diff --git a/src/DHTBucketTree.h b/src/DHTBucketTree.h
index 46d32b2c..96059bd5 100644
--- a/src/DHTBucketTree.h
+++ b/src/DHTBucketTree.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "DHTConstants.h"
namespace aria2 {
@@ -55,20 +55,20 @@ public:
// Ctor for internal node
DHTBucketTreeNode(DHTBucketTreeNode* left, DHTBucketTreeNode* right);
// Ctor for leaf node
- DHTBucketTreeNode(const SharedHandle<DHTBucket>& bucket);
+ DHTBucketTreeNode(const std::shared_ptr<DHTBucket>& bucket);
~DHTBucketTreeNode();
// Returns child node, left or right, which contains key. If dig is
// called against leaf node, then returns 0.
DHTBucketTreeNode* dig(const unsigned char* key);
bool isInRange(const unsigned char* key) const;
// Returns true iff this is a leaf node.
- bool leaf() const { return bucket_; }
+ bool leaf() const { return bucket_.get(); }
const unsigned char* getMaxId() const { return maxId_; }
const unsigned char* getMinId() const { return minId_; }
DHTBucketTreeNode* getParent() const { return parent_; }
DHTBucketTreeNode* getLeft() const { return left_; }
DHTBucketTreeNode* getRight() const { return right_; }
- const SharedHandle<DHTBucket>& getBucket() const { return bucket_; }
+ const std::shared_ptr<DHTBucket>& getBucket() const { return bucket_; }
// Splits this object's bucket using DHTBucket::split() and create
// left and right child node to hold buckets. The bucket of current
// node is reseted so this node becomes internal node after this
@@ -85,7 +85,7 @@ private:
DHTBucketTreeNode* parent_;
DHTBucketTreeNode* left_;
DHTBucketTreeNode* right_;
- SharedHandle<DHTBucket> bucket_;
+ std::shared_ptr<DHTBucket> bucket_;
unsigned char minId_[DHT_ID_LENGTH];
unsigned char maxId_[DHT_ID_LENGTH];
};
@@ -100,7 +100,7 @@ DHTBucketTreeNode* findTreeNodeFor
// Returns bucket where key fits between bucket's min and max ID
// range. This function first use findTreeNodeFor and returns its
// bucket_.
-SharedHandle<DHTBucket> findBucketFor
+std::shared_ptr<DHTBucket> findBucketFor
(DHTBucketTreeNode* root, const unsigned char* key);
// Stores most closest K nodes against key in nodes. K is
@@ -108,13 +108,13 @@ SharedHandle<DHTBucket> findBucketFor
// the routing tree contains less than K nodes. The order of nodes is
// arbitrary. Caller must pass empty nodes.
void findClosestKNodes
-(std::vector<SharedHandle<DHTNode> >& nodes,
+(std::vector<std::shared_ptr<DHTNode> >& nodes,
DHTBucketTreeNode* root,
const unsigned char* key);
// Stores all buckets in buckets.
void enumerateBucket
-(std::vector<SharedHandle<DHTBucket> >& buckets, DHTBucketTreeNode* root);
+(std::vector<std::shared_ptr<DHTBucket> >& buckets, DHTBucketTreeNode* root);
} // namespace dht
diff --git a/src/DHTConnectionImpl.h b/src/DHTConnectionImpl.h
index 91875e05..8409f053 100644
--- a/src/DHTConnectionImpl.h
+++ b/src/DHTConnectionImpl.h
@@ -36,7 +36,9 @@
#define D_DHT_CONNECTION_IMPL_H
#include "DHTConnection.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "SegList.h"
namespace aria2 {
@@ -45,7 +47,7 @@ class SocketCore;
class DHTConnectionImpl:public DHTConnection {
private:
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<SocketCore> socket_;
int family_;
public:
@@ -80,7 +82,7 @@ public:
virtual ssize_t sendMessage(const unsigned char* data, size_t len,
const std::string& host, uint16_t port);
- const SharedHandle<SocketCore>& getSocket() const
+ const std::shared_ptr<SocketCore>& getSocket() const
{
return socket_;
}
diff --git a/src/DHTEntryPointNameResolveCommand.cc b/src/DHTEntryPointNameResolveCommand.cc
index 2df1250f..05e68a11 100644
--- a/src/DHTEntryPointNameResolveCommand.cc
+++ b/src/DHTEntryPointNameResolveCommand.cc
@@ -148,7 +148,7 @@ bool DHTEntryPointNameResolveCommand::execute()
void DHTEntryPointNameResolveCommand::addPingTask
(const std::pair<std::string, uint16_t>& addr)
{
- SharedHandle<DHTNode> entryNode(new DHTNode());
+ std::shared_ptr<DHTNode> entryNode(new DHTNode());
entryNode->setIPAddress(addr.first);
entryNode->setPort(addr.second);
@@ -198,25 +198,25 @@ void DHTEntryPointNameResolveCommand::setBootstrapEnabled(bool f)
}
void DHTEntryPointNameResolveCommand::setTaskQueue
-(const SharedHandle<DHTTaskQueue>& taskQueue)
+(const std::shared_ptr<DHTTaskQueue>& taskQueue)
{
taskQueue_ = taskQueue;
}
void DHTEntryPointNameResolveCommand::setTaskFactory
-(const SharedHandle<DHTTaskFactory>& taskFactory)
+(const std::shared_ptr<DHTTaskFactory>& taskFactory)
{
taskFactory_ = taskFactory;
}
void DHTEntryPointNameResolveCommand::setRoutingTable
-(const SharedHandle<DHTRoutingTable>& routingTable)
+(const std::shared_ptr<DHTRoutingTable>& routingTable)
{
routingTable_ = routingTable;
}
void DHTEntryPointNameResolveCommand::setLocalNode
-(const SharedHandle<DHTNode>& localNode)
+(const std::shared_ptr<DHTNode>& localNode)
{
localNode_ = localNode;
}
diff --git a/src/DHTEntryPointNameResolveCommand.h b/src/DHTEntryPointNameResolveCommand.h
index ea30deff..fde848fc 100644
--- a/src/DHTEntryPointNameResolveCommand.h
+++ b/src/DHTEntryPointNameResolveCommand.h
@@ -41,8 +41,7 @@
#include <vector>
#include <deque>
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -60,16 +59,16 @@ private:
DownloadEngine* e_;
#ifdef ENABLE_ASYNC_DNS
- SharedHandle<AsyncNameResolverMan> asyncNameResolverMan_;
+ std::shared_ptr<AsyncNameResolverMan> asyncNameResolverMan_;
#endif // ENABLE_ASYNC_DNS
- SharedHandle<DHTTaskQueue> taskQueue_;
+ std::shared_ptr<DHTTaskQueue> taskQueue_;
- SharedHandle<DHTTaskFactory> taskFactory_;
+ std::shared_ptr<DHTTaskFactory> taskFactory_;
- SharedHandle<DHTRoutingTable> routingTable_;
+ std::shared_ptr<DHTRoutingTable> routingTable_;
- SharedHandle<DHTNode> localNode_;
+ std::shared_ptr<DHTNode> localNode_;
std::deque<std::pair<std::string, uint16_t> > entryPoints_;
@@ -95,13 +94,13 @@ public:
void setBootstrapEnabled(bool f);
- void setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue);
+ void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
- void setTaskFactory(const SharedHandle<DHTTaskFactory>& taskFactory);
+ void setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory);
- void setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable);
+ void setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable);
- void setLocalNode(const SharedHandle<DHTNode>& localNode);
+ void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
};
} // namespace aria2
diff --git a/src/DHTFindNodeMessage.cc b/src/DHTFindNodeMessage.cc
index ede5f57f..60adb6cd 100644
--- a/src/DHTFindNodeMessage.cc
+++ b/src/DHTFindNodeMessage.cc
@@ -49,8 +49,8 @@ const std::string DHTFindNodeMessage::FIND_NODE("find_node");
const std::string DHTFindNodeMessage::TARGET_NODE("target");
-DHTFindNodeMessage::DHTFindNodeMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+DHTFindNodeMessage::DHTFindNodeMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
const std::string& transactionID):
DHTQueryMessage(localNode, remoteNode, transactionID)
@@ -62,17 +62,17 @@ DHTFindNodeMessage::~DHTFindNodeMessage() {}
void DHTFindNodeMessage::doReceivedAction()
{
- std::vector<SharedHandle<DHTNode> > nodes;
+ std::vector<std::shared_ptr<DHTNode> > nodes;
getRoutingTable()->getClosestKNodes(nodes, targetNodeID_);
- SharedHandle<DHTMessage> reply =
+ std::shared_ptr<DHTMessage> reply =
getMessageFactory()->createFindNodeReplyMessage
(getRemoteNode(), nodes, getTransactionID());
getMessageDispatcher()->addMessageToQueue(reply);
}
-SharedHandle<Dict> DHTFindNodeMessage::getArgument()
+std::shared_ptr<Dict> DHTFindNodeMessage::getArgument()
{
- SharedHandle<Dict> aDict = Dict::g();
+ std::shared_ptr<Dict> aDict = Dict::g();
aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
aDict->put(TARGET_NODE, String::g(targetNodeID_, DHT_ID_LENGTH));
return aDict;
diff --git a/src/DHTFindNodeMessage.h b/src/DHTFindNodeMessage.h
index 431756f2..05ca99a3 100644
--- a/src/DHTFindNodeMessage.h
+++ b/src/DHTFindNodeMessage.h
@@ -46,8 +46,8 @@ private:
protected:
virtual std::string toStringOptional() const;
public:
- DHTFindNodeMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ DHTFindNodeMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
const std::string& transactionID = A2STR::NIL);
@@ -55,7 +55,7 @@ public:
virtual void doReceivedAction();
- virtual SharedHandle<Dict> getArgument();
+ virtual std::shared_ptr<Dict> getArgument();
virtual const std::string& getMessageType() const;
diff --git a/src/DHTFindNodeReplyMessage.cc b/src/DHTFindNodeReplyMessage.cc
index 9669e0ef..74f62366 100644
--- a/src/DHTFindNodeReplyMessage.cc
+++ b/src/DHTFindNodeReplyMessage.cc
@@ -55,8 +55,8 @@ const std::string DHTFindNodeReplyMessage::NODES6("nodes6");
DHTFindNodeReplyMessage::DHTFindNodeReplyMessage
(int family,
- const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID):
DHTResponseMessage(localNode, remoteNode, transactionID),
family_(family) {}
@@ -65,7 +65,7 @@ DHTFindNodeReplyMessage::~DHTFindNodeReplyMessage() {}
void DHTFindNodeReplyMessage::doReceivedAction()
{
- for(std::vector<SharedHandle<DHTNode> >::iterator i = closestKNodes_.begin(),
+ for(std::vector<std::shared_ptr<DHTNode> >::iterator i = closestKNodes_.begin(),
eoi = closestKNodes_.end(); i != eoi; ++i) {
if(memcmp((*i)->getID(), getLocalNode()->getID(), DHT_ID_LENGTH) != 0) {
getRoutingTable()->addNode(*i);
@@ -73,9 +73,9 @@ void DHTFindNodeReplyMessage::doReceivedAction()
}
}
-SharedHandle<Dict> DHTFindNodeReplyMessage::getResponse()
+std::shared_ptr<Dict> DHTFindNodeReplyMessage::getResponse()
{
- SharedHandle<Dict> aDict = Dict::g();
+ std::shared_ptr<Dict> aDict = Dict::g();
aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
unsigned char buffer[DHTBucket::K*38];
const int clen = bittorrent::getCompactLength(family_);
@@ -83,10 +83,10 @@ SharedHandle<Dict> DHTFindNodeReplyMessage::getResponse()
assert(unit <= 38);
size_t offset = 0;
size_t k = 0;
- for(std::vector<SharedHandle<DHTNode> >::const_iterator i =
+ for(std::vector<std::shared_ptr<DHTNode> >::const_iterator i =
closestKNodes_.begin(), eoi = closestKNodes_.end();
i != eoi && k < DHTBucket::K; ++i) {
- SharedHandle<DHTNode> node = *i;
+ std::shared_ptr<DHTNode> node = *i;
memcpy(buffer+offset, node->getID(), DHT_ID_LENGTH);
unsigned char compact[COMPACT_LEN_IPV6];
int compactlen = bittorrent::packcompact
@@ -112,7 +112,7 @@ void DHTFindNodeReplyMessage::accept(DHTMessageCallback* callback)
}
void DHTFindNodeReplyMessage::setClosestKNodes
-(const std::vector<SharedHandle<DHTNode> >& closestKNodes)
+(const std::vector<std::shared_ptr<DHTNode> >& closestKNodes)
{
closestKNodes_ = closestKNodes;
}
diff --git a/src/DHTFindNodeReplyMessage.h b/src/DHTFindNodeReplyMessage.h
index 91f59514..eb62dba1 100644
--- a/src/DHTFindNodeReplyMessage.h
+++ b/src/DHTFindNodeReplyMessage.h
@@ -44,32 +44,32 @@ class DHTFindNodeReplyMessage:public DHTResponseMessage {
private:
int family_;
- std::vector<SharedHandle<DHTNode> > closestKNodes_;
+ std::vector<std::shared_ptr<DHTNode> > closestKNodes_;
protected:
virtual std::string toStringOptional() const;
public:
DHTFindNodeReplyMessage(int family,
- const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID);
virtual ~DHTFindNodeReplyMessage();
virtual void doReceivedAction();
- virtual SharedHandle<Dict> getResponse();
+ virtual std::shared_ptr<Dict> getResponse();
virtual const std::string& getMessageType() const;
virtual void accept(DHTMessageCallback* callback);
- const std::vector<SharedHandle<DHTNode> >& getClosestKNodes() const
+ const std::vector<std::shared_ptr<DHTNode> >& getClosestKNodes() const
{
return closestKNodes_;
}
void setClosestKNodes
- (const std::vector<SharedHandle<DHTNode> >& closestKNodes);
+ (const std::vector<std::shared_ptr<DHTNode> >& closestKNodes);
static const std::string FIND_NODE;
diff --git a/src/DHTGetPeersCommand.cc b/src/DHTGetPeersCommand.cc
index ab7ff16b..90e95853 100644
--- a/src/DHTGetPeersCommand.cc
+++ b/src/DHTGetPeersCommand.cc
@@ -130,22 +130,22 @@ bool DHTGetPeersCommand::execute()
return false;
}
-void DHTGetPeersCommand::setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue)
+void DHTGetPeersCommand::setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue)
{
taskQueue_ = taskQueue;
}
-void DHTGetPeersCommand::setTaskFactory(const SharedHandle<DHTTaskFactory>& taskFactory)
+void DHTGetPeersCommand::setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory)
{
taskFactory_ = taskFactory;
}
-void DHTGetPeersCommand::setBtRuntime(const SharedHandle<BtRuntime>& btRuntime)
+void DHTGetPeersCommand::setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
-void DHTGetPeersCommand::setPeerStorage(const SharedHandle<PeerStorage>& ps)
+void DHTGetPeersCommand::setPeerStorage(const std::shared_ptr<PeerStorage>& ps)
{
peerStorage_ = ps;
}
diff --git a/src/DHTGetPeersCommand.h b/src/DHTGetPeersCommand.h
index 9715709a..03ee64dc 100644
--- a/src/DHTGetPeersCommand.h
+++ b/src/DHTGetPeersCommand.h
@@ -36,7 +36,9 @@
#define D_DHT_GET_PEERS_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "TimerA2.h"
namespace aria2 {
@@ -54,17 +56,17 @@ class DHTGetPeersCommand:public Command {
private:
RequestGroup* requestGroup_;
- SharedHandle<BtRuntime> btRuntime_;
+ std::shared_ptr<BtRuntime> btRuntime_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
DownloadEngine* e_;
- SharedHandle<DHTTaskQueue> taskQueue_;
+ std::shared_ptr<DHTTaskQueue> taskQueue_;
- SharedHandle<DHTTaskFactory> taskFactory_;
+ std::shared_ptr<DHTTaskFactory> taskFactory_;
- SharedHandle<DHTTask> task_;
+ std::shared_ptr<DHTTask> task_;
int numRetry_;
@@ -77,13 +79,13 @@ public:
virtual bool execute();
- void setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue);
+ void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
- void setTaskFactory(const SharedHandle<DHTTaskFactory>& taskFactory);
+ void setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory);
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
};
} // namespace aria2
diff --git a/src/DHTGetPeersMessage.cc b/src/DHTGetPeersMessage.cc
index 6fd94a2b..0a12814d 100644
--- a/src/DHTGetPeersMessage.cc
+++ b/src/DHTGetPeersMessage.cc
@@ -52,8 +52,8 @@ const std::string DHTGetPeersMessage::GET_PEERS("get_peers");
const std::string DHTGetPeersMessage::INFO_HASH("info_hash");
-DHTGetPeersMessage::DHTGetPeersMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+DHTGetPeersMessage::DHTGetPeersMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
const std::string& transactionID):
DHTQueryMessage(localNode, remoteNode, transactionID),
@@ -70,19 +70,19 @@ void DHTGetPeersMessage::doReceivedAction()
std::string token = tokenTracker_->generateToken
(infoHash_, getRemoteNode()->getIPAddress(), getRemoteNode()->getPort());
// Check to see localhost has the contents which has same infohash
- std::vector<SharedHandle<Peer> > peers;
+ std::vector<std::shared_ptr<Peer> > peers;
peerAnnounceStorage_->getPeers(peers, infoHash_);
- std::vector<SharedHandle<DHTNode> > nodes;
+ std::vector<std::shared_ptr<DHTNode> > nodes;
getRoutingTable()->getClosestKNodes(nodes, infoHash_);
- SharedHandle<DHTMessage> reply =
+ std::shared_ptr<DHTMessage> reply =
getMessageFactory()->createGetPeersReplyMessage
(getRemoteNode(), nodes, peers, token, getTransactionID());
getMessageDispatcher()->addMessageToQueue(reply);
}
-SharedHandle<Dict> DHTGetPeersMessage::getArgument()
+std::shared_ptr<Dict> DHTGetPeersMessage::getArgument()
{
- SharedHandle<Dict> aDict = Dict::g();
+ std::shared_ptr<Dict> aDict = Dict::g();
aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
aDict->put(INFO_HASH, String::g(infoHash_, DHT_ID_LENGTH));
return aDict;
diff --git a/src/DHTGetPeersMessage.h b/src/DHTGetPeersMessage.h
index f6e808bd..c662dc1d 100644
--- a/src/DHTGetPeersMessage.h
+++ b/src/DHTGetPeersMessage.h
@@ -54,8 +54,8 @@ private:
protected:
virtual std::string toStringOptional() const;
public:
- DHTGetPeersMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ DHTGetPeersMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
const std::string& transactionID = A2STR::NIL);
@@ -63,7 +63,7 @@ public:
virtual void doReceivedAction();
- virtual SharedHandle<Dict> getArgument();
+ virtual std::shared_ptr<Dict> getArgument();
virtual const std::string& getMessageType() const;
diff --git a/src/DHTGetPeersReplyMessage.cc b/src/DHTGetPeersReplyMessage.cc
index bb56c9de..f64830ef 100644
--- a/src/DHTGetPeersReplyMessage.cc
+++ b/src/DHTGetPeersReplyMessage.cc
@@ -61,8 +61,8 @@ const std::string DHTGetPeersReplyMessage::NODES6("nodes6");
DHTGetPeersReplyMessage::DHTGetPeersReplyMessage
(int family,
- const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& token,
const std::string& transactionID):
DHTResponseMessage(localNode, remoteNode, transactionID),
@@ -76,9 +76,9 @@ void DHTGetPeersReplyMessage::doReceivedAction()
// Returned peers and nodes are handled in DHTPeerLookupTask.
}
-SharedHandle<Dict> DHTGetPeersReplyMessage::getResponse()
+std::shared_ptr<Dict> DHTGetPeersReplyMessage::getResponse()
{
- SharedHandle<Dict> rDict = Dict::g();
+ std::shared_ptr<Dict> rDict = Dict::g();
rDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
rDict->put(TOKEN, token_);
// TODO want parameter
@@ -88,10 +88,10 @@ SharedHandle<Dict> DHTGetPeersReplyMessage::getResponse()
const int unit = clen+20;
size_t offset = 0;
size_t k = 0;
- for(std::vector<SharedHandle<DHTNode> >::const_iterator i =
+ for(std::vector<std::shared_ptr<DHTNode> >::const_iterator i =
closestKNodes_.begin(), eoi = closestKNodes_.end();
i != eoi && k < DHTBucket::K; ++i) {
- SharedHandle<DHTNode> node = *i;
+ std::shared_ptr<DHTNode> node = *i;
memcpy(buffer+offset, node->getID(), DHT_ID_LENGTH);
unsigned char compact[COMPACT_LEN_IPV6];
int compactlen = bittorrent::packcompact
@@ -128,11 +128,11 @@ SharedHandle<Dict> DHTGetPeersReplyMessage::getResponse()
// template may get bigger than 395 bytes. So we use 25 as maximum
// number of peer info that a message can carry.
static const size_t MAX_VALUES_SIZE = 25;
- SharedHandle<List> valuesList = List::g();
- for(std::vector<SharedHandle<Peer> >::const_iterator i = values_.begin(),
+ std::shared_ptr<List> valuesList = List::g();
+ for(std::vector<std::shared_ptr<Peer> >::const_iterator i = values_.begin(),
eoi = values_.end(); i != eoi && valuesList->size() < MAX_VALUES_SIZE;
++i) {
- const SharedHandle<Peer>& peer = *i;
+ const std::shared_ptr<Peer>& peer = *i;
unsigned char compact[COMPACT_LEN_IPV6];
const int clen = bittorrent::getCompactLength(family_);
int compactlen = bittorrent::packcompact
diff --git a/src/DHTGetPeersReplyMessage.h b/src/DHTGetPeersReplyMessage.h
index 045abc81..6c7b7882 100644
--- a/src/DHTGetPeersReplyMessage.h
+++ b/src/DHTGetPeersReplyMessage.h
@@ -51,15 +51,15 @@ private:
std::string token_;
- std::vector<SharedHandle<DHTNode> > closestKNodes_;
+ std::vector<std::shared_ptr<DHTNode> > closestKNodes_;
- std::vector<SharedHandle<Peer> > values_;
+ std::vector<std::shared_ptr<Peer> > values_;
protected:
virtual std::string toStringOptional() const;
public:
DHTGetPeersReplyMessage(int family,
- const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& token,
const std::string& transactionID);
@@ -67,29 +67,29 @@ public:
virtual void doReceivedAction();
- virtual SharedHandle<Dict> getResponse();
+ virtual std::shared_ptr<Dict> getResponse();
virtual const std::string& getMessageType() const;
virtual void accept(DHTMessageCallback* callback);
- const std::vector<SharedHandle<DHTNode> >& getClosestKNodes() const
+ const std::vector<std::shared_ptr<DHTNode> >& getClosestKNodes() const
{
return closestKNodes_;
}
- const std::vector<SharedHandle<Peer> >& getValues() const
+ const std::vector<std::shared_ptr<Peer> >& getValues() const
{
return values_;
}
void setClosestKNodes
- (const std::vector<SharedHandle<DHTNode> >& closestKNodes)
+ (const std::vector<std::shared_ptr<DHTNode> >& closestKNodes)
{
closestKNodes_ = closestKNodes;
}
- void setValues(const std::vector<SharedHandle<Peer> >& peers)
+ void setValues(const std::vector<std::shared_ptr<Peer> >& peers)
{
values_ = peers;
}
diff --git a/src/DHTIDCloser.h b/src/DHTIDCloser.h
index 4d263131..920f197d 100644
--- a/src/DHTIDCloser.h
+++ b/src/DHTIDCloser.h
@@ -48,8 +48,8 @@ private:
public:
DHTIDCloser(const unsigned char* targetID):closer_(targetID, DHT_ID_LENGTH) {}
- bool operator()(const SharedHandle<DHTNodeLookupEntry>& m1,
- const SharedHandle<DHTNodeLookupEntry>& m2) const
+ bool operator()(const std::shared_ptr<DHTNodeLookupEntry>& m1,
+ const std::shared_ptr<DHTNodeLookupEntry>& m2) const
{
return closer_(m1->node->getID(), m2->node->getID());
}
diff --git a/src/DHTInteractionCommand.cc b/src/DHTInteractionCommand.cc
index 096812a8..2e6f77ea 100644
--- a/src/DHTInteractionCommand.cc
+++ b/src/DHTInteractionCommand.cc
@@ -66,7 +66,7 @@ DHTInteractionCommand::~DHTInteractionCommand()
disableReadCheckSocket(readCheckSocket_);
}
-void DHTInteractionCommand::setReadCheckSocket(const SharedHandle<SocketCore>& socket)
+void DHTInteractionCommand::setReadCheckSocket(const std::shared_ptr<SocketCore>& socket)
{
readCheckSocket_ = socket;
if(socket) {
@@ -74,7 +74,7 @@ void DHTInteractionCommand::setReadCheckSocket(const SharedHandle<SocketCore>& s
}
}
-void DHTInteractionCommand::disableReadCheckSocket(const SharedHandle<SocketCore>& socket)
+void DHTInteractionCommand::disableReadCheckSocket(const std::shared_ptr<SocketCore>& socket)
{
if(socket) {
e_->deleteSocketForReadCheck(socket, this);
@@ -142,29 +142,29 @@ bool DHTInteractionCommand::execute()
return false;
}
-void DHTInteractionCommand::setMessageDispatcher(const SharedHandle<DHTMessageDispatcher>& dispatcher)
+void DHTInteractionCommand::setMessageDispatcher(const std::shared_ptr<DHTMessageDispatcher>& dispatcher)
{
dispatcher_ = dispatcher;
}
-void DHTInteractionCommand::setMessageReceiver(const SharedHandle<DHTMessageReceiver>& receiver)
+void DHTInteractionCommand::setMessageReceiver(const std::shared_ptr<DHTMessageReceiver>& receiver)
{
receiver_ = receiver;
}
-void DHTInteractionCommand::setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue)
+void DHTInteractionCommand::setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue)
{
taskQueue_ = taskQueue;
}
void DHTInteractionCommand::setConnection
-(const SharedHandle<DHTConnection>& connection)
+(const std::shared_ptr<DHTConnection>& connection)
{
connection_ = connection;
}
void DHTInteractionCommand::setUDPTrackerClient
-(const SharedHandle<UDPTrackerClient>& udpTrackerClient)
+(const std::shared_ptr<UDPTrackerClient>& udpTrackerClient)
{
udpTrackerClient_ = udpTrackerClient;
}
diff --git a/src/DHTInteractionCommand.h b/src/DHTInteractionCommand.h
index e90a1dd6..f9de06c9 100644
--- a/src/DHTInteractionCommand.h
+++ b/src/DHTInteractionCommand.h
@@ -36,7 +36,8 @@
#define D_DHT_INTERACTION_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -51,12 +52,12 @@ class UDPTrackerClient;
class DHTInteractionCommand:public Command {
private:
DownloadEngine* e_;
- SharedHandle<DHTMessageDispatcher> dispatcher_;
- SharedHandle<DHTMessageReceiver> receiver_;
- SharedHandle<DHTTaskQueue> taskQueue_;
- SharedHandle<SocketCore> readCheckSocket_;
- SharedHandle<DHTConnection> connection_;
- SharedHandle<UDPTrackerClient> udpTrackerClient_;
+ std::shared_ptr<DHTMessageDispatcher> dispatcher_;
+ std::shared_ptr<DHTMessageReceiver> receiver_;
+ std::shared_ptr<DHTTaskQueue> taskQueue_;
+ std::shared_ptr<SocketCore> readCheckSocket_;
+ std::shared_ptr<DHTConnection> connection_;
+ std::shared_ptr<UDPTrackerClient> udpTrackerClient_;
public:
DHTInteractionCommand(cuid_t cuid, DownloadEngine* e);
@@ -64,20 +65,20 @@ public:
virtual bool execute();
- void setReadCheckSocket(const SharedHandle<SocketCore>& socket);
+ void setReadCheckSocket(const std::shared_ptr<SocketCore>& socket);
- void disableReadCheckSocket(const SharedHandle<SocketCore>& socket);
+ void disableReadCheckSocket(const std::shared_ptr<SocketCore>& socket);
- void setMessageDispatcher(const SharedHandle<DHTMessageDispatcher>& dispatcher);
+ void setMessageDispatcher(const std::shared_ptr<DHTMessageDispatcher>& dispatcher);
- void setMessageReceiver(const SharedHandle<DHTMessageReceiver>& receiver);
+ void setMessageReceiver(const std::shared_ptr<DHTMessageReceiver>& receiver);
- void setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue);
+ void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
- void setConnection(const SharedHandle<DHTConnection>& connection);
+ void setConnection(const std::shared_ptr<DHTConnection>& connection);
void setUDPTrackerClient
- (const SharedHandle<UDPTrackerClient>& udpTrackerClient);
+ (const std::shared_ptr<UDPTrackerClient>& udpTrackerClient);
};
} // namespace aria2
diff --git a/src/DHTMessage.cc b/src/DHTMessage.cc
index 69fea1f4..6a0b52de 100644
--- a/src/DHTMessage.cc
+++ b/src/DHTMessage.cc
@@ -46,8 +46,8 @@ const std::string DHTMessage::V("v");
const std::string DHTMessage::ID("id");
-DHTMessage::DHTMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+DHTMessage::DHTMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID):
localNode_(localNode), remoteNode_(remoteNode), transactionID_(transactionID)
{
diff --git a/src/DHTMessage.h b/src/DHTMessage.h
index 5a50e801..c5c64b41 100644
--- a/src/DHTMessage.h
+++ b/src/DHTMessage.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "A2STR.h"
namespace aria2 {
@@ -48,9 +48,9 @@ class DHTNode;
class DHTMessage {
private:
- SharedHandle<DHTNode> localNode_;
+ std::shared_ptr<DHTNode> localNode_;
- SharedHandle<DHTNode> remoteNode_;
+ std::shared_ptr<DHTNode> remoteNode_;
std::string transactionID_;
@@ -58,8 +58,8 @@ private:
void generateTransactionID();
public:
- DHTMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ DHTMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID = A2STR::NIL);
virtual ~DHTMessage();
@@ -69,12 +69,12 @@ public:
return transactionID_;
}
- const SharedHandle<DHTNode>& getLocalNode() const
+ const std::shared_ptr<DHTNode>& getLocalNode() const
{
return localNode_;
}
- const SharedHandle<DHTNode>& getRemoteNode() const
+ const std::shared_ptr<DHTNode>& getRemoteNode() const
{
return remoteNode_;
}
diff --git a/src/DHTMessageCallback.h b/src/DHTMessageCallback.h
index 3f59eaa4..4dc72d1e 100644
--- a/src/DHTMessageCallback.h
+++ b/src/DHTMessageCallback.h
@@ -36,7 +36,9 @@
#define D_DHT_MESSAGE_CALLBACK_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "DHTResponseMessage.h"
namespace aria2 {
@@ -51,7 +53,7 @@ class DHTMessageCallback {
public:
virtual ~DHTMessageCallback() {}
- void onReceived(const SharedHandle<DHTResponseMessage>& message)
+ void onReceived(const std::shared_ptr<DHTResponseMessage>& message)
{
message->accept(this);
}
@@ -64,7 +66,7 @@ public:
virtual void visit(const DHTPingReplyMessage* message) = 0;
- virtual void onTimeout(const SharedHandle<DHTNode>& remoteNode) = 0;
+ virtual void onTimeout(const std::shared_ptr<DHTNode>& remoteNode) = 0;
};
} // namespace aria2
diff --git a/src/DHTMessageDispatcher.h b/src/DHTMessageDispatcher.h
index 7f7a64e2..c9285f9e 100644
--- a/src/DHTMessageDispatcher.h
+++ b/src/DHTMessageDispatcher.h
@@ -36,7 +36,9 @@
#define D_DHT_MESSAGE_DISPATCHER_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "a2time.h"
namespace aria2 {
@@ -49,15 +51,15 @@ public:
virtual ~DHTMessageDispatcher() {}
virtual void
- addMessageToQueue(const SharedHandle<DHTMessage>& message,
+ addMessageToQueue(const std::shared_ptr<DHTMessage>& message,
time_t timeout,
- const SharedHandle<DHTMessageCallback>& callback =
- SharedHandle<DHTMessageCallback>()) = 0;
+ const std::shared_ptr<DHTMessageCallback>& callback =
+ std::shared_ptr<DHTMessageCallback>()) = 0;
virtual void
- addMessageToQueue(const SharedHandle<DHTMessage>& message,
- const SharedHandle<DHTMessageCallback>& callback =
- SharedHandle<DHTMessageCallback>()) = 0;
+ addMessageToQueue(const std::shared_ptr<DHTMessage>& message,
+ const std::shared_ptr<DHTMessageCallback>& callback =
+ std::shared_ptr<DHTMessageCallback>()) = 0;
virtual void sendMessages() = 0;
diff --git a/src/DHTMessageDispatcherImpl.cc b/src/DHTMessageDispatcherImpl.cc
index f9ff0ac1..8cdf4c52 100644
--- a/src/DHTMessageDispatcherImpl.cc
+++ b/src/DHTMessageDispatcherImpl.cc
@@ -47,7 +47,7 @@
namespace aria2 {
DHTMessageDispatcherImpl::DHTMessageDispatcherImpl
-(const SharedHandle<DHTMessageTracker>& tracker)
+(const std::shared_ptr<DHTMessageTracker>& tracker)
: tracker_(tracker),
timeout_(DHT_MESSAGE_TIMEOUT)
{}
@@ -56,26 +56,26 @@ DHTMessageDispatcherImpl::~DHTMessageDispatcherImpl() {}
void
DHTMessageDispatcherImpl::addMessageToQueue
-(const SharedHandle<DHTMessage>& message,
+(const std::shared_ptr<DHTMessage>& message,
time_t timeout,
- const SharedHandle<DHTMessageCallback>& callback)
+ const std::shared_ptr<DHTMessageCallback>& callback)
{
- SharedHandle<DHTMessageEntry> e
+ std::shared_ptr<DHTMessageEntry> e
(new DHTMessageEntry(message, timeout, callback));
messageQueue_.push_back(e);
}
void
DHTMessageDispatcherImpl::addMessageToQueue
-(const SharedHandle<DHTMessage>& message,
- const SharedHandle<DHTMessageCallback>& callback)
+(const std::shared_ptr<DHTMessage>& message,
+ const std::shared_ptr<DHTMessageCallback>& callback)
{
addMessageToQueue(message, timeout_, callback);
}
bool
DHTMessageDispatcherImpl::sendMessage
-(const SharedHandle<DHTMessageEntry>& entry)
+(const std::shared_ptr<DHTMessageEntry>& entry)
{
try {
if(entry->message->send()) {
@@ -105,7 +105,7 @@ void DHTMessageDispatcherImpl::sendMessages()
{
// TODO I can't use bind1st and mem_fun here because bind1st cannot bind a
// function which takes a reference as an argument..
- std::deque<SharedHandle<DHTMessageEntry> >::iterator itr =
+ std::deque<std::shared_ptr<DHTMessageEntry> >::iterator itr =
messageQueue_.begin();
for(; itr != messageQueue_.end(); ++itr) {
if(!sendMessage(*itr)) {
diff --git a/src/DHTMessageDispatcherImpl.h b/src/DHTMessageDispatcherImpl.h
index d0f2090e..68767234 100644
--- a/src/DHTMessageDispatcherImpl.h
+++ b/src/DHTMessageDispatcherImpl.h
@@ -45,28 +45,28 @@ struct DHTMessageEntry;
class DHTMessageDispatcherImpl:public DHTMessageDispatcher {
private:
- SharedHandle<DHTMessageTracker> tracker_;
+ std::shared_ptr<DHTMessageTracker> tracker_;
- std::deque<SharedHandle<DHTMessageEntry> > messageQueue_;
+ std::deque<std::shared_ptr<DHTMessageEntry> > messageQueue_;
time_t timeout_;
- bool sendMessage(const SharedHandle<DHTMessageEntry>& msg);
+ bool sendMessage(const std::shared_ptr<DHTMessageEntry>& msg);
public:
- DHTMessageDispatcherImpl(const SharedHandle<DHTMessageTracker>& tracker);
+ DHTMessageDispatcherImpl(const std::shared_ptr<DHTMessageTracker>& tracker);
virtual ~DHTMessageDispatcherImpl();
virtual void
- addMessageToQueue(const SharedHandle<DHTMessage>& message,
+ addMessageToQueue(const std::shared_ptr<DHTMessage>& message,
time_t timeout,
- const SharedHandle<DHTMessageCallback>& callback =
- SharedHandle<DHTMessageCallback>());
+ const std::shared_ptr<DHTMessageCallback>& callback =
+ std::shared_ptr<DHTMessageCallback>());
virtual void
- addMessageToQueue(const SharedHandle<DHTMessage>& message,
- const SharedHandle<DHTMessageCallback>& callback =
- SharedHandle<DHTMessageCallback>());
+ addMessageToQueue(const std::shared_ptr<DHTMessage>& message,
+ const std::shared_ptr<DHTMessageCallback>& callback =
+ std::shared_ptr<DHTMessageCallback>());
virtual void sendMessages();
diff --git a/src/DHTMessageEntry.cc b/src/DHTMessageEntry.cc
index 6eaafe5d..1c2f4cd7 100644
--- a/src/DHTMessageEntry.cc
+++ b/src/DHTMessageEntry.cc
@@ -40,9 +40,9 @@
namespace aria2 {
DHTMessageEntry::DHTMessageEntry
-(const SharedHandle<DHTMessage>& message,
+(const std::shared_ptr<DHTMessage>& message,
time_t timeout,
- const SharedHandle<DHTMessageCallback>& callback):
+ const std::shared_ptr<DHTMessageCallback>& callback):
message(message),
timeout(timeout),
callback(callback) {}
diff --git a/src/DHTMessageEntry.h b/src/DHTMessageEntry.h
index 92c71064..2698b5ae 100644
--- a/src/DHTMessageEntry.h
+++ b/src/DHTMessageEntry.h
@@ -36,7 +36,9 @@
#define D_DHT_MESSAGE_ENTRY_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "a2time.h"
namespace aria2 {
@@ -45,13 +47,13 @@ class DHTMessage;
class DHTMessageCallback;
struct DHTMessageEntry {
- SharedHandle<DHTMessage> message;
+ std::shared_ptr<DHTMessage> message;
time_t timeout;
- SharedHandle<DHTMessageCallback> callback;
+ std::shared_ptr<DHTMessageCallback> callback;
- DHTMessageEntry(const SharedHandle<DHTMessage>& message,
+ DHTMessageEntry(const std::shared_ptr<DHTMessage>& message,
time_t timeout,
- const SharedHandle<DHTMessageCallback>& callback);
+ const std::shared_ptr<DHTMessageCallback>& callback);
~DHTMessageEntry();
};
diff --git a/src/DHTMessageFactory.h b/src/DHTMessageFactory.h
index 40e9c852..2d8a8ad3 100644
--- a/src/DHTMessageFactory.h
+++ b/src/DHTMessageFactory.h
@@ -39,8 +39,8 @@
#include <string>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "A2STR.h"
#include "ValueBase.h"
@@ -56,60 +56,60 @@ class DHTMessageFactory {
public:
virtual ~DHTMessageFactory() {}
- virtual SharedHandle<DHTQueryMessage>
+ virtual std::shared_ptr<DHTQueryMessage>
createQueryMessage(const Dict* dict,
const std::string& ipaddr, uint16_t port) = 0;
- virtual SharedHandle<DHTResponseMessage>
+ virtual std::shared_ptr<DHTResponseMessage>
createResponseMessage(const std::string& messageType,
const Dict* dict,
const std::string& ipaddr, uint16_t port) = 0;
- virtual SharedHandle<DHTQueryMessage>
- createPingMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTQueryMessage>
+ createPingMessage(const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID = A2STR::NIL) = 0;
- virtual SharedHandle<DHTResponseMessage>
- createPingReplyMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTResponseMessage>
+ createPingReplyMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* id,
const std::string& transactionID) = 0;
- virtual SharedHandle<DHTQueryMessage>
- createFindNodeMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTQueryMessage>
+ createFindNodeMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
const std::string& transactionID = A2STR::NIL) = 0;
- virtual SharedHandle<DHTResponseMessage>
+ virtual std::shared_ptr<DHTResponseMessage>
createFindNodeReplyMessage
- (const SharedHandle<DHTNode>& remoteNode,
- const std::vector<SharedHandle<DHTNode> >& closestKNodes,
+ (const std::shared_ptr<DHTNode>& remoteNode,
+ const std::vector<std::shared_ptr<DHTNode> >& closestKNodes,
const std::string& transactionID) = 0;
- virtual SharedHandle<DHTQueryMessage>
- createGetPeersMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTQueryMessage>
+ createGetPeersMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
const std::string& transactionID = A2STR::NIL) = 0;
- virtual SharedHandle<DHTResponseMessage>
+ virtual std::shared_ptr<DHTResponseMessage>
createGetPeersReplyMessage
- (const SharedHandle<DHTNode>& remoteNode,
- const std::vector<SharedHandle<DHTNode> >& closestKNodes,
- const std::vector<SharedHandle<Peer> >& peers,
+ (const std::shared_ptr<DHTNode>& remoteNode,
+ const std::vector<std::shared_ptr<DHTNode> >& closestKNodes,
+ const std::vector<std::shared_ptr<Peer> >& peers,
const std::string& token,
const std::string& transactionID) = 0;
- virtual SharedHandle<DHTQueryMessage>
- createAnnouncePeerMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTQueryMessage>
+ createAnnouncePeerMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
uint16_t tcpPort,
const std::string& token,
const std::string& transactionID = A2STR::NIL) = 0;
- virtual SharedHandle<DHTResponseMessage>
- createAnnouncePeerReplyMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTResponseMessage>
+ createAnnouncePeerReplyMessage(const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID) = 0;
- virtual SharedHandle<DHTMessage>
+ virtual std::shared_ptr<DHTMessage>
createUnknownMessage(const unsigned char* data, size_t length,
const std::string& ipaddr, uint16_t port) = 0;
};
diff --git a/src/DHTMessageFactoryImpl.cc b/src/DHTMessageFactoryImpl.cc
index 4e09db3b..f1d07c2b 100644
--- a/src/DHTMessageFactoryImpl.cc
+++ b/src/DHTMessageFactoryImpl.cc
@@ -75,11 +75,11 @@ DHTMessageFactoryImpl::DHTMessageFactoryImpl(int family)
DHTMessageFactoryImpl::~DHTMessageFactoryImpl() {}
-SharedHandle<DHTNode>
+std::shared_ptr<DHTNode>
DHTMessageFactoryImpl::getRemoteNode
(const unsigned char* id, const std::string& ipaddr, uint16_t port) const
{
- SharedHandle<DHTNode> node = routingTable_->getNode(id, ipaddr, port);
+ std::shared_ptr<DHTNode> node = routingTable_->getNode(id, ipaddr, port);
if(!node) {
node.reset(new DHTNode(id));
node->setIPAddress(ipaddr);
@@ -188,7 +188,7 @@ void DHTMessageFactoryImpl::validatePort(const Integer* port) const
}
namespace {
-void setVersion(const SharedHandle<DHTMessage>& msg, const Dict* dict)
+void setVersion(const std::shared_ptr<DHTMessage>& msg, const Dict* dict)
{
const String* v = downcast<String>(dict->get(DHTMessage::V));
if(v) {
@@ -199,7 +199,7 @@ void setVersion(const SharedHandle<DHTMessage>& msg, const Dict* dict)
}
} // namespace
-SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createQueryMessage
+std::shared_ptr<DHTQueryMessage> DHTMessageFactoryImpl::createQueryMessage
(const Dict* dict, const std::string& ipaddr, uint16_t port)
{
const String* messageType = getString(dict, DHTQueryMessage::Q);
@@ -211,8 +211,8 @@ SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createQueryMessage
}
const String* id = getString(aDict, DHTMessage::ID);
validateID(id);
- SharedHandle<DHTNode> remoteNode = getRemoteNode(id->uc(), ipaddr, port);
- SharedHandle<DHTQueryMessage> msg;
+ std::shared_ptr<DHTNode> remoteNode = getRemoteNode(id->uc(), ipaddr, port);
+ std::shared_ptr<DHTQueryMessage> msg;
if(messageType->s() == DHTPingMessage::PING) {
msg = createPingMessage(remoteNode, transactionID->s());
} else if(messageType->s() == DHTFindNodeMessage::FIND_NODE) {
@@ -242,7 +242,7 @@ SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createQueryMessage
return msg;
}
-SharedHandle<DHTResponseMessage>
+std::shared_ptr<DHTResponseMessage>
DHTMessageFactoryImpl::createResponseMessage
(const std::string& messageType,
const Dict* dict,
@@ -270,8 +270,8 @@ DHTMessageFactoryImpl::createResponseMessage
const Dict* rDict = getDictionary(dict, DHTResponseMessage::R);
const String* id = getString(rDict, DHTMessage::ID);
validateID(id);
- SharedHandle<DHTNode> remoteNode = getRemoteNode(id->uc(), ipaddr, port);
- SharedHandle<DHTResponseMessage> msg;
+ std::shared_ptr<DHTNode> remoteNode = getRemoteNode(id->uc(), ipaddr, port);
+ std::shared_ptr<DHTResponseMessage> msg;
if(messageType == DHTPingReplyMessage::PING) {
msg = createPingReplyMessage(remoteNode, id->uc(), transactionID->s());
} else if(messageType == DHTFindNodeReplyMessage::FIND_NODE) {
@@ -312,51 +312,51 @@ void DHTMessageFactoryImpl::setCommonProperty(DHTAbstractMessage* m)
m->setVersion(getDefaultVersion());
}
-SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createPingMessage
-(const SharedHandle<DHTNode>& remoteNode, const std::string& transactionID)
+std::shared_ptr<DHTQueryMessage> DHTMessageFactoryImpl::createPingMessage
+(const std::shared_ptr<DHTNode>& remoteNode, const std::string& transactionID)
{
DHTPingMessage* m(new DHTPingMessage(localNode_, remoteNode, transactionID));
setCommonProperty(m);
- return SharedHandle<DHTQueryMessage>(m);
+ return std::shared_ptr<DHTQueryMessage>(m);
}
-SharedHandle<DHTResponseMessage> DHTMessageFactoryImpl::createPingReplyMessage
-(const SharedHandle<DHTNode>& remoteNode,
+std::shared_ptr<DHTResponseMessage> DHTMessageFactoryImpl::createPingReplyMessage
+(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* id,
const std::string& transactionID)
{
DHTPingReplyMessage* m
(new DHTPingReplyMessage(localNode_, remoteNode, id, transactionID));
setCommonProperty(m);
- return SharedHandle<DHTResponseMessage>(m);
+ return std::shared_ptr<DHTResponseMessage>(m);
}
-SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createFindNodeMessage
-(const SharedHandle<DHTNode>& remoteNode,
+std::shared_ptr<DHTQueryMessage> DHTMessageFactoryImpl::createFindNodeMessage
+(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
const std::string& transactionID)
{
DHTFindNodeMessage* m(new DHTFindNodeMessage
(localNode_, remoteNode, targetNodeID, transactionID));
setCommonProperty(m);
- return SharedHandle<DHTQueryMessage>(m);
+ return std::shared_ptr<DHTQueryMessage>(m);
}
-SharedHandle<DHTResponseMessage>
+std::shared_ptr<DHTResponseMessage>
DHTMessageFactoryImpl::createFindNodeReplyMessage
-(const SharedHandle<DHTNode>& remoteNode,
- const std::vector<SharedHandle<DHTNode> >& closestKNodes,
+(const std::shared_ptr<DHTNode>& remoteNode,
+ const std::vector<std::shared_ptr<DHTNode> >& closestKNodes,
const std::string& transactionID)
{
DHTFindNodeReplyMessage* m(new DHTFindNodeReplyMessage
(family_, localNode_, remoteNode, transactionID));
m->setClosestKNodes(closestKNodes);
setCommonProperty(m);
- return SharedHandle<DHTResponseMessage>(m);
+ return std::shared_ptr<DHTResponseMessage>(m);
}
void DHTMessageFactoryImpl::extractNodes
-(std::vector<SharedHandle<DHTNode> >& nodes,
+(std::vector<std::shared_ptr<DHTNode> >& nodes,
const unsigned char* src, size_t length)
{
int unit = bittorrent::getCompactLength(family_)+20;
@@ -365,7 +365,7 @@ void DHTMessageFactoryImpl::extractNodes
(fmt("Nodes length is not multiple of %d", unit));
}
for(size_t offset = 0; offset < length; offset += unit) {
- SharedHandle<DHTNode> node(new DHTNode(src+offset));
+ std::shared_ptr<DHTNode> node(new DHTNode(src+offset));
std::pair<std::string, uint16_t> addr =
bittorrent::unpackcompact(src+offset+DHT_ID_LENGTH, family_);
if(addr.first.empty()) {
@@ -377,9 +377,9 @@ void DHTMessageFactoryImpl::extractNodes
}
}
-SharedHandle<DHTResponseMessage>
+std::shared_ptr<DHTResponseMessage>
DHTMessageFactoryImpl::createFindNodeReplyMessage
-(const SharedHandle<DHTNode>& remoteNode,
+(const std::shared_ptr<DHTNode>& remoteNode,
const Dict* dict,
const std::string& transactionID)
{
@@ -387,16 +387,16 @@ DHTMessageFactoryImpl::createFindNodeReplyMessage
downcast<String>(getDictionary(dict, DHTResponseMessage::R)->
get(family_ == AF_INET?DHTFindNodeReplyMessage::NODES:
DHTFindNodeReplyMessage::NODES6));
- std::vector<SharedHandle<DHTNode> > nodes;
+ std::vector<std::shared_ptr<DHTNode> > nodes;
if(nodesData) {
extractNodes(nodes, nodesData->uc(), nodesData->s().size());
}
return createFindNodeReplyMessage(remoteNode, nodes, transactionID);
}
-SharedHandle<DHTQueryMessage>
+std::shared_ptr<DHTQueryMessage>
DHTMessageFactoryImpl::createGetPeersMessage
-(const SharedHandle<DHTNode>& remoteNode,
+(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
const std::string& transactionID)
{
@@ -405,12 +405,12 @@ DHTMessageFactoryImpl::createGetPeersMessage
m->setPeerAnnounceStorage(peerAnnounceStorage_);
m->setTokenTracker(tokenTracker_);
setCommonProperty(m);
- return SharedHandle<DHTQueryMessage>(m);
+ return std::shared_ptr<DHTQueryMessage>(m);
}
-SharedHandle<DHTResponseMessage>
+std::shared_ptr<DHTResponseMessage>
DHTMessageFactoryImpl::createGetPeersReplyMessage
-(const SharedHandle<DHTNode>& remoteNode,
+(const std::shared_ptr<DHTNode>& remoteNode,
const Dict* dict,
const std::string& transactionID)
{
@@ -418,13 +418,13 @@ DHTMessageFactoryImpl::createGetPeersReplyMessage
const String* nodesData =
downcast<String>(rDict->get(family_ == AF_INET?DHTGetPeersReplyMessage::NODES:
DHTGetPeersReplyMessage::NODES6));
- std::vector<SharedHandle<DHTNode> > nodes;
+ std::vector<std::shared_ptr<DHTNode> > nodes;
if(nodesData) {
extractNodes(nodes, nodesData->uc(), nodesData->s().size());
}
const List* valuesList =
downcast<List>(rDict->get(DHTGetPeersReplyMessage::VALUES));
- std::vector<SharedHandle<Peer> > peers;
+ std::vector<std::shared_ptr<Peer> > peers;
size_t clen = bittorrent::getCompactLength(family_);
if(valuesList) {
for(List::ValueType::const_iterator i = valuesList->begin(),
@@ -436,7 +436,7 @@ DHTMessageFactoryImpl::createGetPeersReplyMessage
if(addr.first.empty()) {
continue;
}
- SharedHandle<Peer> peer(new Peer(addr.first, addr.second));
+ std::shared_ptr<Peer> peer(new Peer(addr.first, addr.second));
peers.push_back(peer);
}
}
@@ -446,11 +446,11 @@ DHTMessageFactoryImpl::createGetPeersReplyMessage
(remoteNode, nodes, peers, token->s(), transactionID);
}
-SharedHandle<DHTResponseMessage>
+std::shared_ptr<DHTResponseMessage>
DHTMessageFactoryImpl::createGetPeersReplyMessage
-(const SharedHandle<DHTNode>& remoteNode,
- const std::vector<SharedHandle<DHTNode> >& closestKNodes,
- const std::vector<SharedHandle<Peer> >& values,
+(const std::shared_ptr<DHTNode>& remoteNode,
+ const std::vector<std::shared_ptr<DHTNode> >& closestKNodes,
+ const std::vector<std::shared_ptr<Peer> >& values,
const std::string& token,
const std::string& transactionID)
{
@@ -460,12 +460,12 @@ DHTMessageFactoryImpl::createGetPeersReplyMessage
m->setClosestKNodes(closestKNodes);
m->setValues(values);
setCommonProperty(m);
- return SharedHandle<DHTResponseMessage>(m);
+ return std::shared_ptr<DHTResponseMessage>(m);
}
-SharedHandle<DHTQueryMessage>
+std::shared_ptr<DHTQueryMessage>
DHTMessageFactoryImpl::createAnnouncePeerMessage
-(const SharedHandle<DHTNode>& remoteNode,
+(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
uint16_t tcpPort,
const std::string& token,
@@ -477,20 +477,20 @@ DHTMessageFactoryImpl::createAnnouncePeerMessage
m->setPeerAnnounceStorage(peerAnnounceStorage_);
m->setTokenTracker(tokenTracker_);
setCommonProperty(m);
- return SharedHandle<DHTQueryMessage>(m);
+ return std::shared_ptr<DHTQueryMessage>(m);
}
-SharedHandle<DHTResponseMessage>
+std::shared_ptr<DHTResponseMessage>
DHTMessageFactoryImpl::createAnnouncePeerReplyMessage
-(const SharedHandle<DHTNode>& remoteNode, const std::string& transactionID)
+(const std::shared_ptr<DHTNode>& remoteNode, const std::string& transactionID)
{
DHTAnnouncePeerReplyMessage* m
(new DHTAnnouncePeerReplyMessage(localNode_, remoteNode, transactionID));
setCommonProperty(m);
- return SharedHandle<DHTResponseMessage>(m);
+ return std::shared_ptr<DHTResponseMessage>(m);
}
-SharedHandle<DHTMessage>
+std::shared_ptr<DHTMessage>
DHTMessageFactoryImpl::createUnknownMessage
(const unsigned char* data, size_t length,
const std::string& ipaddr, uint16_t port)
@@ -498,7 +498,7 @@ DHTMessageFactoryImpl::createUnknownMessage
{
DHTUnknownMessage* m
(new DHTUnknownMessage(localNode_, data, length, ipaddr, port));
- return SharedHandle<DHTMessage>(m);
+ return std::shared_ptr<DHTMessage>(m);
}
void DHTMessageFactoryImpl::setRoutingTable(DHTRoutingTable* routingTable)
@@ -529,7 +529,7 @@ void DHTMessageFactoryImpl::setTokenTracker(DHTTokenTracker* tokenTracker)
}
void DHTMessageFactoryImpl::setLocalNode
-(const SharedHandle<DHTNode>& localNode)
+(const std::shared_ptr<DHTNode>& localNode)
{
localNode_ = localNode;
}
diff --git a/src/DHTMessageFactoryImpl.h b/src/DHTMessageFactoryImpl.h
index 87738b44..cafdcbd3 100644
--- a/src/DHTMessageFactoryImpl.h
+++ b/src/DHTMessageFactoryImpl.h
@@ -52,7 +52,7 @@ class DHTMessageFactoryImpl:public DHTMessageFactory {
private:
int family_;
- SharedHandle<DHTNode> localNode_;
+ std::shared_ptr<DHTNode> localNode_;
DHTConnection* connection_;
@@ -65,7 +65,7 @@ private:
DHTTokenTracker* tokenTracker_;
// search node in routingTable. If it is not found, create new one.
- SharedHandle<DHTNode> getRemoteNode
+ std::shared_ptr<DHTNode> getRemoteNode
(const unsigned char* id, const std::string& ipaddr, uint16_t port) const;
void validateID(const String* id) const;
@@ -73,7 +73,7 @@ private:
void validatePort(const Integer* i) const;
void extractNodes
- (std::vector<SharedHandle<DHTNode> >& nodes,
+ (std::vector<std::shared_ptr<DHTNode> >& nodes,
const unsigned char* src, size_t length);
void setCommonProperty(DHTAbstractMessage* m);
@@ -83,72 +83,72 @@ public:
virtual ~DHTMessageFactoryImpl();
- virtual SharedHandle<DHTQueryMessage>
+ virtual std::shared_ptr<DHTQueryMessage>
createQueryMessage(const Dict* dict,
const std::string& ipaddr, uint16_t port);
- virtual SharedHandle<DHTResponseMessage>
+ virtual std::shared_ptr<DHTResponseMessage>
createResponseMessage(const std::string& messageType,
const Dict* dict,
const std::string& ipaddr, uint16_t port);
- virtual SharedHandle<DHTQueryMessage>
- createPingMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTQueryMessage>
+ createPingMessage(const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID = A2STR::NIL);
- virtual SharedHandle<DHTResponseMessage>
- createPingReplyMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTResponseMessage>
+ createPingReplyMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* id,
const std::string& transactionID);
- virtual SharedHandle<DHTQueryMessage>
- createFindNodeMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTQueryMessage>
+ createFindNodeMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
const std::string& transactionID = A2STR::NIL);
- SharedHandle<DHTResponseMessage>
- createFindNodeReplyMessage(const SharedHandle<DHTNode>& remoteNode,
+ std::shared_ptr<DHTResponseMessage>
+ createFindNodeReplyMessage(const std::shared_ptr<DHTNode>& remoteNode,
const Dict* dict,
const std::string& transactionID);
- virtual SharedHandle<DHTResponseMessage>
+ virtual std::shared_ptr<DHTResponseMessage>
createFindNodeReplyMessage
- (const SharedHandle<DHTNode>& remoteNode,
- const std::vector<SharedHandle<DHTNode> >& closestKNodes,
+ (const std::shared_ptr<DHTNode>& remoteNode,
+ const std::vector<std::shared_ptr<DHTNode> >& closestKNodes,
const std::string& transactionID);
- virtual SharedHandle<DHTQueryMessage>
- createGetPeersMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTQueryMessage>
+ createGetPeersMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
const std::string& transactionID = A2STR::NIL);
- virtual SharedHandle<DHTResponseMessage>
+ virtual std::shared_ptr<DHTResponseMessage>
createGetPeersReplyMessage
- (const SharedHandle<DHTNode>& remoteNode,
- const std::vector<SharedHandle<DHTNode> >& closestKNodes,
- const std::vector<SharedHandle<Peer> >& peers,
+ (const std::shared_ptr<DHTNode>& remoteNode,
+ const std::vector<std::shared_ptr<DHTNode> >& closestKNodes,
+ const std::vector<std::shared_ptr<Peer> >& peers,
const std::string& token,
const std::string& transactionID);
- SharedHandle<DHTResponseMessage>
+ std::shared_ptr<DHTResponseMessage>
createGetPeersReplyMessage
- (const SharedHandle<DHTNode>& remoteNode,
+ (const std::shared_ptr<DHTNode>& remoteNode,
const Dict* dict,
const std::string& transactionID);
- virtual SharedHandle<DHTQueryMessage>
- createAnnouncePeerMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTQueryMessage>
+ createAnnouncePeerMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
uint16_t tcpPort,
const std::string& token,
const std::string& transactionID = A2STR::NIL);
- virtual SharedHandle<DHTResponseMessage>
- createAnnouncePeerReplyMessage(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTResponseMessage>
+ createAnnouncePeerReplyMessage(const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID);
- virtual SharedHandle<DHTMessage>
+ virtual std::shared_ptr<DHTMessage>
createUnknownMessage(const unsigned char* data, size_t length,
const std::string& ipaddr, uint16_t port);
@@ -162,7 +162,7 @@ public:
void setTokenTracker(DHTTokenTracker* tokenTracker);
- void setLocalNode(const SharedHandle<DHTNode>& localNode);
+ void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
};
} // namespace aria2
diff --git a/src/DHTMessageReceiver.cc b/src/DHTMessageReceiver.cc
index 36e40639..ec6ad904 100644
--- a/src/DHTMessageReceiver.cc
+++ b/src/DHTMessageReceiver.cc
@@ -57,19 +57,19 @@
namespace aria2 {
DHTMessageReceiver::DHTMessageReceiver
-(const SharedHandle<DHTMessageTracker>& tracker)
+(const std::shared_ptr<DHTMessageTracker>& tracker)
: tracker_(tracker)
{}
DHTMessageReceiver::~DHTMessageReceiver() {}
-SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage
+std::shared_ptr<DHTMessage> DHTMessageReceiver::receiveMessage
(const std::string& remoteAddr, uint16_t remotePort, unsigned char *data,
size_t length)
{
try {
bool isReply = false;
- SharedHandle<ValueBase> decoded = bencode2::decode(data, length);
+ std::shared_ptr<ValueBase> decoded = bencode2::decode(data, length);
const Dict* dict = downcast<Dict>(decoded);
if(dict) {
const String* y = downcast<String>(dict->get(DHTMessage::Y));
@@ -89,8 +89,8 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage
return handleUnknownMessage(data, length, remoteAddr, remotePort);
}
if(isReply) {
- std::pair<SharedHandle<DHTResponseMessage>,
- SharedHandle<DHTMessageCallback> > p =
+ std::pair<std::shared_ptr<DHTResponseMessage>,
+ std::shared_ptr<DHTMessageCallback> > p =
tracker_->messageArrived(dict, remoteAddr, remotePort);
if(!p.first) {
// timeout or malicious? message
@@ -102,7 +102,7 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage
}
return p.first;
} else {
- SharedHandle<DHTQueryMessage> message =
+ std::shared_ptr<DHTQueryMessage> message =
factory_->createQueryMessage(dict, remoteAddr, remotePort);
if(*message->getLocalNode() == *message->getRemoteNode()) {
// drop message from localnode
@@ -119,7 +119,7 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage
}
void DHTMessageReceiver::onMessageReceived
-(const SharedHandle<DHTMessage>& message)
+(const std::shared_ptr<DHTMessage>& message)
{
A2_LOG_INFO(fmt("Message received: %s", message->toString().c_str()));
message->validate();
@@ -134,29 +134,29 @@ void DHTMessageReceiver::handleTimeout()
tracker_->handleTimeout();
}
-SharedHandle<DHTMessage>
+std::shared_ptr<DHTMessage>
DHTMessageReceiver::handleUnknownMessage(const unsigned char* data,
size_t length,
const std::string& remoteAddr,
uint16_t remotePort)
{
- SharedHandle<DHTMessage> m =
+ std::shared_ptr<DHTMessage> m =
factory_->createUnknownMessage(data, length, remoteAddr, remotePort);
A2_LOG_INFO(fmt("Message received: %s", m->toString().c_str()));
return m;
}
-void DHTMessageReceiver::setConnection(const SharedHandle<DHTConnection>& connection)
+void DHTMessageReceiver::setConnection(const std::shared_ptr<DHTConnection>& connection)
{
connection_ = connection;
}
-void DHTMessageReceiver::setMessageFactory(const SharedHandle<DHTMessageFactory>& factory)
+void DHTMessageReceiver::setMessageFactory(const std::shared_ptr<DHTMessageFactory>& factory)
{
factory_ = factory;
}
-void DHTMessageReceiver::setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable)
+void DHTMessageReceiver::setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable)
{
routingTable_ = routingTable;
}
diff --git a/src/DHTMessageReceiver.h b/src/DHTMessageReceiver.h
index f8ed5018..6b008aef 100644
--- a/src/DHTMessageReceiver.h
+++ b/src/DHTMessageReceiver.h
@@ -38,8 +38,7 @@
#include "common.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -51,45 +50,45 @@ class DHTRoutingTable;
class DHTMessageReceiver {
private:
- SharedHandle<DHTMessageTracker> tracker_;
+ std::shared_ptr<DHTMessageTracker> tracker_;
- SharedHandle<DHTConnection> connection_;
+ std::shared_ptr<DHTConnection> connection_;
- SharedHandle<DHTMessageFactory> factory_;
+ std::shared_ptr<DHTMessageFactory> factory_;
- SharedHandle<DHTRoutingTable> routingTable_;
+ std::shared_ptr<DHTRoutingTable> routingTable_;
- SharedHandle<DHTMessage>
+ std::shared_ptr<DHTMessage>
handleUnknownMessage(const unsigned char* data, size_t length,
const std::string& remoteAddr, uint16_t remotePort);
- void onMessageReceived(const SharedHandle<DHTMessage>& message);
+ void onMessageReceived(const std::shared_ptr<DHTMessage>& message);
public:
- DHTMessageReceiver(const SharedHandle<DHTMessageTracker>& tracker);
+ DHTMessageReceiver(const std::shared_ptr<DHTMessageTracker>& tracker);
~DHTMessageReceiver();
- SharedHandle<DHTMessage> receiveMessage
+ std::shared_ptr<DHTMessage> receiveMessage
(const std::string& remoteAddr, uint16_t remotePort, unsigned char *data,
size_t length);
void handleTimeout();
- const SharedHandle<DHTConnection>& getConnection() const
+ const std::shared_ptr<DHTConnection>& getConnection() const
{
return connection_;
}
- const SharedHandle<DHTMessageTracker>& getMessageTracker() const
+ const std::shared_ptr<DHTMessageTracker>& getMessageTracker() const
{
return tracker_;
}
- void setConnection(const SharedHandle<DHTConnection>& connection);
+ void setConnection(const std::shared_ptr<DHTConnection>& connection);
- void setMessageFactory(const SharedHandle<DHTMessageFactory>& factory);
+ void setMessageFactory(const std::shared_ptr<DHTMessageFactory>& factory);
- void setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable);
+ void setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable);
};
} // namespace aria2
diff --git a/src/DHTMessageTracker.cc b/src/DHTMessageTracker.cc
index 06baf50e..261acdc3 100644
--- a/src/DHTMessageTracker.cc
+++ b/src/DHTMessageTracker.cc
@@ -55,13 +55,13 @@ DHTMessageTracker::DHTMessageTracker() {}
DHTMessageTracker::~DHTMessageTracker() {}
-void DHTMessageTracker::addMessage(const SharedHandle<DHTMessage>& message, time_t timeout, const SharedHandle<DHTMessageCallback>& callback)
+void DHTMessageTracker::addMessage(const std::shared_ptr<DHTMessage>& message, time_t timeout, const std::shared_ptr<DHTMessageCallback>& callback)
{
- SharedHandle<DHTMessageTrackerEntry> e(new DHTMessageTrackerEntry(message, timeout, callback));
+ std::shared_ptr<DHTMessageTrackerEntry> e(new DHTMessageTrackerEntry(message, timeout, callback));
entries_.push_back(e);
}
-std::pair<SharedHandle<DHTResponseMessage>, SharedHandle<DHTMessageCallback> >
+std::pair<std::shared_ptr<DHTResponseMessage>, std::shared_ptr<DHTMessageCallback> >
DHTMessageTracker::messageArrived
(const Dict* dict, const std::string& ipaddr, uint16_t port)
{
@@ -73,15 +73,15 @@ DHTMessageTracker::messageArrived
A2_LOG_DEBUG(fmt("Searching tracker entry for TransactionID=%s, Remote=%s:%u",
util::toHex(tid->s()).c_str(),
ipaddr.c_str(), port));
- for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::iterator i =
+ for(std::deque<std::shared_ptr<DHTMessageTrackerEntry> >::iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
if((*i)->match(tid->s(), ipaddr, port)) {
- SharedHandle<DHTMessageTrackerEntry> entry = *i;
+ std::shared_ptr<DHTMessageTrackerEntry> entry = *i;
entries_.erase(i);
A2_LOG_DEBUG("Tracker entry found.");
- SharedHandle<DHTNode> targetNode = entry->getTargetNode();
+ std::shared_ptr<DHTNode> targetNode = entry->getTargetNode();
try {
- SharedHandle<DHTResponseMessage> message =
+ std::shared_ptr<DHTResponseMessage> message =
factory_->createResponseMessage(entry->getMessageType(), dict,
targetNode->getIPAddress(),
targetNode->getPort());
@@ -89,7 +89,7 @@ DHTMessageTracker::messageArrived
int64_t rtt = entry->getElapsedMillis();
A2_LOG_DEBUG(fmt("RTT is %" PRId64 "", rtt));
message->getRemoteNode()->updateRTT(rtt);
- SharedHandle<DHTMessageCallback> callback = entry->getCallback();
+ std::shared_ptr<DHTMessageCallback> callback = entry->getCallback();
if(!(*targetNode == *message->getRemoteNode())) {
// Node ID has changed. Drop previous node ID from
// DHTRoutingTable
@@ -108,15 +108,15 @@ DHTMessageTracker::messageArrived
}
}
A2_LOG_DEBUG("Tracker entry not found.");
- return std::pair<SharedHandle<DHTResponseMessage>,
- SharedHandle<DHTMessageCallback> >();
+ return std::pair<std::shared_ptr<DHTResponseMessage>,
+ std::shared_ptr<DHTMessageCallback> >();
}
void DHTMessageTracker::handleTimeoutEntry
-(const SharedHandle<DHTMessageTrackerEntry>& entry)
+(const std::shared_ptr<DHTMessageTrackerEntry>& entry)
{
try {
- SharedHandle<DHTNode> node = entry->getTargetNode();
+ std::shared_ptr<DHTNode> node = entry->getTargetNode();
A2_LOG_DEBUG(fmt("Message timeout: To:%s:%u",
node->getIPAddress().c_str(), node->getPort()));
node->updateRTT(entry->getElapsedMillis());
@@ -126,7 +126,7 @@ void DHTMessageTracker::handleTimeoutEntry
node->getIPAddress().c_str(), node->getPort()));
routingTable_->dropNode(node);
}
- SharedHandle<DHTMessageCallback> callback = entry->getCallback();
+ std::shared_ptr<DHTMessageCallback> callback = entry->getCallback();
if(callback) {
callback->onTimeout(node);
}
@@ -140,7 +140,7 @@ struct HandleTimeout {
HandleTimeout(DHTMessageTracker* tracker)
: tracker(tracker)
{}
- bool operator()(const SharedHandle<DHTMessageTrackerEntry>& ent) const
+ bool operator()(const std::shared_ptr<DHTMessageTrackerEntry>& ent) const
{
if(ent->isTimeout()) {
tracker->handleTimeoutEntry(ent);
@@ -160,10 +160,10 @@ void DHTMessageTracker::handleTimeout()
entries_.end());
}
-SharedHandle<DHTMessageTrackerEntry>
-DHTMessageTracker::getEntryFor(const SharedHandle<DHTMessage>& message) const
+std::shared_ptr<DHTMessageTrackerEntry>
+DHTMessageTracker::getEntryFor(const std::shared_ptr<DHTMessage>& message) const
{
- for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::const_iterator i =
+ for(std::deque<std::shared_ptr<DHTMessageTrackerEntry> >::const_iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
if((*i)->match(message->getTransactionID(),
message->getRemoteNode()->getIPAddress(),
@@ -171,7 +171,7 @@ DHTMessageTracker::getEntryFor(const SharedHandle<DHTMessage>& message) const
return *i;
}
}
- return SharedHandle<DHTMessageTrackerEntry>();
+ return std::shared_ptr<DHTMessageTrackerEntry>();
}
size_t DHTMessageTracker::countEntry() const
@@ -180,13 +180,13 @@ size_t DHTMessageTracker::countEntry() const
}
void DHTMessageTracker::setRoutingTable
-(const SharedHandle<DHTRoutingTable>& routingTable)
+(const std::shared_ptr<DHTRoutingTable>& routingTable)
{
routingTable_ = routingTable;
}
void DHTMessageTracker::setMessageFactory
-(const SharedHandle<DHTMessageFactory>& factory)
+(const std::shared_ptr<DHTMessageFactory>& factory)
{
factory_ = factory;
}
diff --git a/src/DHTMessageTracker.h b/src/DHTMessageTracker.h
index 39aa5d8f..5686ba4f 100644
--- a/src/DHTMessageTracker.h
+++ b/src/DHTMessageTracker.h
@@ -39,8 +39,8 @@
#include <utility>
#include <deque>
+#include <memory>
-#include "SharedHandle.h"
#include "a2time.h"
#include "ValueBase.h"
@@ -55,38 +55,38 @@ class DHTMessageTrackerEntry;
class DHTMessageTracker {
private:
- std::deque<SharedHandle<DHTMessageTrackerEntry> > entries_;
+ std::deque<std::shared_ptr<DHTMessageTrackerEntry> > entries_;
- SharedHandle<DHTRoutingTable> routingTable_;
+ std::shared_ptr<DHTRoutingTable> routingTable_;
- SharedHandle<DHTMessageFactory> factory_;
+ std::shared_ptr<DHTMessageFactory> factory_;
public:
DHTMessageTracker();
~DHTMessageTracker();
- void addMessage(const SharedHandle<DHTMessage>& message,
+ void addMessage(const std::shared_ptr<DHTMessage>& message,
time_t timeout,
- const SharedHandle<DHTMessageCallback>& callback =
- SharedHandle<DHTMessageCallback>());
+ const std::shared_ptr<DHTMessageCallback>& callback =
+ std::shared_ptr<DHTMessageCallback>());
- std::pair<SharedHandle<DHTResponseMessage>, SharedHandle<DHTMessageCallback> >
+ std::pair<std::shared_ptr<DHTResponseMessage>, std::shared_ptr<DHTMessageCallback> >
messageArrived(const Dict* dict,
const std::string& ipaddr, uint16_t port);
void handleTimeout();
// Made public so that unnamed functor can access this
- void handleTimeoutEntry(const SharedHandle<DHTMessageTrackerEntry>& entry);
+ void handleTimeoutEntry(const std::shared_ptr<DHTMessageTrackerEntry>& entry);
- SharedHandle<DHTMessageTrackerEntry> getEntryFor
- (const SharedHandle<DHTMessage>& message) const;
+ std::shared_ptr<DHTMessageTrackerEntry> getEntryFor
+ (const std::shared_ptr<DHTMessage>& message) const;
size_t countEntry() const;
- void setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable);
+ void setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable);
- void setMessageFactory(const SharedHandle<DHTMessageFactory>& factory);
+ void setMessageFactory(const std::shared_ptr<DHTMessageFactory>& factory);
};
} // namespace aria2
diff --git a/src/DHTMessageTrackerEntry.cc b/src/DHTMessageTrackerEntry.cc
index 59ad4322..1b36ab6d 100644
--- a/src/DHTMessageTrackerEntry.cc
+++ b/src/DHTMessageTrackerEntry.cc
@@ -42,9 +42,9 @@
namespace aria2 {
-DHTMessageTrackerEntry::DHTMessageTrackerEntry(const SharedHandle<DHTMessage>& sentMessage,
+DHTMessageTrackerEntry::DHTMessageTrackerEntry(const std::shared_ptr<DHTMessage>& sentMessage,
time_t timeout,
- const SharedHandle<DHTMessageCallback>& callback):
+ const std::shared_ptr<DHTMessageCallback>& callback):
targetNode_(sentMessage->getRemoteNode()),
transactionID_(sentMessage->getTransactionID()),
messageType_(sentMessage->getMessageType()),
diff --git a/src/DHTMessageTrackerEntry.h b/src/DHTMessageTrackerEntry.h
index 7674e186..48dcef16 100644
--- a/src/DHTMessageTrackerEntry.h
+++ b/src/DHTMessageTrackerEntry.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "DHTConstants.h"
#include "TimerA2.h"
@@ -51,22 +51,22 @@ class DHTMessageCallback;
class DHTMessageTrackerEntry {
private:
- SharedHandle<DHTNode> targetNode_;
+ std::shared_ptr<DHTNode> targetNode_;
std::string transactionID_;
std::string messageType_;
- SharedHandle<DHTMessageCallback> callback_;
+ std::shared_ptr<DHTMessageCallback> callback_;
Timer dispatchedTime_;
time_t timeout_;
public:
- DHTMessageTrackerEntry(const SharedHandle<DHTMessage>& sentMessage,
+ DHTMessageTrackerEntry(const std::shared_ptr<DHTMessage>& sentMessage,
time_t timeout,
- const SharedHandle<DHTMessageCallback>& callback =
- SharedHandle<DHTMessageCallback>());
+ const std::shared_ptr<DHTMessageCallback>& callback =
+ std::shared_ptr<DHTMessageCallback>());
~DHTMessageTrackerEntry();
@@ -76,7 +76,7 @@ public:
bool match(const std::string& transactionID, const std::string& ipaddr, uint16_t port) const;
- const SharedHandle<DHTNode>& getTargetNode() const
+ const std::shared_ptr<DHTNode>& getTargetNode() const
{
return targetNode_;
}
@@ -86,7 +86,7 @@ public:
return messageType_;
}
- const SharedHandle<DHTMessageCallback>& getCallback() const
+ const std::shared_ptr<DHTMessageCallback>& getCallback() const
{
return callback_;
}
diff --git a/src/DHTNode.h b/src/DHTNode.h
index 303b23c8..619ecc0b 100644
--- a/src/DHTNode.h
+++ b/src/DHTNode.h
@@ -39,7 +39,6 @@
#include <string>
-#include "SharedHandle.h"
#include "DHTConstants.h"
#include "TimerA2.h"
diff --git a/src/DHTNodeLookupEntry.cc b/src/DHTNodeLookupEntry.cc
index 0026e4bf..82eda5da 100644
--- a/src/DHTNodeLookupEntry.cc
+++ b/src/DHTNodeLookupEntry.cc
@@ -37,7 +37,7 @@
namespace aria2 {
-DHTNodeLookupEntry::DHTNodeLookupEntry(const SharedHandle<DHTNode>& node):
+DHTNodeLookupEntry::DHTNodeLookupEntry(const std::shared_ptr<DHTNode>& node):
node(node), used(false) {}
DHTNodeLookupEntry::DHTNodeLookupEntry():
diff --git a/src/DHTNodeLookupEntry.h b/src/DHTNodeLookupEntry.h
index 6a6016ae..6475381b 100644
--- a/src/DHTNodeLookupEntry.h
+++ b/src/DHTNodeLookupEntry.h
@@ -36,18 +36,19 @@
#define D_DHT_NODE_LOOKUP_ENTRY_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
class DHTNode;
struct DHTNodeLookupEntry {
- SharedHandle<DHTNode> node;
+ std::shared_ptr<DHTNode> node;
bool used;
- DHTNodeLookupEntry(const SharedHandle<DHTNode>& node);
+ DHTNodeLookupEntry(const std::shared_ptr<DHTNode>& node);
DHTNodeLookupEntry();
diff --git a/src/DHTNodeLookupTask.cc b/src/DHTNodeLookupTask.cc
index 46c56c35..c116d403 100644
--- a/src/DHTNodeLookupTask.cc
+++ b/src/DHTNodeLookupTask.cc
@@ -50,23 +50,23 @@ DHTNodeLookupTask::DHTNodeLookupTask(const unsigned char* targetNodeID):
void
DHTNodeLookupTask::getNodesFromMessage
-(std::vector<SharedHandle<DHTNode> >& nodes,
+(std::vector<std::shared_ptr<DHTNode> >& nodes,
const DHTFindNodeReplyMessage* message)
{
- const std::vector<SharedHandle<DHTNode> >& knodes =
+ const std::vector<std::shared_ptr<DHTNode> >& knodes =
message->getClosestKNodes();
nodes.insert(nodes.end(), knodes.begin(), knodes.end());
}
-SharedHandle<DHTMessage>
-DHTNodeLookupTask::createMessage(const SharedHandle<DHTNode>& remoteNode)
+std::shared_ptr<DHTMessage>
+DHTNodeLookupTask::createMessage(const std::shared_ptr<DHTNode>& remoteNode)
{
return getMessageFactory()->createFindNodeMessage(remoteNode, getTargetID());
}
-SharedHandle<DHTMessageCallback> DHTNodeLookupTask::createCallback()
+std::shared_ptr<DHTMessageCallback> DHTNodeLookupTask::createCallback()
{
- return SharedHandle<DHTNodeLookupTaskCallback>
+ return std::shared_ptr<DHTNodeLookupTaskCallback>
(new DHTNodeLookupTaskCallback(this));
}
diff --git a/src/DHTNodeLookupTask.h b/src/DHTNodeLookupTask.h
index b60b2715..f1fd11a8 100644
--- a/src/DHTNodeLookupTask.h
+++ b/src/DHTNodeLookupTask.h
@@ -47,13 +47,13 @@ public:
DHTNodeLookupTask(const unsigned char* targetNodeID);
virtual void getNodesFromMessage
- (std::vector<SharedHandle<DHTNode> >& nodes,
+ (std::vector<std::shared_ptr<DHTNode> >& nodes,
const DHTFindNodeReplyMessage* message);
- virtual SharedHandle<DHTMessage> createMessage
- (const SharedHandle<DHTNode>& remoteNode);
+ virtual std::shared_ptr<DHTMessage> createMessage
+ (const std::shared_ptr<DHTNode>& remoteNode);
- virtual SharedHandle<DHTMessageCallback> createCallback();
+ virtual std::shared_ptr<DHTMessageCallback> createCallback();
};
} // namespace aria2
diff --git a/src/DHTNodeLookupTaskCallback.cc b/src/DHTNodeLookupTaskCallback.cc
index 59b60d6a..1a07a8c7 100644
--- a/src/DHTNodeLookupTaskCallback.cc
+++ b/src/DHTNodeLookupTaskCallback.cc
@@ -70,7 +70,7 @@ void DHTNodeLookupTaskCallback::visit(const DHTPingReplyMessage* message)
}
void DHTNodeLookupTaskCallback::onTimeout
-(const SharedHandle<DHTNode>& remoteNode)
+(const std::shared_ptr<DHTNode>& remoteNode)
{
task_->onTimeout(remoteNode);
}
diff --git a/src/DHTNodeLookupTaskCallback.h b/src/DHTNodeLookupTaskCallback.h
index 33d3a3d1..441ddce7 100644
--- a/src/DHTNodeLookupTaskCallback.h
+++ b/src/DHTNodeLookupTaskCallback.h
@@ -55,7 +55,7 @@ public:
virtual void visit(const DHTPingReplyMessage* message);
- virtual void onTimeout(const SharedHandle<DHTNode>& remoteNode);
+ virtual void onTimeout(const std::shared_ptr<DHTNode>& remoteNode);
};
} // namespace aria2
diff --git a/src/DHTPeerAnnounceCommand.cc b/src/DHTPeerAnnounceCommand.cc
index 9ab386cf..97945c01 100644
--- a/src/DHTPeerAnnounceCommand.cc
+++ b/src/DHTPeerAnnounceCommand.cc
@@ -68,7 +68,7 @@ void DHTPeerAnnounceCommand::process()
}
void DHTPeerAnnounceCommand::setPeerAnnounceStorage
-(const SharedHandle<DHTPeerAnnounceStorage>& storage)
+(const std::shared_ptr<DHTPeerAnnounceStorage>& storage)
{
peerAnnounceStorage_ = storage;
}
diff --git a/src/DHTPeerAnnounceCommand.h b/src/DHTPeerAnnounceCommand.h
index 4e313cf5..a704b8f8 100644
--- a/src/DHTPeerAnnounceCommand.h
+++ b/src/DHTPeerAnnounceCommand.h
@@ -36,7 +36,8 @@
#define D_DHT_PEER_ANNOUNCE_COMMAND_H
#include "TimeBasedCommand.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -44,7 +45,7 @@ class DHTPeerAnnounceStorage;
class DHTPeerAnnounceCommand:public TimeBasedCommand {
private:
- SharedHandle<DHTPeerAnnounceStorage> peerAnnounceStorage_;
+ std::shared_ptr<DHTPeerAnnounceStorage> peerAnnounceStorage_;
public:
DHTPeerAnnounceCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
@@ -54,7 +55,7 @@ public:
virtual void process();
- void setPeerAnnounceStorage(const SharedHandle<DHTPeerAnnounceStorage>& storage);
+ void setPeerAnnounceStorage(const std::shared_ptr<DHTPeerAnnounceStorage>& storage);
};
} // namespace aria2
diff --git a/src/DHTPeerAnnounceEntry.cc b/src/DHTPeerAnnounceEntry.cc
index 3fe0a470..bec96191 100644
--- a/src/DHTPeerAnnounceEntry.cc
+++ b/src/DHTPeerAnnounceEntry.cc
@@ -96,11 +96,11 @@ bool DHTPeerAnnounceEntry::empty() const
}
void DHTPeerAnnounceEntry::getPeers
-(std::vector<SharedHandle<Peer> >& peers) const
+(std::vector<std::shared_ptr<Peer> >& peers) const
{
for(std::vector<PeerAddrEntry>::const_iterator i = peerAddrEntries_.begin(),
eoi = peerAddrEntries_.end(); i != eoi; ++i) {
- SharedHandle<Peer> peer(new Peer((*i).getIPAddress(), (*i).getPort()));
+ std::shared_ptr<Peer> peer(new Peer((*i).getIPAddress(), (*i).getPort()));
peers.push_back(peer);
}
}
diff --git a/src/DHTPeerAnnounceEntry.h b/src/DHTPeerAnnounceEntry.h
index 427720ab..b1d29b8c 100644
--- a/src/DHTPeerAnnounceEntry.h
+++ b/src/DHTPeerAnnounceEntry.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "DHTConstants.h"
#include "PeerAddrEntry.h"
#include "TimerA2.h"
@@ -87,7 +87,7 @@ public:
return infoHash_;
}
- void getPeers(std::vector<SharedHandle<Peer> >& peers) const;
+ void getPeers(std::vector<std::shared_ptr<Peer> >& peers) const;
};
diff --git a/src/DHTPeerAnnounceStorage.cc b/src/DHTPeerAnnounceStorage.cc
index 3a7cee9c..11f38a80 100644
--- a/src/DHTPeerAnnounceStorage.cc
+++ b/src/DHTPeerAnnounceStorage.cc
@@ -57,16 +57,16 @@ DHTPeerAnnounceStorage::DHTPeerAnnounceStorage() {}
DHTPeerAnnounceStorage::~DHTPeerAnnounceStorage() {}
bool DHTPeerAnnounceStorage::InfoHashLess::operator()
- (const SharedHandle<DHTPeerAnnounceEntry>& lhs,
- const SharedHandle<DHTPeerAnnounceEntry>& rhs)
+ (const std::shared_ptr<DHTPeerAnnounceEntry>& lhs,
+ const std::shared_ptr<DHTPeerAnnounceEntry>& rhs)
{
return memcmp(lhs->getInfoHash(), rhs->getInfoHash(), DHT_ID_LENGTH) < 0;
}
-SharedHandle<DHTPeerAnnounceEntry>
+std::shared_ptr<DHTPeerAnnounceEntry>
DHTPeerAnnounceStorage::getPeerAnnounceEntry(const unsigned char* infoHash)
{
- SharedHandle<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
+ std::shared_ptr<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
DHTPeerAnnounceEntrySet::iterator i = entries_.lower_bound(entry);
@@ -91,15 +91,15 @@ DHTPeerAnnounceStorage::addPeerAnnounce(const unsigned char* infoHash,
bool DHTPeerAnnounceStorage::contains(const unsigned char* infoHash) const
{
- SharedHandle<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
+ std::shared_ptr<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
return
std::binary_search(entries_.begin(), entries_.end(), entry, InfoHashLess());
}
-void DHTPeerAnnounceStorage::getPeers(std::vector<SharedHandle<Peer> >& peers,
+void DHTPeerAnnounceStorage::getPeers(std::vector<std::shared_ptr<Peer> >& peers,
const unsigned char* infoHash)
{
- SharedHandle<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
+ std::shared_ptr<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
DHTPeerAnnounceEntrySet::iterator i = entries_.find(entry);
if(i != entries_.end()) {
@@ -111,7 +111,7 @@ namespace {
class RemoveStalePeerAddrEntry
{
public:
- void operator()(const SharedHandle<DHTPeerAnnounceEntry>& e)
+ void operator()(const std::shared_ptr<DHTPeerAnnounceEntry>& e)
{
e->removeStalePeerAddrEntry(DHT_PEER_ANNOUNCE_PURGE_INTERVAL);
}
@@ -143,7 +143,7 @@ void DHTPeerAnnounceStorage::announcePeer()
if((*i)->getLastUpdated().
difference(global::wallclock()) >= DHT_PEER_ANNOUNCE_INTERVAL) {
(*i)->notifyUpdate();
- SharedHandle<DHTTask> task =
+ std::shared_ptr<DHTTask> task =
taskFactory_->createPeerAnnounceTask((*i)->getInfoHash());
taskQueue_->addPeriodicTask2(task);
A2_LOG_DEBUG
@@ -153,12 +153,12 @@ void DHTPeerAnnounceStorage::announcePeer()
}
}
-void DHTPeerAnnounceStorage::setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue)
+void DHTPeerAnnounceStorage::setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue)
{
taskQueue_ = taskQueue;
}
-void DHTPeerAnnounceStorage::setTaskFactory(const SharedHandle<DHTTaskFactory>& taskFactory)
+void DHTPeerAnnounceStorage::setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory)
{
taskFactory_ = taskFactory;
}
diff --git a/src/DHTPeerAnnounceStorage.h b/src/DHTPeerAnnounceStorage.h
index e32ab7f2..a0f2dd22 100644
--- a/src/DHTPeerAnnounceStorage.h
+++ b/src/DHTPeerAnnounceStorage.h
@@ -40,8 +40,7 @@
#include <set>
#include <vector>
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -54,18 +53,18 @@ class DHTPeerAnnounceStorage {
private:
class InfoHashLess {
public:
- bool operator()(const SharedHandle<DHTPeerAnnounceEntry>& lhs,
- const SharedHandle<DHTPeerAnnounceEntry>& rhs);
+ bool operator()(const std::shared_ptr<DHTPeerAnnounceEntry>& lhs,
+ const std::shared_ptr<DHTPeerAnnounceEntry>& rhs);
};
- typedef std::set<SharedHandle<DHTPeerAnnounceEntry>, InfoHashLess>
+ typedef std::set<std::shared_ptr<DHTPeerAnnounceEntry>, InfoHashLess>
DHTPeerAnnounceEntrySet;
DHTPeerAnnounceEntrySet entries_;
- SharedHandle<DHTPeerAnnounceEntry> getPeerAnnounceEntry(const unsigned char* infoHash);
+ std::shared_ptr<DHTPeerAnnounceEntry> getPeerAnnounceEntry(const unsigned char* infoHash);
- SharedHandle<DHTTaskQueue> taskQueue_;
+ std::shared_ptr<DHTTaskQueue> taskQueue_;
- SharedHandle<DHTTaskFactory> taskFactory_;
+ std::shared_ptr<DHTTaskFactory> taskFactory_;
public:
DHTPeerAnnounceStorage();
@@ -76,7 +75,7 @@ public:
bool contains(const unsigned char* infoHash) const;
- void getPeers(std::vector<SharedHandle<Peer> >& peers,
+ void getPeers(std::vector<std::shared_ptr<Peer> >& peers,
const unsigned char* infoHash);
// drop peer announce entry which is not updated in the past
@@ -88,9 +87,9 @@ public:
// are excluded from announce.
void announcePeer();
- void setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue);
+ void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
- void setTaskFactory(const SharedHandle<DHTTaskFactory>& taskFactory);
+ void setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory);
};
} // namespace aria2
diff --git a/src/DHTPeerLookupTask.cc b/src/DHTPeerLookupTask.cc
index 3c0b9eaa..9a9711d4 100644
--- a/src/DHTPeerLookupTask.cc
+++ b/src/DHTPeerLookupTask.cc
@@ -53,7 +53,7 @@
namespace aria2 {
DHTPeerLookupTask::DHTPeerLookupTask
-(const SharedHandle<DownloadContext>& downloadContext,
+(const std::shared_ptr<DownloadContext>& downloadContext,
uint16_t tcpPort)
: DHTAbstractNodeLookupTask<DHTGetPeersReplyMessage>
(bittorrent::getInfoHash(downloadContext)),
@@ -62,10 +62,10 @@ DHTPeerLookupTask::DHTPeerLookupTask
void
DHTPeerLookupTask::getNodesFromMessage
-(std::vector<SharedHandle<DHTNode> >& nodes,
+(std::vector<std::shared_ptr<DHTNode> >& nodes,
const DHTGetPeersReplyMessage* message)
{
- const std::vector<SharedHandle<DHTNode> >& knodes =
+ const std::vector<std::shared_ptr<DHTNode> >& knodes =
message->getClosestKNodes();
nodes.insert(nodes.end(), knodes.begin(), knodes.end());
}
@@ -73,7 +73,7 @@ DHTPeerLookupTask::getNodesFromMessage
void DHTPeerLookupTask::onReceivedInternal
(const DHTGetPeersReplyMessage* message)
{
- SharedHandle<DHTNode> remoteNode = message->getRemoteNode();
+ std::shared_ptr<DHTNode> remoteNode = message->getRemoteNode();
tokenStorage_[util::toHex(remoteNode->getID(), DHT_ID_LENGTH)] =
message->getToken();
peerStorage_->addPeer(message->getValues());
@@ -81,15 +81,15 @@ void DHTPeerLookupTask::onReceivedInternal
static_cast<unsigned long>(message->getValues().size())));
}
-SharedHandle<DHTMessage> DHTPeerLookupTask::createMessage
-(const SharedHandle<DHTNode>& remoteNode)
+std::shared_ptr<DHTMessage> DHTPeerLookupTask::createMessage
+(const std::shared_ptr<DHTNode>& remoteNode)
{
return getMessageFactory()->createGetPeersMessage(remoteNode, getTargetID());
}
-SharedHandle<DHTMessageCallback> DHTPeerLookupTask::createCallback()
+std::shared_ptr<DHTMessageCallback> DHTPeerLookupTask::createCallback()
{
- return SharedHandle<DHTPeerLookupTaskCallback>
+ return std::shared_ptr<DHTPeerLookupTaskCallback>
(new DHTPeerLookupTaskCallback(this));
}
@@ -99,20 +99,20 @@ void DHTPeerLookupTask::onFinish()
util::toHex(getTargetID(), DHT_ID_LENGTH).c_str()));
// send announce_peer message to K closest nodes
size_t num = DHTBucket::K;
- for(std::deque<SharedHandle<DHTNodeLookupEntry> >::const_iterator i =
+ for(std::deque<std::shared_ptr<DHTNodeLookupEntry> >::const_iterator i =
getEntries().begin(), eoi = getEntries().end();
i != eoi && num > 0; ++i) {
if(!(*i)->used) {
continue;
}
- const SharedHandle<DHTNode>& node = (*i)->node;
+ const std::shared_ptr<DHTNode>& node = (*i)->node;
std::string idHex = util::toHex(node->getID(), DHT_ID_LENGTH);
std::string token = tokenStorage_[idHex];
if(token.empty()) {
A2_LOG_DEBUG(fmt("Token is empty for ID:%s", idHex.c_str()));
continue;
}
- SharedHandle<DHTMessage> m =
+ std::shared_ptr<DHTMessage> m =
getMessageFactory()->createAnnouncePeerMessage
(node,
getTargetID(), // this is infoHash
@@ -123,7 +123,7 @@ void DHTPeerLookupTask::onFinish()
}
}
-void DHTPeerLookupTask::setPeerStorage(const SharedHandle<PeerStorage>& ps)
+void DHTPeerLookupTask::setPeerStorage(const std::shared_ptr<PeerStorage>& ps)
{
peerStorage_ = ps;
}
diff --git a/src/DHTPeerLookupTask.h b/src/DHTPeerLookupTask.h
index 1f444878..7b269dff 100644
--- a/src/DHTPeerLookupTask.h
+++ b/src/DHTPeerLookupTask.h
@@ -50,27 +50,27 @@ class DHTPeerLookupTask:
private:
std::map<std::string, std::string> tokenStorage_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
uint16_t tcpPort_;
public:
DHTPeerLookupTask
- (const SharedHandle<DownloadContext>& downloadContext,
+ (const std::shared_ptr<DownloadContext>& downloadContext,
uint16_t tcpPort);
virtual void getNodesFromMessage
- (std::vector<SharedHandle<DHTNode> >& nodes,
+ (std::vector<std::shared_ptr<DHTNode> >& nodes,
const DHTGetPeersReplyMessage* message);
virtual void onReceivedInternal(const DHTGetPeersReplyMessage* message);
- virtual SharedHandle<DHTMessage> createMessage
- (const SharedHandle<DHTNode>& remoteNode);
+ virtual std::shared_ptr<DHTMessage> createMessage
+ (const std::shared_ptr<DHTNode>& remoteNode);
- virtual SharedHandle<DHTMessageCallback> createCallback();
+ virtual std::shared_ptr<DHTMessageCallback> createCallback();
virtual void onFinish();
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
};
} // namespace aria2
diff --git a/src/DHTPeerLookupTaskCallback.cc b/src/DHTPeerLookupTaskCallback.cc
index dc60a45e..de0fa875 100644
--- a/src/DHTPeerLookupTaskCallback.cc
+++ b/src/DHTPeerLookupTaskCallback.cc
@@ -67,7 +67,7 @@ void DHTPeerLookupTaskCallback::visit(const DHTPingReplyMessage* message)
}
void DHTPeerLookupTaskCallback::onTimeout
-(const SharedHandle<DHTNode>& remoteNode)
+(const std::shared_ptr<DHTNode>& remoteNode)
{
task_->onTimeout(remoteNode);
}
diff --git a/src/DHTPeerLookupTaskCallback.h b/src/DHTPeerLookupTaskCallback.h
index efdc1f14..78cdc924 100644
--- a/src/DHTPeerLookupTaskCallback.h
+++ b/src/DHTPeerLookupTaskCallback.h
@@ -55,7 +55,7 @@ public:
virtual void visit(const DHTPingReplyMessage* message);
- virtual void onTimeout(const SharedHandle<DHTNode>& remoteNode);
+ virtual void onTimeout(const std::shared_ptr<DHTNode>& remoteNode);
};
} // namespace aria2
diff --git a/src/DHTPingMessage.cc b/src/DHTPingMessage.cc
index 6038aab3..7ef680be 100644
--- a/src/DHTPingMessage.cc
+++ b/src/DHTPingMessage.cc
@@ -43,8 +43,8 @@ namespace aria2 {
const std::string DHTPingMessage::PING("ping");
-DHTPingMessage::DHTPingMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+DHTPingMessage::DHTPingMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID):
DHTQueryMessage(localNode, remoteNode, transactionID) {}
@@ -53,15 +53,15 @@ DHTPingMessage::~DHTPingMessage() {}
void DHTPingMessage::doReceivedAction()
{
// send back ping reply
- SharedHandle<DHTMessage> reply =
+ std::shared_ptr<DHTMessage> reply =
getMessageFactory()->createPingReplyMessage
(getRemoteNode(), getLocalNode()->getID(), getTransactionID());
getMessageDispatcher()->addMessageToQueue(reply);
}
-SharedHandle<Dict> DHTPingMessage::getArgument()
+std::shared_ptr<Dict> DHTPingMessage::getArgument()
{
- SharedHandle<Dict> aDict = Dict::g();
+ std::shared_ptr<Dict> aDict = Dict::g();
aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
return aDict;
}
diff --git a/src/DHTPingMessage.h b/src/DHTPingMessage.h
index fc265c23..d626d212 100644
--- a/src/DHTPingMessage.h
+++ b/src/DHTPingMessage.h
@@ -42,15 +42,15 @@ namespace aria2 {
class DHTPingMessage:public DHTQueryMessage {
public:
- DHTPingMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ DHTPingMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID = A2STR::NIL);
virtual ~DHTPingMessage();
virtual void doReceivedAction();
- virtual SharedHandle<Dict> getArgument();
+ virtual std::shared_ptr<Dict> getArgument();
virtual const std::string& getMessageType() const;
diff --git a/src/DHTPingReplyMessage.cc b/src/DHTPingReplyMessage.cc
index d0a89b58..9f050616 100644
--- a/src/DHTPingReplyMessage.cc
+++ b/src/DHTPingReplyMessage.cc
@@ -44,8 +44,8 @@ namespace aria2 {
const std::string DHTPingReplyMessage::PING("ping");
DHTPingReplyMessage::DHTPingReplyMessage
-(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* id,
const std::string& transactionID):
DHTResponseMessage(localNode, remoteNode, transactionID)
@@ -57,9 +57,9 @@ DHTPingReplyMessage::~DHTPingReplyMessage() {}
void DHTPingReplyMessage::doReceivedAction() {}
-SharedHandle<Dict> DHTPingReplyMessage::getResponse()
+std::shared_ptr<Dict> DHTPingReplyMessage::getResponse()
{
- SharedHandle<Dict> rDict = Dict::g();
+ std::shared_ptr<Dict> rDict = Dict::g();
rDict->put(DHTMessage::ID, String::g(id_, DHT_ID_LENGTH));
return rDict;
}
diff --git a/src/DHTPingReplyMessage.h b/src/DHTPingReplyMessage.h
index 25771906..c300b225 100644
--- a/src/DHTPingReplyMessage.h
+++ b/src/DHTPingReplyMessage.h
@@ -44,8 +44,8 @@ class DHTPingReplyMessage:public DHTResponseMessage {
private:
unsigned char id_[DHT_ID_LENGTH];
public:
- DHTPingReplyMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ DHTPingReplyMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* id,
const std::string& transactionID);
@@ -53,7 +53,7 @@ public:
virtual void doReceivedAction();
- virtual SharedHandle<Dict> getResponse();
+ virtual std::shared_ptr<Dict> getResponse();
virtual const std::string& getMessageType() const;
diff --git a/src/DHTPingReplyMessageCallback.h b/src/DHTPingReplyMessageCallback.h
index 1743713b..ddb311f3 100644
--- a/src/DHTPingReplyMessageCallback.h
+++ b/src/DHTPingReplyMessageCallback.h
@@ -70,7 +70,7 @@ public:
task_->onReceived(message);
}
- virtual void onTimeout(const SharedHandle<DHTNode>& remoteNode)
+ virtual void onTimeout(const std::shared_ptr<DHTNode>& remoteNode)
{
task_->onTimeout(remoteNode);
}
diff --git a/src/DHTPingTask.cc b/src/DHTPingTask.cc
index 75a8e3b4..f0aaed64 100644
--- a/src/DHTPingTask.cc
+++ b/src/DHTPingTask.cc
@@ -44,7 +44,7 @@
namespace aria2 {
DHTPingTask::DHTPingTask
-(const SharedHandle<DHTNode>& remoteNode, int numMaxRetry):
+(const std::shared_ptr<DHTNode>& remoteNode, int numMaxRetry):
remoteNode_(remoteNode),
numMaxRetry_(numMaxRetry),
numRetry_(0),
@@ -56,9 +56,9 @@ DHTPingTask::~DHTPingTask() {}
void DHTPingTask::addMessage()
{
- SharedHandle<DHTMessage> m =
+ std::shared_ptr<DHTMessage> m =
getMessageFactory()->createPingMessage(remoteNode_);
- SharedHandle<DHTMessageCallback> callback
+ std::shared_ptr<DHTMessageCallback> callback
(new DHTPingReplyMessageCallback<DHTPingTask>(this));
getMessageDispatcher()->addMessageToQueue(m, timeout_, callback);
}
@@ -74,7 +74,7 @@ void DHTPingTask::onReceived(const DHTPingReplyMessage* message)
setFinished(true);
}
-void DHTPingTask::onTimeout(const SharedHandle<DHTNode>& node)
+void DHTPingTask::onTimeout(const std::shared_ptr<DHTNode>& node)
{
++numRetry_;
if(numRetry_ >= numMaxRetry_) {
diff --git a/src/DHTPingTask.h b/src/DHTPingTask.h
index 85681fbf..db20b3c1 100644
--- a/src/DHTPingTask.h
+++ b/src/DHTPingTask.h
@@ -44,7 +44,7 @@ class DHTPingReplyMessage;
class DHTPingTask:public DHTAbstractTask {
private:
- SharedHandle<DHTNode> remoteNode_;
+ std::shared_ptr<DHTNode> remoteNode_;
int numMaxRetry_;
@@ -56,7 +56,7 @@ private:
void addMessage();
public:
- DHTPingTask(const SharedHandle<DHTNode>& remoteNode, int numMaxRetry = 0);
+ DHTPingTask(const std::shared_ptr<DHTNode>& remoteNode, int numMaxRetry = 0);
virtual ~DHTPingTask();
@@ -64,7 +64,7 @@ public:
void onReceived(const DHTPingReplyMessage* message);
- void onTimeout(const SharedHandle<DHTNode>& node);
+ void onTimeout(const std::shared_ptr<DHTNode>& node);
void setTimeout(time_t timeout)
{
diff --git a/src/DHTQueryMessage.cc b/src/DHTQueryMessage.cc
index 308f7df0..e3c85e1f 100644
--- a/src/DHTQueryMessage.cc
+++ b/src/DHTQueryMessage.cc
@@ -43,8 +43,8 @@ const std::string DHTQueryMessage::Q("q");
const std::string DHTQueryMessage::A("a");
-DHTQueryMessage::DHTQueryMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+DHTQueryMessage::DHTQueryMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID):
DHTAbstractMessage(localNode, remoteNode, transactionID) {}
diff --git a/src/DHTQueryMessage.h b/src/DHTQueryMessage.h
index 295c2992..68996e91 100644
--- a/src/DHTQueryMessage.h
+++ b/src/DHTQueryMessage.h
@@ -45,8 +45,8 @@ class DHTQueryMessage:public DHTAbstractMessage {
protected:
virtual std::string toStringOptional() const { return A2STR::NIL; }
public:
- DHTQueryMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ DHTQueryMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID = A2STR::NIL);
virtual ~DHTQueryMessage();
@@ -55,7 +55,7 @@ public:
virtual void fillMessage(Dict* msgDict);
- virtual SharedHandle<Dict> getArgument() = 0;
+ virtual std::shared_ptr<Dict> getArgument() = 0;
virtual bool isReply() const;
diff --git a/src/DHTRegistry.h b/src/DHTRegistry.h
index df79d28d..b8886844 100644
--- a/src/DHTRegistry.h
+++ b/src/DHTRegistry.h
@@ -36,7 +36,8 @@
#define D_DHT_REGISTRY_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -55,23 +56,23 @@ private:
struct Data {
bool initialized;
- SharedHandle<DHTNode> localNode;
+ std::shared_ptr<DHTNode> localNode;
- SharedHandle<DHTRoutingTable> routingTable;
+ std::shared_ptr<DHTRoutingTable> routingTable;
- SharedHandle<DHTTaskQueue> taskQueue;
+ std::shared_ptr<DHTTaskQueue> taskQueue;
- SharedHandle<DHTTaskFactory> taskFactory;
+ std::shared_ptr<DHTTaskFactory> taskFactory;
- SharedHandle<DHTPeerAnnounceStorage> peerAnnounceStorage;
+ std::shared_ptr<DHTPeerAnnounceStorage> peerAnnounceStorage;
- SharedHandle<DHTTokenTracker> tokenTracker;
+ std::shared_ptr<DHTTokenTracker> tokenTracker;
- SharedHandle<DHTMessageDispatcher> messageDispatcher;
+ std::shared_ptr<DHTMessageDispatcher> messageDispatcher;
- SharedHandle<DHTMessageReceiver> messageReceiver;
+ std::shared_ptr<DHTMessageReceiver> messageReceiver;
- SharedHandle<DHTMessageFactory> messageFactory;
+ std::shared_ptr<DHTMessageFactory> messageFactory;
Data():initialized(false) {}
};
diff --git a/src/DHTReplaceNodeTask.cc b/src/DHTReplaceNodeTask.cc
index 163102b0..fbf9a961 100644
--- a/src/DHTReplaceNodeTask.cc
+++ b/src/DHTReplaceNodeTask.cc
@@ -47,7 +47,7 @@
namespace aria2 {
DHTReplaceNodeTask::DHTReplaceNodeTask
-(const SharedHandle<DHTBucket>& bucket, const SharedHandle<DHTNode>& newNode)
+(const std::shared_ptr<DHTBucket>& bucket, const std::shared_ptr<DHTNode>& newNode)
: bucket_(bucket),
newNode_(newNode),
numRetry_(0),
@@ -63,13 +63,13 @@ void DHTReplaceNodeTask::startup()
void DHTReplaceNodeTask::sendMessage()
{
- SharedHandle<DHTNode> questionableNode = bucket_->getLRUQuestionableNode();
+ std::shared_ptr<DHTNode> questionableNode = bucket_->getLRUQuestionableNode();
if(!questionableNode) {
setFinished(true);
} else {
- SharedHandle<DHTMessage> m =
+ std::shared_ptr<DHTMessage> m =
getMessageFactory()->createPingMessage(questionableNode);
- SharedHandle<DHTMessageCallback> callback
+ std::shared_ptr<DHTMessageCallback> callback
(new DHTPingReplyMessageCallback<DHTReplaceNodeTask>(this));
getMessageDispatcher()->addMessageToQueue(m, timeout_, callback);
}
@@ -86,7 +86,7 @@ namespace {
const int MAX_RETRY = 2;
} //namespace
-void DHTReplaceNodeTask::onTimeout(const SharedHandle<DHTNode>& node)
+void DHTReplaceNodeTask::onTimeout(const std::shared_ptr<DHTNode>& node)
{
++numRetry_;
if(numRetry_ >= MAX_RETRY) {
diff --git a/src/DHTReplaceNodeTask.h b/src/DHTReplaceNodeTask.h
index 005696e4..f934bd1e 100644
--- a/src/DHTReplaceNodeTask.h
+++ b/src/DHTReplaceNodeTask.h
@@ -45,9 +45,9 @@ class DHTPingReplyMessage;
class DHTReplaceNodeTask:public DHTAbstractTask {
private:
- SharedHandle<DHTBucket> bucket_;
+ std::shared_ptr<DHTBucket> bucket_;
- SharedHandle<DHTNode> newNode_;
+ std::shared_ptr<DHTNode> newNode_;
int numRetry_;
@@ -55,8 +55,8 @@ private:
void sendMessage();
public:
- DHTReplaceNodeTask(const SharedHandle<DHTBucket>& bucket,
- const SharedHandle<DHTNode>& newNode);
+ DHTReplaceNodeTask(const std::shared_ptr<DHTBucket>& bucket,
+ const std::shared_ptr<DHTNode>& newNode);
virtual ~DHTReplaceNodeTask();
@@ -64,7 +64,7 @@ public:
void onReceived(const DHTPingReplyMessage* message);
- void onTimeout(const SharedHandle<DHTNode>& node);
+ void onTimeout(const std::shared_ptr<DHTNode>& node);
void setTimeout(time_t timeout)
{
diff --git a/src/DHTResponseMessage.cc b/src/DHTResponseMessage.cc
index 952188f8..d2882131 100644
--- a/src/DHTResponseMessage.cc
+++ b/src/DHTResponseMessage.cc
@@ -41,8 +41,8 @@ namespace aria2 {
const std::string DHTResponseMessage::R("r");
-DHTResponseMessage::DHTResponseMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+DHTResponseMessage::DHTResponseMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID):
DHTAbstractMessage(localNode, remoteNode, transactionID) {}
diff --git a/src/DHTResponseMessage.h b/src/DHTResponseMessage.h
index 68eef0f8..f5bbe937 100644
--- a/src/DHTResponseMessage.h
+++ b/src/DHTResponseMessage.h
@@ -47,8 +47,8 @@ class DHTResponseMessage:public DHTAbstractMessage {
protected:
virtual std::string toStringOptional() const { return A2STR::NIL; }
public:
- DHTResponseMessage(const SharedHandle<DHTNode>& localNode,
- const SharedHandle<DHTNode>& remoteNode,
+ DHTResponseMessage(const std::shared_ptr<DHTNode>& localNode,
+ const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID);
virtual ~DHTResponseMessage();
@@ -57,7 +57,7 @@ public:
virtual void fillMessage(Dict* msgDict);
- virtual SharedHandle<Dict> getResponse() = 0;
+ virtual std::shared_ptr<Dict> getResponse() = 0;
virtual bool isReply() const;
diff --git a/src/DHTRoutingTable.cc b/src/DHTRoutingTable.cc
index ab23a7bb..24c91195 100644
--- a/src/DHTRoutingTable.cc
+++ b/src/DHTRoutingTable.cc
@@ -49,10 +49,10 @@
namespace aria2 {
-DHTRoutingTable::DHTRoutingTable(const SharedHandle<DHTNode>& localNode)
+DHTRoutingTable::DHTRoutingTable(const std::shared_ptr<DHTNode>& localNode)
: localNode_(localNode),
root_(new DHTBucketTreeNode
- (SharedHandle<DHTBucket>(new DHTBucket(localNode_)))),
+ (std::shared_ptr<DHTBucket>(new DHTBucket(localNode_)))),
numBucket_(1)
{}
@@ -61,17 +61,17 @@ DHTRoutingTable::~DHTRoutingTable()
delete root_;
}
-bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node)
+bool DHTRoutingTable::addNode(const std::shared_ptr<DHTNode>& node)
{
return addNode(node, false);
}
-bool DHTRoutingTable::addGoodNode(const SharedHandle<DHTNode>& node)
+bool DHTRoutingTable::addGoodNode(const std::shared_ptr<DHTNode>& node)
{
return addNode(node, true);
}
-bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
+bool DHTRoutingTable::addNode(const std::shared_ptr<DHTNode>& node, bool good)
{
A2_LOG_DEBUG(fmt("Trying to add node:%s", node->toString().c_str()));
if(*localNode_ == *node) {
@@ -80,7 +80,7 @@ bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
}
DHTBucketTreeNode* treeNode = dht::findTreeNodeFor(root_, node->getID());
while(1) {
- const SharedHandle<DHTBucket>& bucket = treeNode->getBucket();
+ const std::shared_ptr<DHTBucket>& bucket = treeNode->getBucket();
if(bucket->addNode(node)) {
A2_LOG_DEBUG("Added DHTNode.");
return true;
@@ -107,7 +107,7 @@ bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
}
void DHTRoutingTable::getClosestKNodes
-(std::vector<SharedHandle<DHTNode> >& nodes,
+(std::vector<std::shared_ptr<DHTNode> >& nodes,
const unsigned char* key) const
{
dht::findClosestKNodes(nodes, root_, key);
@@ -120,56 +120,56 @@ int DHTRoutingTable::getNumBucket() const
void DHTRoutingTable::showBuckets() const
{/*
- for(std::deque<SharedHandle<DHTBucket> >::const_iterator itr = buckets_.begin(); itr != buckets_.end(); ++itr) {
+ for(std::deque<std::shared_ptr<DHTBucket> >::const_iterator itr = buckets_.begin(); itr != buckets_.end(); ++itr) {
cerr << "prefix = " << (*itr)->getPrefixLength() << ", "
<< "nodes = " << (*itr)->countNode() << endl;
}
*/
}
-SharedHandle<DHTBucket> DHTRoutingTable::getBucketFor(const unsigned char* nodeID) const
+std::shared_ptr<DHTBucket> DHTRoutingTable::getBucketFor(const unsigned char* nodeID) const
{
return dht::findBucketFor(root_, nodeID);
}
-SharedHandle<DHTBucket> DHTRoutingTable::getBucketFor(const SharedHandle<DHTNode>& node) const
+std::shared_ptr<DHTBucket> DHTRoutingTable::getBucketFor(const std::shared_ptr<DHTNode>& node) const
{
return getBucketFor(node->getID());
}
-SharedHandle<DHTNode> DHTRoutingTable::getNode(const unsigned char* nodeID, const std::string& ipaddr, uint16_t port) const
+std::shared_ptr<DHTNode> DHTRoutingTable::getNode(const unsigned char* nodeID, const std::string& ipaddr, uint16_t port) const
{
- SharedHandle<DHTBucket> bucket = getBucketFor(nodeID);
+ std::shared_ptr<DHTBucket> bucket = getBucketFor(nodeID);
return bucket->getNode(nodeID, ipaddr, port);
}
-void DHTRoutingTable::dropNode(const SharedHandle<DHTNode>& node)
+void DHTRoutingTable::dropNode(const std::shared_ptr<DHTNode>& node)
{
getBucketFor(node)->dropNode(node);
}
/*
- void DHTRoutingTable::moveBucketHead(const SharedHandle<DHTNode>& node)
+ void DHTRoutingTable::moveBucketHead(const std::shared_ptr<DHTNode>& node)
{
getBucketFor(node)->moveToHead(node);
}
*/
-void DHTRoutingTable::moveBucketTail(const SharedHandle<DHTNode>& node)
+void DHTRoutingTable::moveBucketTail(const std::shared_ptr<DHTNode>& node)
{
getBucketFor(node)->moveToTail(node);
}
void DHTRoutingTable::getBuckets
-(std::vector<SharedHandle<DHTBucket> >& buckets) const
+(std::vector<std::shared_ptr<DHTBucket> >& buckets) const
{
dht::enumerateBucket(buckets, root_);
}
-void DHTRoutingTable::setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue)
+void DHTRoutingTable::setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue)
{
taskQueue_ = taskQueue;
}
-void DHTRoutingTable::setTaskFactory(const SharedHandle<DHTTaskFactory>& taskFactory)
+void DHTRoutingTable::setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory)
{
taskFactory_ = taskFactory;
}
diff --git a/src/DHTRoutingTable.h b/src/DHTRoutingTable.h
index d7fb0b6f..a0708ac7 100644
--- a/src/DHTRoutingTable.h
+++ b/src/DHTRoutingTable.h
@@ -39,8 +39,7 @@
#include <string>
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -52,50 +51,50 @@ class DHTBucketTreeNode;
class DHTRoutingTable {
private:
- SharedHandle<DHTNode> localNode_;
+ std::shared_ptr<DHTNode> localNode_;
DHTBucketTreeNode* root_;
int numBucket_;
- SharedHandle<DHTTaskQueue> taskQueue_;
+ std::shared_ptr<DHTTaskQueue> taskQueue_;
- SharedHandle<DHTTaskFactory> taskFactory_;
+ std::shared_ptr<DHTTaskFactory> taskFactory_;
- bool addNode(const SharedHandle<DHTNode>& node, bool good);
+ bool addNode(const std::shared_ptr<DHTNode>& node, bool good);
public:
- DHTRoutingTable(const SharedHandle<DHTNode>& localNode);
+ DHTRoutingTable(const std::shared_ptr<DHTNode>& localNode);
~DHTRoutingTable();
- bool addNode(const SharedHandle<DHTNode>& node);
+ bool addNode(const std::shared_ptr<DHTNode>& node);
- bool addGoodNode(const SharedHandle<DHTNode>& node);
+ bool addGoodNode(const std::shared_ptr<DHTNode>& node);
- void getClosestKNodes(std::vector<SharedHandle<DHTNode> >& nodes,
+ void getClosestKNodes(std::vector<std::shared_ptr<DHTNode> >& nodes,
const unsigned char* key) const;
int getNumBucket() const;
void showBuckets() const;
- void dropNode(const SharedHandle<DHTNode>& node);
+ void dropNode(const std::shared_ptr<DHTNode>& node);
- void moveBucketHead(const SharedHandle<DHTNode>& node);
+ void moveBucketHead(const std::shared_ptr<DHTNode>& node);
- void moveBucketTail(const SharedHandle<DHTNode>& node);
+ void moveBucketTail(const std::shared_ptr<DHTNode>& node);
- SharedHandle<DHTBucket> getBucketFor(const unsigned char* nodeID) const;
+ std::shared_ptr<DHTBucket> getBucketFor(const unsigned char* nodeID) const;
- SharedHandle<DHTBucket> getBucketFor(const SharedHandle<DHTNode>& node) const;
+ std::shared_ptr<DHTBucket> getBucketFor(const std::shared_ptr<DHTNode>& node) const;
- SharedHandle<DHTNode> getNode(const unsigned char* id, const std::string& ipaddr, uint16_t port) const;
+ std::shared_ptr<DHTNode> getNode(const unsigned char* id, const std::string& ipaddr, uint16_t port) const;
- void getBuckets(std::vector<SharedHandle<DHTBucket> >& buckets) const;
+ void getBuckets(std::vector<std::shared_ptr<DHTBucket> >& buckets) const;
- void setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue);
+ void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
- void setTaskFactory(const SharedHandle<DHTTaskFactory>& taskFactory);
+ void setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory);
};
} // namespace aria2
diff --git a/src/DHTRoutingTableDeserializer.cc b/src/DHTRoutingTableDeserializer.cc
index f580415c..b1a2ce3b 100644
--- a/src/DHTRoutingTableDeserializer.cc
+++ b/src/DHTRoutingTableDeserializer.cc
@@ -144,7 +144,7 @@ void DHTRoutingTableDeserializer::deserialize(const std::string& filename)
readBytes(fp, buf, buf.size(), 8);
// localnode ID
readBytes(fp, buf, buf.size(), DHT_ID_LENGTH);
- SharedHandle<DHTNode> localNode(new DHTNode(buf));
+ std::shared_ptr<DHTNode> localNode(new DHTNode(buf));
// 4bytes reserved
readBytes(fp, buf, buf.size(), 4);
@@ -154,7 +154,7 @@ void DHTRoutingTableDeserializer::deserialize(const std::string& filename)
// 4bytes reserved
readBytes(fp, buf, buf.size(), 4);
- std::vector<SharedHandle<DHTNode> > nodes;
+ std::vector<std::shared_ptr<DHTNode> > nodes;
// nodes
const int compactlen = bittorrent::getCompactLength(family_);
for(size_t i = 0; i < numNodes; ++i) {
@@ -187,7 +187,7 @@ void DHTRoutingTableDeserializer::deserialize(const std::string& filename)
// node ID
readBytes(fp, buf, buf.size(), DHT_ID_LENGTH);
- SharedHandle<DHTNode> node(new DHTNode(buf));
+ std::shared_ptr<DHTNode> node(new DHTNode(buf));
node->setIPAddress(peer.first);
node->setPort(peer.second);
// 4bytes reserved
diff --git a/src/DHTRoutingTableDeserializer.h b/src/DHTRoutingTableDeserializer.h
index a94acb94..6e772905 100644
--- a/src/DHTRoutingTableDeserializer.h
+++ b/src/DHTRoutingTableDeserializer.h
@@ -39,8 +39,8 @@
#include <vector>
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "TimeA2.h"
namespace aria2 {
@@ -51,9 +51,9 @@ class DHTRoutingTableDeserializer {
private:
int family_;
- SharedHandle<DHTNode> localNode_;
+ std::shared_ptr<DHTNode> localNode_;
- std::vector<SharedHandle<DHTNode> > nodes_;
+ std::vector<std::shared_ptr<DHTNode> > nodes_;
Time serializedTime_;
public:
@@ -61,12 +61,12 @@ public:
~DHTRoutingTableDeserializer();
- const SharedHandle<DHTNode>& getLocalNode() const
+ const std::shared_ptr<DHTNode>& getLocalNode() const
{
return localNode_;
}
- const std::vector<SharedHandle<DHTNode> >& getNodes() const
+ const std::vector<std::shared_ptr<DHTNode> >& getNodes() const
{
return nodes_;
}
diff --git a/src/DHTRoutingTableSerializer.cc b/src/DHTRoutingTableSerializer.cc
index 2aa76a78..dc4a27cb 100644
--- a/src/DHTRoutingTableSerializer.cc
+++ b/src/DHTRoutingTableSerializer.cc
@@ -58,13 +58,13 @@ DHTRoutingTableSerializer::DHTRoutingTableSerializer(int family):
DHTRoutingTableSerializer::~DHTRoutingTableSerializer() {}
void DHTRoutingTableSerializer::setLocalNode
-(const SharedHandle<DHTNode>& localNode)
+(const std::shared_ptr<DHTNode>& localNode)
{
localNode_ = localNode;
}
void DHTRoutingTableSerializer::setNodes
-(const std::vector<SharedHandle<DHTNode> >& nodes)
+(const std::vector<std::shared_ptr<DHTNode> >& nodes)
{
nodes_ = nodes;
}
@@ -120,9 +120,9 @@ void DHTRoutingTableSerializer::serialize(const std::string& filename)
const int clen = bittorrent::getCompactLength(family_);
// nodes
- for(std::vector<SharedHandle<DHTNode> >::const_iterator i = nodes_.begin(),
+ for(std::vector<std::shared_ptr<DHTNode> >::const_iterator i = nodes_.begin(),
eoi = nodes_.end(); i != eoi; ++i) {
- const SharedHandle<DHTNode>& node = *i;
+ const std::shared_ptr<DHTNode>& node = *i;
// Write IP address + port in Compact IP-address/port info form.
unsigned char compactPeer[COMPACT_LEN_IPV6];
int compactlen = bittorrent::packcompact
diff --git a/src/DHTRoutingTableSerializer.h b/src/DHTRoutingTableSerializer.h
index f0b703fd..8d45b9b6 100644
--- a/src/DHTRoutingTableSerializer.h
+++ b/src/DHTRoutingTableSerializer.h
@@ -39,8 +39,7 @@
#include <vector>
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -50,17 +49,17 @@ class DHTRoutingTableSerializer {
private:
int family_;
- SharedHandle<DHTNode> localNode_;
+ std::shared_ptr<DHTNode> localNode_;
- std::vector<SharedHandle<DHTNode> > nodes_;
+ std::vector<std::shared_ptr<DHTNode> > nodes_;
public:
DHTRoutingTableSerializer(int family);
~DHTRoutingTableSerializer();
- void setLocalNode(const SharedHandle<DHTNode>& localNode);
+ void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
- void setNodes(const std::vector<SharedHandle<DHTNode> >& nodes);
+ void setNodes(const std::vector<std::shared_ptr<DHTNode> >& nodes);
void serialize(const std::string& filename);
};
diff --git a/src/DHTSetup.cc b/src/DHTSetup.cc
index 13df226c..f2842535 100644
--- a/src/DHTSetup.cc
+++ b/src/DHTSetup.cc
@@ -93,7 +93,7 @@ void DHTSetup::setup
auto_delete_container<std::vector<Command*> > commandsDel(tempCommands);
// load routing table and localnode id here
- SharedHandle<DHTNode> localNode;
+ std::shared_ptr<DHTNode> localNode;
DHTRoutingTableDeserializer deserializer(family);
const std::string& dhtFile =
@@ -113,7 +113,7 @@ void DHTSetup::setup
}
uint16_t port;
- SharedHandle<DHTConnectionImpl> connection(new DHTConnectionImpl(family));
+ std::shared_ptr<DHTConnectionImpl> connection(new DHTConnectionImpl(family));
{
port = e->getBtRegistry()->getUdpPort();
const std::string& addr =
@@ -139,24 +139,24 @@ void DHTSetup::setup
}
A2_LOG_DEBUG(fmt("Initialized local node ID=%s",
util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str()));
- SharedHandle<DHTRoutingTable> routingTable(new DHTRoutingTable(localNode));
+ std::shared_ptr<DHTRoutingTable> routingTable(new DHTRoutingTable(localNode));
- SharedHandle<DHTMessageFactoryImpl> factory
+ std::shared_ptr<DHTMessageFactoryImpl> factory
(new DHTMessageFactoryImpl(family));
- SharedHandle<DHTMessageTracker> tracker(new DHTMessageTracker());
+ std::shared_ptr<DHTMessageTracker> tracker(new DHTMessageTracker());
- SharedHandle<DHTMessageDispatcherImpl> dispatcher(new DHTMessageDispatcherImpl(tracker));
+ std::shared_ptr<DHTMessageDispatcherImpl> dispatcher(new DHTMessageDispatcherImpl(tracker));
- SharedHandle<DHTMessageReceiver> receiver(new DHTMessageReceiver(tracker));
+ std::shared_ptr<DHTMessageReceiver> receiver(new DHTMessageReceiver(tracker));
- SharedHandle<DHTTaskQueue> taskQueue(new DHTTaskQueueImpl());
+ std::shared_ptr<DHTTaskQueue> taskQueue(new DHTTaskQueueImpl());
- SharedHandle<DHTTaskFactoryImpl> taskFactory(new DHTTaskFactoryImpl());
+ std::shared_ptr<DHTTaskFactoryImpl> taskFactory(new DHTTaskFactoryImpl());
- SharedHandle<DHTPeerAnnounceStorage> peerAnnounceStorage(new DHTPeerAnnounceStorage());
+ std::shared_ptr<DHTPeerAnnounceStorage> peerAnnounceStorage(new DHTPeerAnnounceStorage());
- SharedHandle<DHTTokenTracker> tokenTracker(new DHTTokenTracker());
+ std::shared_ptr<DHTTokenTracker> tokenTracker(new DHTTokenTracker());
const time_t messageTimeout = e->getOption()->getAsInt(PREF_DHT_MESSAGE_TIMEOUT);
// wiring up
@@ -190,7 +190,7 @@ void DHTSetup::setup
factory->setLocalNode(localNode);
// For now, UDPTrackerClient was enabled along with DHT
- SharedHandle<UDPTrackerClient> udpTrackerClient(new UDPTrackerClient());
+ std::shared_ptr<UDPTrackerClient> udpTrackerClient(new UDPTrackerClient());
// assign them into DHTRegistry
if(family == AF_INET) {
DHTRegistry::getMutableData().localNode = localNode;
@@ -215,16 +215,15 @@ void DHTSetup::setup
DHTRegistry::getMutableData6().messageFactory = factory;
}
// add deserialized nodes to routing table
- const std::vector<SharedHandle<DHTNode> >& desnodes =
+ const std::vector<std::shared_ptr<DHTNode> >& desnodes =
deserializer.getNodes();
- for(std::vector<SharedHandle<DHTNode> >::const_iterator i =
+ for(std::vector<std::shared_ptr<DHTNode> >::const_iterator i =
desnodes.begin(), eoi = desnodes.end(); i != eoi; ++i) {
routingTable->addNode(*i);
}
if(!desnodes.empty()) {
- SharedHandle<DHTBucketRefreshTask> task
- (static_pointer_cast<DHTBucketRefreshTask>
- (taskFactory->createBucketRefreshTask()));
+ auto task = std::static_pointer_cast<DHTBucketRefreshTask>
+ (taskFactory->createBucketRefreshTask());
task->setForceRefresh(true);
taskQueue->addPeriodicTask1(task);
}
@@ -311,7 +310,7 @@ void DHTSetup::setup
if(family == AF_INET) {
DHTRegistry::clearData();
e->getBtRegistry()->setUDPTrackerClient
- (SharedHandle<UDPTrackerClient>());
+ (std::shared_ptr<UDPTrackerClient>());
} else {
DHTRegistry::clearData6();
}
diff --git a/src/DHTTaskExecutor.cc b/src/DHTTaskExecutor.cc
index ba57c1f3..9179dbe4 100644
--- a/src/DHTTaskExecutor.cc
+++ b/src/DHTTaskExecutor.cc
@@ -62,7 +62,7 @@ void DHTTaskExecutor::update()
r = 0;
}
while(r && !queue_.empty()) {
- SharedHandle<DHTTask> task = queue_.front();
+ std::shared_ptr<DHTTask> task = queue_.front();
queue_.pop_front();
task->startup();
if(!task->finished()) {
diff --git a/src/DHTTaskExecutor.h b/src/DHTTaskExecutor.h
index f64fd6c6..c50f52d3 100644
--- a/src/DHTTaskExecutor.h
+++ b/src/DHTTaskExecutor.h
@@ -39,8 +39,7 @@
#include <vector>
#include <deque>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -49,8 +48,8 @@ class DHTTask;
class DHTTaskExecutor {
private:
int numConcurrent_;
- std::vector<SharedHandle<DHTTask> > execTasks_;
- std::deque<SharedHandle<DHTTask> > queue_;
+ std::vector<std::shared_ptr<DHTTask> > execTasks_;
+ std::deque<std::shared_ptr<DHTTask> > queue_;
public:
DHTTaskExecutor(int numConcurrent);
@@ -58,7 +57,7 @@ public:
void update();
- void addTask(const SharedHandle<DHTTask>& task)
+ void addTask(const std::shared_ptr<DHTTask>& task)
{
queue_.push_back(task);
}
diff --git a/src/DHTTaskFactory.h b/src/DHTTaskFactory.h
index 90434696..7d329d92 100644
--- a/src/DHTTaskFactory.h
+++ b/src/DHTTaskFactory.h
@@ -36,7 +36,8 @@
#define D_DHT_TASK_FACTORY_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -50,26 +51,26 @@ class DHTTaskFactory {
public:
virtual ~DHTTaskFactory() {}
- virtual SharedHandle<DHTTask>
- createPingTask(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTTask>
+ createPingTask(const std::shared_ptr<DHTNode>& remoteNode,
int numRetry = 0) = 0;
- virtual SharedHandle<DHTTask>
+ virtual std::shared_ptr<DHTTask>
createNodeLookupTask(const unsigned char* targetID) = 0;
- virtual SharedHandle<DHTTask> createBucketRefreshTask() = 0;
+ virtual std::shared_ptr<DHTTask> createBucketRefreshTask() = 0;
- virtual SharedHandle<DHTTask>
- createPeerLookupTask(const SharedHandle<DownloadContext>& ctx,
+ virtual std::shared_ptr<DHTTask>
+ createPeerLookupTask(const std::shared_ptr<DownloadContext>& ctx,
uint16_t tcpPort,
- const SharedHandle<PeerStorage>& peerStorage) = 0;
+ const std::shared_ptr<PeerStorage>& peerStorage) = 0;
- virtual SharedHandle<DHTTask>
+ virtual std::shared_ptr<DHTTask>
createPeerAnnounceTask(const unsigned char* infoHash) = 0;
- virtual SharedHandle<DHTTask>
- createReplaceNodeTask(const SharedHandle<DHTBucket>& bucket,
- const SharedHandle<DHTNode>& newNode) = 0;
+ virtual std::shared_ptr<DHTTask>
+ createReplaceNodeTask(const std::shared_ptr<DHTBucket>& bucket,
+ const std::shared_ptr<DHTNode>& newNode) = 0;
};
} // namespace aria2
diff --git a/src/DHTTaskFactoryImpl.cc b/src/DHTTaskFactoryImpl.cc
index aec36c7c..2bed9da5 100644
--- a/src/DHTTaskFactoryImpl.cc
+++ b/src/DHTTaskFactoryImpl.cc
@@ -60,63 +60,63 @@ DHTTaskFactoryImpl::DHTTaskFactoryImpl()
DHTTaskFactoryImpl::~DHTTaskFactoryImpl() {}
-SharedHandle<DHTTask>
-DHTTaskFactoryImpl::createPingTask(const SharedHandle<DHTNode>& remoteNode,
+std::shared_ptr<DHTTask>
+DHTTaskFactoryImpl::createPingTask(const std::shared_ptr<DHTNode>& remoteNode,
int numRetry)
{
- SharedHandle<DHTPingTask> task(new DHTPingTask(remoteNode, numRetry));
+ std::shared_ptr<DHTPingTask> task(new DHTPingTask(remoteNode, numRetry));
task->setTimeout(timeout_);
setCommonProperty(task);
return task;
}
-SharedHandle<DHTTask>
+std::shared_ptr<DHTTask>
DHTTaskFactoryImpl::createNodeLookupTask(const unsigned char* targetID)
{
- SharedHandle<DHTNodeLookupTask> task(new DHTNodeLookupTask(targetID));
+ std::shared_ptr<DHTNodeLookupTask> task(new DHTNodeLookupTask(targetID));
setCommonProperty(task);
return task;
}
-SharedHandle<DHTTask>
+std::shared_ptr<DHTTask>
DHTTaskFactoryImpl::createBucketRefreshTask()
{
- SharedHandle<DHTBucketRefreshTask> task(new DHTBucketRefreshTask());
+ std::shared_ptr<DHTBucketRefreshTask> task(new DHTBucketRefreshTask());
setCommonProperty(task);
return task;
}
-SharedHandle<DHTTask>
+std::shared_ptr<DHTTask>
DHTTaskFactoryImpl::createPeerLookupTask
-(const SharedHandle<DownloadContext>& ctx,
+(const std::shared_ptr<DownloadContext>& ctx,
uint16_t tcpPort,
- const SharedHandle<PeerStorage>& peerStorage)
+ const std::shared_ptr<PeerStorage>& peerStorage)
{
- SharedHandle<DHTPeerLookupTask> task(new DHTPeerLookupTask(ctx, tcpPort));
+ std::shared_ptr<DHTPeerLookupTask> task(new DHTPeerLookupTask(ctx, tcpPort));
// TODO this may be not freed by RequestGroup::releaseRuntimeResource()
task->setPeerStorage(peerStorage);
setCommonProperty(task);
return task;
}
-SharedHandle<DHTTask>
+std::shared_ptr<DHTTask>
DHTTaskFactoryImpl::createPeerAnnounceTask(const unsigned char* infoHash)
{
// TODO
- return SharedHandle<DHTTask>();
+ return std::shared_ptr<DHTTask>();
}
-SharedHandle<DHTTask>
-DHTTaskFactoryImpl::createReplaceNodeTask(const SharedHandle<DHTBucket>& bucket,
- const SharedHandle<DHTNode>& newNode)
+std::shared_ptr<DHTTask>
+DHTTaskFactoryImpl::createReplaceNodeTask(const std::shared_ptr<DHTBucket>& bucket,
+ const std::shared_ptr<DHTNode>& newNode)
{
- SharedHandle<DHTReplaceNodeTask> task(new DHTReplaceNodeTask(bucket, newNode));
+ std::shared_ptr<DHTReplaceNodeTask> task(new DHTReplaceNodeTask(bucket, newNode));
task->setTimeout(timeout_);
setCommonProperty(task);
return task;
}
-void DHTTaskFactoryImpl::setCommonProperty(const SharedHandle<DHTAbstractTask>& task)
+void DHTTaskFactoryImpl::setCommonProperty(const std::shared_ptr<DHTAbstractTask>& task)
{
task->setRoutingTable(routingTable_);
task->setMessageDispatcher(dispatcher_);
@@ -145,7 +145,7 @@ void DHTTaskFactoryImpl::setTaskQueue(DHTTaskQueue* taskQueue)
taskQueue_ = taskQueue;
}
-void DHTTaskFactoryImpl::setLocalNode(const SharedHandle<DHTNode>& localNode)
+void DHTTaskFactoryImpl::setLocalNode(const std::shared_ptr<DHTNode>& localNode)
{
localNode_ = localNode;
}
diff --git a/src/DHTTaskFactoryImpl.h b/src/DHTTaskFactoryImpl.h
index aef197f2..baded49d 100644
--- a/src/DHTTaskFactoryImpl.h
+++ b/src/DHTTaskFactoryImpl.h
@@ -49,7 +49,7 @@ class DHTAbstractTask;
class DHTTaskFactoryImpl:public DHTTaskFactory {
private:
- SharedHandle<DHTNode> localNode_;
+ std::shared_ptr<DHTNode> localNode_;
DHTRoutingTable* routingTable_;
@@ -61,32 +61,32 @@ private:
time_t timeout_;
- void setCommonProperty(const SharedHandle<DHTAbstractTask>& task);
+ void setCommonProperty(const std::shared_ptr<DHTAbstractTask>& task);
public:
DHTTaskFactoryImpl();
virtual ~DHTTaskFactoryImpl();
- virtual SharedHandle<DHTTask>
- createPingTask(const SharedHandle<DHTNode>& remoteNode,
+ virtual std::shared_ptr<DHTTask>
+ createPingTask(const std::shared_ptr<DHTNode>& remoteNode,
int numRetry = 0);
- virtual SharedHandle<DHTTask>
+ virtual std::shared_ptr<DHTTask>
createNodeLookupTask(const unsigned char* targetID);
- virtual SharedHandle<DHTTask> createBucketRefreshTask();
+ virtual std::shared_ptr<DHTTask> createBucketRefreshTask();
- virtual SharedHandle<DHTTask>
- createPeerLookupTask(const SharedHandle<DownloadContext>& ctx,
+ virtual std::shared_ptr<DHTTask>
+ createPeerLookupTask(const std::shared_ptr<DownloadContext>& ctx,
uint16_t tcpPort,
- const SharedHandle<PeerStorage>& peerStorage);
+ const std::shared_ptr<PeerStorage>& peerStorage);
- virtual SharedHandle<DHTTask>
+ virtual std::shared_ptr<DHTTask>
createPeerAnnounceTask(const unsigned char* infoHash);
- virtual SharedHandle<DHTTask>
- createReplaceNodeTask(const SharedHandle<DHTBucket>& bucket,
- const SharedHandle<DHTNode>& newNode);
+ virtual std::shared_ptr<DHTTask>
+ createReplaceNodeTask(const std::shared_ptr<DHTBucket>& bucket,
+ const std::shared_ptr<DHTNode>& newNode);
void setRoutingTable(DHTRoutingTable* routingTable);
@@ -96,7 +96,7 @@ public:
void setTaskQueue(DHTTaskQueue* taskQueue);
- void setLocalNode(const SharedHandle<DHTNode>& localNode);
+ void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
void setTimeout(time_t timeout)
{
diff --git a/src/DHTTaskQueue.h b/src/DHTTaskQueue.h
index c7596aeb..dad5e99f 100644
--- a/src/DHTTaskQueue.h
+++ b/src/DHTTaskQueue.h
@@ -36,7 +36,8 @@
#define D_DHT_TASK_QUEUE_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -48,11 +49,11 @@ public:
virtual void executeTask() = 0;
- virtual void addPeriodicTask1(const SharedHandle<DHTTask>& task) = 0;
+ virtual void addPeriodicTask1(const std::shared_ptr<DHTTask>& task) = 0;
- virtual void addPeriodicTask2(const SharedHandle<DHTTask>& task) = 0;
+ virtual void addPeriodicTask2(const std::shared_ptr<DHTTask>& task) = 0;
- virtual void addImmediateTask(const SharedHandle<DHTTask>& task) = 0;
+ virtual void addImmediateTask(const std::shared_ptr<DHTTask>& task) = 0;
};
} // namespace aria2
diff --git a/src/DHTTaskQueueImpl.cc b/src/DHTTaskQueueImpl.cc
index 505fb010..2097aae9 100644
--- a/src/DHTTaskQueueImpl.cc
+++ b/src/DHTTaskQueueImpl.cc
@@ -61,17 +61,17 @@ void DHTTaskQueueImpl::executeTask()
immediateTaskQueue_.update();
}
-void DHTTaskQueueImpl::addPeriodicTask1(const SharedHandle<DHTTask>& task)
+void DHTTaskQueueImpl::addPeriodicTask1(const std::shared_ptr<DHTTask>& task)
{
periodicTaskQueue1_.addTask(task);
}
-void DHTTaskQueueImpl::addPeriodicTask2(const SharedHandle<DHTTask>& task)
+void DHTTaskQueueImpl::addPeriodicTask2(const std::shared_ptr<DHTTask>& task)
{
periodicTaskQueue2_.addTask(task);
}
-void DHTTaskQueueImpl::addImmediateTask(const SharedHandle<DHTTask>& task)
+void DHTTaskQueueImpl::addImmediateTask(const std::shared_ptr<DHTTask>& task)
{
immediateTaskQueue_.addTask(task);
}
diff --git a/src/DHTTaskQueueImpl.h b/src/DHTTaskQueueImpl.h
index 87c0eaf0..eb21e620 100644
--- a/src/DHTTaskQueueImpl.h
+++ b/src/DHTTaskQueueImpl.h
@@ -54,11 +54,11 @@ public:
virtual void executeTask();
- virtual void addPeriodicTask1(const SharedHandle<DHTTask>& task);
+ virtual void addPeriodicTask1(const std::shared_ptr<DHTTask>& task);
- virtual void addPeriodicTask2(const SharedHandle<DHTTask>& task);
+ virtual void addPeriodicTask2(const std::shared_ptr<DHTTask>& task);
- virtual void addImmediateTask(const SharedHandle<DHTTask>& task);
+ virtual void addImmediateTask(const std::shared_ptr<DHTTask>& task);
};
} // namespace aria2
diff --git a/src/DHTTokenUpdateCommand.cc b/src/DHTTokenUpdateCommand.cc
index 176cb6a9..d7ccb6d4 100644
--- a/src/DHTTokenUpdateCommand.cc
+++ b/src/DHTTokenUpdateCommand.cc
@@ -67,7 +67,7 @@ void DHTTokenUpdateCommand::process()
}
}
-void DHTTokenUpdateCommand::setTokenTracker(const SharedHandle<DHTTokenTracker>& tokenTracker)
+void DHTTokenUpdateCommand::setTokenTracker(const std::shared_ptr<DHTTokenTracker>& tokenTracker)
{
tokenTracker_ = tokenTracker;
}
diff --git a/src/DHTTokenUpdateCommand.h b/src/DHTTokenUpdateCommand.h
index ecb6d8af..cec5ca30 100644
--- a/src/DHTTokenUpdateCommand.h
+++ b/src/DHTTokenUpdateCommand.h
@@ -36,7 +36,8 @@
#define D_DHT_TOKEN_UPDATE_COMMAND_H
#include "TimeBasedCommand.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -44,7 +45,7 @@ class DHTTokenTracker;
class DHTTokenUpdateCommand:public TimeBasedCommand {
private:
- SharedHandle<DHTTokenTracker> tokenTracker_;
+ std::shared_ptr<DHTTokenTracker> tokenTracker_;
public:
DHTTokenUpdateCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
@@ -54,7 +55,7 @@ public:
virtual void process();
- void setTokenTracker(const SharedHandle<DHTTokenTracker>& tokenTracker);
+ void setTokenTracker(const std::shared_ptr<DHTTokenTracker>& tokenTracker);
};
} // namespace aria2
diff --git a/src/DHTUnknownMessage.cc b/src/DHTUnknownMessage.cc
index 268b30a0..46cdaf5c 100644
--- a/src/DHTUnknownMessage.cc
+++ b/src/DHTUnknownMessage.cc
@@ -47,10 +47,10 @@ const std::string DHTUnknownMessage::E("e");
const std::string DHTUnknownMessage::UNKNOWN("unknown");
-DHTUnknownMessage::DHTUnknownMessage(const SharedHandle<DHTNode>& localNode,
+DHTUnknownMessage::DHTUnknownMessage(const std::shared_ptr<DHTNode>& localNode,
const unsigned char* data, size_t length,
const std::string& ipaddr, uint16_t port):
- DHTMessage(localNode, SharedHandle<DHTNode>()),
+ DHTMessage(localNode, std::shared_ptr<DHTNode>()),
length_(length),
ipaddr_(ipaddr),
port_(port)
diff --git a/src/DHTUnknownMessage.h b/src/DHTUnknownMessage.h
index 683fa19b..2ad03cbb 100644
--- a/src/DHTUnknownMessage.h
+++ b/src/DHTUnknownMessage.h
@@ -47,7 +47,7 @@ private:
uint16_t port_;
public:
// _remoteNode is always null
- DHTUnknownMessage(const SharedHandle<DHTNode>& localNode,
+ DHTUnknownMessage(const std::shared_ptr<DHTNode>& localNode,
const unsigned char* data, size_t length,
const std::string& ipaddr, uint16_t port);
diff --git a/src/DNSCache.cc b/src/DNSCache.cc
index 5ffdb831..6097df1d 100644
--- a/src/DNSCache.cc
+++ b/src/DNSCache.cc
@@ -167,7 +167,7 @@ DNSCache& DNSCache::operator=(const DNSCache& c)
const std::string& DNSCache::find
(const std::string& hostname, uint16_t port) const
{
- SharedHandle<CacheEntry> target(new CacheEntry(hostname, port));
+ std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
CacheEntrySet::iterator i = entries_.find(target);
if(i == entries_.end()) {
return A2STR::NIL;
@@ -179,7 +179,7 @@ const std::string& DNSCache::find
void DNSCache::put
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
{
- SharedHandle<CacheEntry> target(new CacheEntry(hostname, port));
+ std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
CacheEntrySet::iterator i = entries_.lower_bound(target);
if(i != entries_.end() && *(*i) == *target) {
(*i)->add(ipaddr);
@@ -192,7 +192,7 @@ void DNSCache::put
void DNSCache::markBad
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
{
- SharedHandle<CacheEntry> target(new CacheEntry(hostname, port));
+ std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
CacheEntrySet::iterator i = entries_.find(target);
if(i != entries_.end()) {
(*i)->markBad(ipaddr);
@@ -201,7 +201,7 @@ void DNSCache::markBad
void DNSCache::remove(const std::string& hostname, uint16_t port)
{
- SharedHandle<CacheEntry> target(new CacheEntry(hostname, port));
+ std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
entries_.erase(target);
}
diff --git a/src/DNSCache.h b/src/DNSCache.h
index 49606e62..ed4de417 100644
--- a/src/DNSCache.h
+++ b/src/DNSCache.h
@@ -98,8 +98,8 @@ private:
bool operator==(const CacheEntry& e) const;
};
- typedef std::set<SharedHandle<CacheEntry>,
- DerefLess<SharedHandle<CacheEntry> > > CacheEntrySet;
+ typedef std::set<std::shared_ptr<CacheEntry>,
+ DerefLess<std::shared_ptr<CacheEntry> > > CacheEntrySet;
CacheEntrySet entries_;
public:
DNSCache();
@@ -114,7 +114,7 @@ public:
void findAll
(OutputIterator out, const std::string& hostname, uint16_t port) const
{
- SharedHandle<CacheEntry> target(new CacheEntry(hostname, port));
+ std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
CacheEntrySet::iterator i = entries_.find(target);
if(i != entries_.end()) {
(*i)->getAllGoodAddrs(out);
diff --git a/src/DefaultAuthResolver.cc b/src/DefaultAuthResolver.cc
index dc5f01c7..2cb589cf 100644
--- a/src/DefaultAuthResolver.cc
+++ b/src/DefaultAuthResolver.cc
@@ -37,7 +37,7 @@
namespace aria2 {
-SharedHandle<AuthConfig> DefaultAuthResolver::resolveAuthConfig
+std::shared_ptr<AuthConfig> DefaultAuthResolver::resolveAuthConfig
(const std::string& hostname)
{
if(!getUserDefinedAuthConfig()) {
diff --git a/src/DefaultAuthResolver.h b/src/DefaultAuthResolver.h
index bb2ec8e3..e3ddf509 100644
--- a/src/DefaultAuthResolver.h
+++ b/src/DefaultAuthResolver.h
@@ -41,7 +41,7 @@ namespace aria2 {
class DefaultAuthResolver : public AbstractAuthResolver {
public:
- virtual SharedHandle<AuthConfig> resolveAuthConfig
+ virtual std::shared_ptr<AuthConfig> resolveAuthConfig
(const std::string& hostname);
};
diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc
index a41f002d..f371def2 100644
--- a/src/DefaultBtAnnounce.cc
+++ b/src/DefaultBtAnnounce.cc
@@ -58,7 +58,7 @@
namespace aria2 {
DefaultBtAnnounce::DefaultBtAnnounce
-(const SharedHandle<DownloadContext>& downloadContext,
+(const std::shared_ptr<DownloadContext>& downloadContext,
const Option* option)
: downloadContext_(downloadContext),
trackers_(0),
@@ -202,16 +202,16 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
return uri;
}
-SharedHandle<UDPTrackerRequest> DefaultBtAnnounce::createUDPTrackerRequest
+std::shared_ptr<UDPTrackerRequest> DefaultBtAnnounce::createUDPTrackerRequest
(const std::string& remoteAddr, uint16_t remotePort, uint16_t localPort)
{
if(!adjustAnnounceList()) {
- return SharedHandle<UDPTrackerRequest>();
+ return std::shared_ptr<UDPTrackerRequest>();
}
NetStat& stat = downloadContext_->getNetStat();
int64_t left =
pieceStorage_->getTotalLength()-pieceStorage_->getCompletedLength();
- SharedHandle<UDPTrackerRequest> req(new UDPTrackerRequest());
+ std::shared_ptr<UDPTrackerRequest> req(new UDPTrackerRequest());
req->remoteAddr = remoteAddr;
req->remotePort = remotePort;
req->action = UDPT_ACT_ANNOUNCE;
@@ -284,7 +284,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
size_t trackerResponseLength)
{
A2_LOG_DEBUG("Now processing tracker response.");
- SharedHandle<ValueBase> decodedValue =
+ std::shared_ptr<ValueBase> decodedValue =
bencode2::decode(trackerResponse, trackerResponseLength);
const Dict* dict = downcast<Dict>(decodedValue);
if(!dict) {
@@ -328,22 +328,22 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
incomplete_ = incomp->i();
A2_LOG_DEBUG(fmt("Incomplete:%d", incomplete_));
}
- const SharedHandle<ValueBase>& peerData = dict->get(BtAnnounce::PEERS);
+ const std::shared_ptr<ValueBase>& peerData = dict->get(BtAnnounce::PEERS);
if(!peerData) {
A2_LOG_INFO(MSG_NO_PEER_LIST_RECEIVED);
} else {
if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) {
- std::vector<SharedHandle<Peer> > peers;
+ std::vector<std::shared_ptr<Peer> > peers;
bittorrent::extractPeer(peerData, AF_INET, std::back_inserter(peers));
peerStorage_->addPeer(peers);
}
}
- const SharedHandle<ValueBase>& peer6Data = dict->get(BtAnnounce::PEERS6);
+ const std::shared_ptr<ValueBase>& peer6Data = dict->get(BtAnnounce::PEERS6);
if(!peer6Data) {
A2_LOG_INFO("No peers6 received.");
} else {
if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) {
- std::vector<SharedHandle<Peer> > peers;
+ std::vector<std::shared_ptr<Peer> > peers;
bittorrent::extractPeer(peer6Data, AF_INET6, std::back_inserter(peers));
peerStorage_->addPeer(peers);
}
@@ -351,9 +351,9 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
}
void DefaultBtAnnounce::processUDPTrackerResponse
-(const SharedHandle<UDPTrackerRequest>& req)
+(const std::shared_ptr<UDPTrackerRequest>& req)
{
- const SharedHandle<UDPTrackerReply>& reply = req->reply;
+ const std::shared_ptr<UDPTrackerReply>& reply = req->reply;
A2_LOG_DEBUG("Now processing UDP tracker response.");
if(reply->interval > 0) {
minInterval_ = reply->interval;
@@ -368,7 +368,7 @@ void DefaultBtAnnounce::processUDPTrackerResponse
for(std::vector<std::pair<std::string, uint16_t> >::iterator i =
reply->peers.begin(), eoi = reply->peers.end(); i != eoi;
++i) {
- peerStorage_->addPeer(SharedHandle<Peer>(new Peer((*i).first,
+ peerStorage_->addPeer(std::shared_ptr<Peer>(new Peer((*i).first,
(*i).second)));
}
}
@@ -385,23 +385,23 @@ void DefaultBtAnnounce::shuffleAnnounce() {
}
void DefaultBtAnnounce::setRandomizer
-(const SharedHandle<Randomizer>& randomizer)
+(const std::shared_ptr<Randomizer>& randomizer)
{
randomizer_ = randomizer;
}
-void DefaultBtAnnounce::setBtRuntime(const SharedHandle<BtRuntime>& btRuntime)
+void DefaultBtAnnounce::setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
-void DefaultBtAnnounce::setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage)
+void DefaultBtAnnounce::setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
void DefaultBtAnnounce::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
diff --git a/src/DefaultBtAnnounce.h b/src/DefaultBtAnnounce.h
index 5428a42c..7c2f9eb8 100644
--- a/src/DefaultBtAnnounce.h
+++ b/src/DefaultBtAnnounce.h
@@ -50,7 +50,7 @@ class Randomizer;
class DefaultBtAnnounce : public BtAnnounce {
private:
- SharedHandle<DownloadContext> downloadContext_;
+ std::shared_ptr<DownloadContext> downloadContext_;
int trackers_;
Timer prevAnnounceTimer_;
time_t interval_;
@@ -61,36 +61,36 @@ private:
AnnounceList announceList_;
std::string trackerId_;
const Option* option_;
- SharedHandle<Randomizer> randomizer_;
- SharedHandle<BtRuntime> btRuntime_;
- SharedHandle<PieceStorage> pieceStorage_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<Randomizer> randomizer_;
+ std::shared_ptr<BtRuntime> btRuntime_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
uint16_t tcpPort_;
bool adjustAnnounceList();
public:
- DefaultBtAnnounce(const SharedHandle<DownloadContext>& downloadContext,
+ DefaultBtAnnounce(const std::shared_ptr<DownloadContext>& downloadContext,
const Option* option);
virtual ~DefaultBtAnnounce();
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
- const SharedHandle<BtRuntime>& getBtRuntime() const
+ const std::shared_ptr<BtRuntime>& getBtRuntime() const
{
return btRuntime_;
}
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
- const SharedHandle<PieceStorage>& getPieceStorage() const
+ const std::shared_ptr<PieceStorage>& getPieceStorage() const
{
return pieceStorage_;
}
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
- const SharedHandle<PeerStorage>& getPeerStorage() const
+ const std::shared_ptr<PeerStorage>& getPeerStorage() const
{
return peerStorage_;
}
@@ -105,7 +105,7 @@ public:
virtual std::string getAnnounceUrl();
- virtual SharedHandle<UDPTrackerRequest>
+ virtual std::shared_ptr<UDPTrackerRequest>
createUDPTrackerRequest(const std::string& remoteAddr, uint16_t remotePort,
uint16_t localPort);
@@ -123,7 +123,7 @@ public:
size_t trackerResponseLength);
virtual void processUDPTrackerResponse
- (const SharedHandle<UDPTrackerRequest>& req);
+ (const std::shared_ptr<UDPTrackerRequest>& req);
virtual bool noMoreAnnounce();
@@ -136,7 +136,7 @@ public:
tcpPort_ = port;
}
- void setRandomizer(const SharedHandle<Randomizer>& randomizer);
+ void setRandomizer(const std::shared_ptr<Randomizer>& randomizer);
time_t getInterval() const
{
diff --git a/src/DefaultBtInteractive.cc b/src/DefaultBtInteractive.cc
index 42058c5f..61b8343d 100644
--- a/src/DefaultBtInteractive.cc
+++ b/src/DefaultBtInteractive.cc
@@ -77,8 +77,8 @@
namespace aria2 {
DefaultBtInteractive::DefaultBtInteractive
-(const SharedHandle<DownloadContext>& downloadContext,
- const SharedHandle<Peer>& peer)
+(const std::shared_ptr<DownloadContext>& downloadContext,
+ const std::shared_ptr<Peer>& peer)
: cuid_(0),
downloadContext_(downloadContext),
peer_(peer),
@@ -104,18 +104,18 @@ DefaultBtInteractive::DefaultBtInteractive
DefaultBtInteractive::~DefaultBtInteractive() {}
void DefaultBtInteractive::initiateHandshake() {
- SharedHandle<BtMessage> message =
+ std::shared_ptr<BtMessage> message =
messageFactory_->createHandshakeMessage
(bittorrent::getInfoHash(downloadContext_), bittorrent::getStaticPeerId());
dispatcher_->addMessageToQueue(message);
dispatcher_->sendMessages();
}
-SharedHandle<BtMessage> DefaultBtInteractive::receiveHandshake(bool quickReply) {
- SharedHandle<BtHandshakeMessage> message =
+std::shared_ptr<BtMessage> DefaultBtInteractive::receiveHandshake(bool quickReply) {
+ std::shared_ptr<BtHandshakeMessage> message =
btMessageReceiver_->receiveHandshake(quickReply);
if(!message) {
- return SharedHandle<BtMessage>();
+ return std::shared_ptr<BtMessage>();
}
if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(),
PEER_ID_LENGTH) == 0) {
@@ -158,7 +158,7 @@ SharedHandle<BtMessage> DefaultBtInteractive::receiveHandshake(bool quickReply)
return message;
}
-SharedHandle<BtMessage> DefaultBtInteractive::receiveAndSendHandshake() {
+std::shared_ptr<BtMessage> DefaultBtInteractive::receiveAndSendHandshake() {
return receiveHandshake(true);
}
@@ -191,16 +191,16 @@ void DefaultBtInteractive::addPortMessageToQueue()
void DefaultBtInteractive::addHandshakeExtendedMessageToQueue()
{
- SharedHandle<HandshakeExtensionMessage> m(new HandshakeExtensionMessage());
+ std::shared_ptr<HandshakeExtensionMessage> m(new HandshakeExtensionMessage());
m->setClientVersion("aria2/" PACKAGE_VERSION);
m->setTCPPort(tcpPort_);
m->setExtensions(extensionMessageRegistry_->getExtensions());
- SharedHandle<TorrentAttribute> attrs =
+ std::shared_ptr<TorrentAttribute> attrs =
bittorrent::getTorrentAttrs(downloadContext_);
if(!attrs->metadata.empty()) {
m->setMetadataSize(attrs->metadataSize);
}
- SharedHandle<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
+ std::shared_ptr<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
dispatcher_->addMessageToQueue(msg);
}
@@ -290,7 +290,7 @@ size_t DefaultBtInteractive::receiveMessages() {
downloadContext_->getOwnerRequestGroup()->doesDownloadSpeedExceed()) {
break;
}
- SharedHandle<BtMessage> message = btMessageReceiver_->receiveMessage();
+ std::shared_ptr<BtMessage> message = btMessageReceiver_->receiveMessage();
if(!message) {
break;
}
@@ -356,7 +356,7 @@ void DefaultBtInteractive::fillPiece(size_t maxMissingBlock) {
return;
}
size_t diffMissingBlock = maxMissingBlock-numMissingBlock;
- std::vector<SharedHandle<Piece> > pieces;
+ std::vector<std::shared_ptr<Piece> > pieces;
if(peer_->peerChoking()) {
if(peer_->isFastExtensionEnabled()) {
if(pieceStorage_->isEndGame()) {
@@ -383,7 +383,7 @@ void DefaultBtInteractive::fillPiece(size_t maxMissingBlock) {
pieceStorage_->getMissingPiece(pieces, diffMissingBlock, peer_, cuid_);
}
}
- for(std::vector<SharedHandle<Piece> >::const_iterator i =
+ for(std::vector<std::shared_ptr<Piece> >::const_iterator i =
pieces.begin(), eoi = pieces.end(); i != eoi; ++i) {
btRequestFactory_->addTargetPiece(*i);
}
@@ -400,7 +400,7 @@ void DefaultBtInteractive::addRequests() {
0 : maxOutstandingRequest_-dispatcher_->countOutstandingRequest();
if(reqNumToCreate > 0) {
- std::vector<SharedHandle<BtMessage> > requests;
+ std::vector<std::shared_ptr<BtMessage> > requests;
requests.reserve(reqNumToCreate);
if(pieceStorage_->isEndGame()) {
btRequestFactory_->createRequestMessagesOnEndGame(requests,reqNumToCreate);
@@ -481,7 +481,7 @@ void DefaultBtInteractive::addPeerExchangeMessage()
{
if(pexTimer_.
difference(global::wallclock()) >= UTPexExtensionMessage::DEFAULT_INTERVAL) {
- SharedHandle<UTPexExtensionMessage> m
+ std::shared_ptr<UTPexExtensionMessage> m
(new UTPexExtensionMessage(peer_->getExtensionMessageID
(ExtensionMessageRegistry::UT_PEX)));
@@ -492,9 +492,9 @@ void DefaultBtInteractive::addPeerExchangeMessage()
m->addFreshPeer(*i);
}
}
- const std::deque<SharedHandle<Peer> >& droppedPeers =
+ const std::deque<std::shared_ptr<Peer> >& droppedPeers =
peerStorage_->getDroppedPeers();
- for(std::deque<SharedHandle<Peer> >::const_iterator i =
+ for(std::deque<std::shared_ptr<Peer> >::const_iterator i =
droppedPeers.begin(), eoi = droppedPeers.end();
i != eoi && !m->droppedPeersAreFull();
++i) {
@@ -503,7 +503,7 @@ void DefaultBtInteractive::addPeerExchangeMessage()
}
}
- SharedHandle<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
+ std::shared_ptr<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
dispatcher_->addMessageToQueue(msg);
pexTimer_ = global::wallclock();
}
@@ -521,7 +521,7 @@ void DefaultBtInteractive::doInteractionProcessing() {
downloadContext_->getTotalLength() > 0) {
size_t num = utMetadataRequestTracker_->avail();
if(num > 0) {
- std::vector<SharedHandle<BtMessage> > requests;
+ std::vector<std::shared_ptr<BtMessage> > requests;
utMetadataRequestFactory_->create(requests, num, pieceStorage_);
dispatcher_->addMessageToQueue(requests);
}
@@ -596,60 +596,60 @@ size_t DefaultBtInteractive::countOutstandingRequest()
}
void DefaultBtInteractive::setBtRuntime
-(const SharedHandle<BtRuntime>& btRuntime)
+(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
void DefaultBtInteractive::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
void DefaultBtInteractive::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
-void DefaultBtInteractive::setPeer(const SharedHandle<Peer>& peer)
+void DefaultBtInteractive::setPeer(const std::shared_ptr<Peer>& peer)
{
peer_ = peer;
}
void DefaultBtInteractive::setBtMessageReceiver
-(const SharedHandle<BtMessageReceiver>& receiver)
+(const std::shared_ptr<BtMessageReceiver>& receiver)
{
btMessageReceiver_ = receiver;
}
void DefaultBtInteractive::setDispatcher
-(const SharedHandle<BtMessageDispatcher>& dispatcher)
+(const std::shared_ptr<BtMessageDispatcher>& dispatcher)
{
dispatcher_ = dispatcher;
}
void DefaultBtInteractive::setBtRequestFactory
-(const SharedHandle<BtRequestFactory>& factory)
+(const std::shared_ptr<BtRequestFactory>& factory)
{
btRequestFactory_ = factory;
}
void DefaultBtInteractive::setPeerConnection
-(const SharedHandle<PeerConnection>& peerConnection)
+(const std::shared_ptr<PeerConnection>& peerConnection)
{
peerConnection_ = peerConnection;
}
void DefaultBtInteractive::setExtensionMessageFactory
-(const SharedHandle<ExtensionMessageFactory>& factory)
+(const std::shared_ptr<ExtensionMessageFactory>& factory)
{
extensionMessageFactory_ = factory;
}
void DefaultBtInteractive::setBtMessageFactory
-(const SharedHandle<BtMessageFactory>& factory)
+(const std::shared_ptr<BtMessageFactory>& factory)
{
messageFactory_ = factory;
}
diff --git a/src/DefaultBtInteractive.h b/src/DefaultBtInteractive.h
index c96b8663..d64227d1 100644
--- a/src/DefaultBtInteractive.h
+++ b/src/DefaultBtInteractive.h
@@ -100,27 +100,27 @@ class DefaultBtInteractive : public BtInteractive {
private:
cuid_t cuid_;
- SharedHandle<DownloadContext> downloadContext_;
+ std::shared_ptr<DownloadContext> downloadContext_;
- SharedHandle<BtRuntime> btRuntime_;
+ std::shared_ptr<BtRuntime> btRuntime_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
- SharedHandle<BtMessageReceiver> btMessageReceiver_;
- SharedHandle<BtMessageDispatcher> dispatcher_;
- SharedHandle<BtRequestFactory> btRequestFactory_;
+ std::shared_ptr<BtMessageReceiver> btMessageReceiver_;
+ std::shared_ptr<BtMessageDispatcher> dispatcher_;
+ std::shared_ptr<BtRequestFactory> btRequestFactory_;
// Although peerStorage_ is not used in this class, this object
// holds the reference so that peerConnection_ is not deleted.
- SharedHandle<PeerConnection> peerConnection_;
- SharedHandle<BtMessageFactory> messageFactory_;
- SharedHandle<ExtensionMessageFactory> extensionMessageFactory_;
- SharedHandle<ExtensionMessageRegistry> extensionMessageRegistry_;
- SharedHandle<UTMetadataRequestFactory> utMetadataRequestFactory_;
- SharedHandle<UTMetadataRequestTracker> utMetadataRequestTracker_;
+ std::shared_ptr<PeerConnection> peerConnection_;
+ std::shared_ptr<BtMessageFactory> messageFactory_;
+ std::shared_ptr<ExtensionMessageFactory> extensionMessageFactory_;
+ std::shared_ptr<ExtensionMessageRegistry> extensionMessageRegistry_;
+ std::shared_ptr<UTMetadataRequestFactory> utMetadataRequestFactory_;
+ std::shared_ptr<UTMetadataRequestTracker> utMetadataRequestTracker_;
bool metadataGetMode_;
@@ -166,16 +166,16 @@ private:
void addPortMessageToQueue();
public:
- DefaultBtInteractive(const SharedHandle<DownloadContext>& downloadContext,
- const SharedHandle<Peer>& peer);
+ DefaultBtInteractive(const std::shared_ptr<DownloadContext>& downloadContext,
+ const std::shared_ptr<Peer>& peer);
virtual ~DefaultBtInteractive();
virtual void initiateHandshake();
- virtual SharedHandle<BtMessage> receiveHandshake(bool quickReply = false);
+ virtual std::shared_ptr<BtMessage> receiveHandshake(bool quickReply = false);
- virtual SharedHandle<BtMessage> receiveAndSendHandshake();
+ virtual std::shared_ptr<BtMessage> receiveAndSendHandshake();
virtual void doPostHandshakeProcessing();
@@ -200,29 +200,29 @@ public:
cuid_ = cuid;
}
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
- void setPeer(const SharedHandle<Peer>& peer);
+ void setPeer(const std::shared_ptr<Peer>& peer);
- void setBtMessageReceiver(const SharedHandle<BtMessageReceiver>& receiver);
+ void setBtMessageReceiver(const std::shared_ptr<BtMessageReceiver>& receiver);
- void setDispatcher(const SharedHandle<BtMessageDispatcher>& dispatcher);
+ void setDispatcher(const std::shared_ptr<BtMessageDispatcher>& dispatcher);
- void setBtRequestFactory(const SharedHandle<BtRequestFactory>& factory);
+ void setBtRequestFactory(const std::shared_ptr<BtRequestFactory>& factory);
- void setPeerConnection(const SharedHandle<PeerConnection>& peerConnection);
+ void setPeerConnection(const std::shared_ptr<PeerConnection>& peerConnection);
- void setBtMessageFactory(const SharedHandle<BtMessageFactory>& factory);
+ void setBtMessageFactory(const std::shared_ptr<BtMessageFactory>& factory);
void setExtensionMessageFactory
- (const SharedHandle<ExtensionMessageFactory>& factory);
+ (const std::shared_ptr<ExtensionMessageFactory>& factory);
void setExtensionMessageRegistry
- (const SharedHandle<ExtensionMessageRegistry>& registry)
+ (const std::shared_ptr<ExtensionMessageRegistry>& registry)
{
extensionMessageRegistry_ = registry;
}
@@ -246,13 +246,13 @@ public:
void setRequestGroupMan(RequestGroupMan* rgman);
void setUTMetadataRequestTracker
- (const SharedHandle<UTMetadataRequestTracker>& tracker)
+ (const std::shared_ptr<UTMetadataRequestTracker>& tracker)
{
utMetadataRequestTracker_ = tracker;
}
void setUTMetadataRequestFactory
- (const SharedHandle<UTMetadataRequestFactory>& factory)
+ (const std::shared_ptr<UTMetadataRequestFactory>& factory)
{
utMetadataRequestFactory_ = factory;
}
diff --git a/src/DefaultBtMessageDispatcher.cc b/src/DefaultBtMessageDispatcher.cc
index bc236350..ac7d4d8a 100644
--- a/src/DefaultBtMessageDispatcher.cc
+++ b/src/DefaultBtMessageDispatcher.cc
@@ -73,16 +73,16 @@ DefaultBtMessageDispatcher::~DefaultBtMessageDispatcher()
}
void DefaultBtMessageDispatcher::addMessageToQueue
-(const SharedHandle<BtMessage>& btMessage)
+(const std::shared_ptr<BtMessage>& btMessage)
{
btMessage->onQueued();
messageQueue_.push_back(btMessage);
}
void DefaultBtMessageDispatcher::addMessageToQueue
-(const std::vector<SharedHandle<BtMessage> >& btMessages)
+(const std::vector<std::shared_ptr<BtMessage> >& btMessages)
{
- for(std::vector<SharedHandle<BtMessage> >::const_iterator itr =
+ for(std::vector<std::shared_ptr<BtMessage> >::const_iterator itr =
btMessages.begin(), eoi = btMessages.end(); itr != eoi; ++itr) {
addMessageToQueue(*itr);
}
@@ -90,9 +90,9 @@ void DefaultBtMessageDispatcher::addMessageToQueue
void DefaultBtMessageDispatcher::sendMessagesInternal()
{
- std::vector<SharedHandle<BtMessage> > tempQueue;
+ std::vector<std::shared_ptr<BtMessage> > tempQueue;
while(!messageQueue_.empty()) {
- SharedHandle<BtMessage> msg = messageQueue_.front();
+ std::shared_ptr<BtMessage> msg = messageQueue_.front();
messageQueue_.pop_front();
if(msg->isUploading()) {
if(requestGroupMan_->doesOverallUploadSpeedExceed() ||
@@ -123,7 +123,7 @@ void DefaultBtMessageDispatcher::doCancelSendingPieceAction
{
BtCancelSendingPieceEvent event(index, begin, length);
- std::vector<SharedHandle<BtMessage> > tempQueue
+ std::vector<std::shared_ptr<BtMessage> > tempQueue
(messageQueue_.begin(), messageQueue_.end());
forEachMemFunSH(tempQueue.begin(), tempQueue.end(),
@@ -133,13 +133,13 @@ void DefaultBtMessageDispatcher::doCancelSendingPieceAction
// Cancel sending piece message to peer.
// TODO Is this method really necessary?
void DefaultBtMessageDispatcher::doCancelSendingPieceAction
-(const SharedHandle<Piece>& piece)
+(const std::shared_ptr<Piece>& piece)
{
}
namespace {
void abortOutstandingRequest
-(const RequestSlot& slot, const SharedHandle<Piece>& piece, cuid_t cuid)
+(const RequestSlot& slot, const std::shared_ptr<Piece>& piece, cuid_t cuid)
{
A2_LOG_DEBUG(fmt(MSG_DELETING_REQUEST_SLOT,
cuid,
@@ -163,7 +163,7 @@ struct FindRequestSlotByIndex {
// localhost cancels outstanding download requests to the peer.
void DefaultBtMessageDispatcher::doAbortOutstandingRequestAction
-(const SharedHandle<Piece>& piece) {
+(const std::shared_ptr<Piece>& piece) {
for(std::deque<RequestSlot>::iterator itr = requestSlots_.begin(),
eoi = requestSlots_.end(); itr != eoi; ++itr) {
if((*itr).getIndex() == piece->getIndex()) {
@@ -176,7 +176,7 @@ void DefaultBtMessageDispatcher::doAbortOutstandingRequestAction
BtAbortOutstandingRequestEvent event(piece);
- std::vector<SharedHandle<BtMessage> > tempQueue
+ std::vector<std::shared_ptr<BtMessage> > tempQueue
(messageQueue_.begin(), messageQueue_.end());
forEachMemFunSH(tempQueue.begin(), tempQueue.end(),
&BtMessage::onAbortOutstandingRequestEvent, event);
@@ -186,13 +186,13 @@ namespace {
class ProcessChokedRequestSlot {
private:
cuid_t cuid_;
- SharedHandle<Peer> peer_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<Peer> peer_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
public:
ProcessChokedRequestSlot
(cuid_t cuid,
- const SharedHandle<Peer>& peer,
- const SharedHandle<PieceStorage>& pieceStorage)
+ const std::shared_ptr<Peer>& peer,
+ const std::shared_ptr<PieceStorage>& pieceStorage)
: cuid_(cuid),
peer_(peer),
pieceStorage_(pieceStorage)
@@ -206,7 +206,7 @@ public:
static_cast<unsigned long>(slot.getIndex()),
slot.getBegin(),
static_cast<unsigned long>(slot.getBlockIndex())));
- SharedHandle<Piece> piece = pieceStorage_->getPiece(slot.getIndex());
+ std::shared_ptr<Piece> piece = pieceStorage_->getPiece(slot.getIndex());
piece->cancelBlock(slot.getBlockIndex());
}
}
@@ -217,9 +217,9 @@ public:
namespace {
class FindChokedRequestSlot {
private:
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
public:
- FindChokedRequestSlot(const SharedHandle<Peer>& peer):
+ FindChokedRequestSlot(const std::shared_ptr<Peer>& peer):
peer_(peer) {}
bool operator()(const RequestSlot& slot) const
@@ -245,7 +245,7 @@ void DefaultBtMessageDispatcher::doChokingAction()
{
BtChokingEvent event;
- std::vector<SharedHandle<BtMessage> > tempQueue
+ std::vector<std::shared_ptr<BtMessage> > tempQueue
(messageQueue_.begin(), messageQueue_.end());
forEachMemFunSH(tempQueue.begin(), tempQueue.end(),
&BtMessage::onChokingEvent, event);
@@ -255,15 +255,15 @@ namespace {
class ProcessStaleRequestSlot {
private:
cuid_t cuid_;
- SharedHandle<Peer> peer_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<Peer> peer_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
BtMessageDispatcher* messageDispatcher_;
BtMessageFactory* messageFactory_;
time_t requestTimeout_;
public:
ProcessStaleRequestSlot
- (cuid_t cuid, const SharedHandle<Peer>& peer,
- const SharedHandle<PieceStorage>& pieceStorage,
+ (cuid_t cuid, const std::shared_ptr<Peer>& peer,
+ const std::shared_ptr<PieceStorage>& pieceStorage,
BtMessageDispatcher* dispatcher,
BtMessageFactory* factory,
time_t requestTimeout)
@@ -303,10 +303,10 @@ public:
namespace {
class FindStaleRequestSlot {
private:
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
time_t requestTimeout_;
public:
- FindStaleRequestSlot(const SharedHandle<PieceStorage>& pieceStorage,
+ FindStaleRequestSlot(const std::shared_ptr<PieceStorage>& pieceStorage,
time_t requestTimeout):
pieceStorage_(pieceStorage),
requestTimeout_(requestTimeout) {}
@@ -411,25 +411,25 @@ size_t DefaultBtMessageDispatcher::countOutstandingUpload()
mem_fun_sh(&BtMessage::isUploading));
}
-void DefaultBtMessageDispatcher::setPeer(const SharedHandle<Peer>& peer)
+void DefaultBtMessageDispatcher::setPeer(const std::shared_ptr<Peer>& peer)
{
peer_ = peer;
}
void DefaultBtMessageDispatcher::setDownloadContext
-(const SharedHandle<DownloadContext>& downloadContext)
+(const std::shared_ptr<DownloadContext>& downloadContext)
{
downloadContext_ = downloadContext;
}
void DefaultBtMessageDispatcher::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
void DefaultBtMessageDispatcher::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
diff --git a/src/DefaultBtMessageDispatcher.h b/src/DefaultBtMessageDispatcher.h
index 7a8c44e1..96fefdf7 100644
--- a/src/DefaultBtMessageDispatcher.h
+++ b/src/DefaultBtMessageDispatcher.h
@@ -57,14 +57,14 @@ class PeerConnection;
class DefaultBtMessageDispatcher : public BtMessageDispatcher {
private:
cuid_t cuid_;
- std::deque<SharedHandle<BtMessage> > messageQueue_;
+ std::deque<std::shared_ptr<BtMessage> > messageQueue_;
std::deque<RequestSlot> requestSlots_;
- SharedHandle<DownloadContext> downloadContext_;
- SharedHandle<PeerStorage> peerStorage_;
- SharedHandle<PieceStorage> pieceStorage_;
- SharedHandle<PeerConnection> peerConnection_;
+ std::shared_ptr<DownloadContext> downloadContext_;
+ std::shared_ptr<PeerStorage> peerStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
+ std::shared_ptr<PeerConnection> peerConnection_;
BtMessageFactory* messageFactory_;
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
RequestGroupMan* requestGroupMan_;
time_t requestTimeout_;
public:
@@ -72,10 +72,10 @@ public:
virtual ~DefaultBtMessageDispatcher();
- virtual void addMessageToQueue(const SharedHandle<BtMessage>& btMessage);
+ virtual void addMessageToQueue(const std::shared_ptr<BtMessage>& btMessage);
virtual void addMessageToQueue
- (const std::vector<SharedHandle<BtMessage> >& btMessages);
+ (const std::vector<std::shared_ptr<BtMessage> >& btMessages);
virtual void sendMessages();
@@ -85,9 +85,9 @@ public:
virtual void doCancelSendingPieceAction
(size_t index, int32_t begin, int32_t length);
- virtual void doCancelSendingPieceAction(const SharedHandle<Piece>& piece);
+ virtual void doCancelSendingPieceAction(const std::shared_ptr<Piece>& piece);
- virtual void doAbortOutstandingRequestAction(const SharedHandle<Piece>& piece);
+ virtual void doAbortOutstandingRequestAction(const std::shared_ptr<Piece>& piece);
virtual void doChokedAction();
@@ -117,7 +117,7 @@ public:
virtual size_t countOutstandingUpload();
- const std::deque<SharedHandle<BtMessage> >& getMessageQueue() const
+ const std::deque<std::shared_ptr<BtMessage> >& getMessageQueue() const
{
return messageQueue_;
}
@@ -127,13 +127,13 @@ public:
return requestSlots_;
}
- void setPeer(const SharedHandle<Peer>& peer);
+ void setPeer(const std::shared_ptr<Peer>& peer);
- void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& downloadContext);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
void setBtMessageFactory(BtMessageFactory* factory);
@@ -149,7 +149,7 @@ public:
requestTimeout_ = requestTimeout;
}
- void setPeerConnection(const SharedHandle<PeerConnection>& peerConnection)
+ void setPeerConnection(const std::shared_ptr<PeerConnection>& peerConnection)
{
peerConnection_ = peerConnection;
}
diff --git a/src/DefaultBtMessageFactory.cc b/src/DefaultBtMessageFactory.cc
index e2666fa5..6abe6445 100644
--- a/src/DefaultBtMessageFactory.cc
+++ b/src/DefaultBtMessageFactory.cc
@@ -85,11 +85,11 @@ DefaultBtMessageFactory::DefaultBtMessageFactory():
DefaultBtMessageFactory::~DefaultBtMessageFactory() {}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createBtMessage
(const unsigned char* data, size_t dataLength)
{
- SharedHandle<AbstractBtMessage> msg;
+ std::shared_ptr<AbstractBtMessage> msg;
if(dataLength == 0) {
// keep-alive
msg.reset(new BtKeepAliveMessage());
@@ -120,7 +120,7 @@ DefaultBtMessageFactory::createBtMessage
case BtHaveMessage::ID:
msg.reset(BtHaveMessage::create(data, dataLength));
if(!metadataGetMode_) {
- SharedHandle<BtMessageValidator> v
+ std::shared_ptr<BtMessageValidator> v
(new IndexBtMessageValidator(static_cast<BtHaveMessage*>(msg.get()),
downloadContext_->getNumPieces()));
msg->setBtMessageValidator(v);
@@ -129,7 +129,7 @@ DefaultBtMessageFactory::createBtMessage
case BtBitfieldMessage::ID:
msg.reset(BtBitfieldMessage::create(data, dataLength));
if(!metadataGetMode_) {
- SharedHandle<BtMessageValidator> v
+ std::shared_ptr<BtMessageValidator> v
(new BtBitfieldMessageValidator
(static_cast<BtBitfieldMessage*>(msg.get()),
downloadContext_->getNumPieces()));
@@ -139,7 +139,7 @@ DefaultBtMessageFactory::createBtMessage
case BtRequestMessage::ID: {
BtRequestMessage* m = BtRequestMessage::create(data, dataLength);
if(!metadataGetMode_) {
- SharedHandle<BtMessageValidator> validator
+ std::shared_ptr<BtMessageValidator> validator
(new RangeBtMessageValidator
(m,
downloadContext_->getNumPieces(),
@@ -152,7 +152,7 @@ DefaultBtMessageFactory::createBtMessage
case BtCancelMessage::ID: {
BtCancelMessage* m = BtCancelMessage::create(data, dataLength);
if(!metadataGetMode_) {
- SharedHandle<BtMessageValidator> validator
+ std::shared_ptr<BtMessageValidator> validator
(new RangeBtMessageValidator
(m,
downloadContext_->getNumPieces(),
@@ -165,7 +165,7 @@ DefaultBtMessageFactory::createBtMessage
case BtPieceMessage::ID: {
BtPieceMessage* m = BtPieceMessage::create(data, dataLength);
if(!metadataGetMode_) {
- SharedHandle<BtMessageValidator> validator
+ std::shared_ptr<BtMessageValidator> validator
(new BtPieceMessageValidator
(m,
downloadContext_->getNumPieces(),
@@ -186,7 +186,7 @@ DefaultBtMessageFactory::createBtMessage
case BtRejectMessage::ID: {
BtRejectMessage* m = BtRejectMessage::create(data, dataLength);
if(!metadataGetMode_) {
- SharedHandle<BtMessageValidator> validator
+ std::shared_ptr<BtMessageValidator> validator
(new RangeBtMessageValidator
(m,
downloadContext_->getNumPieces(),
@@ -200,7 +200,7 @@ DefaultBtMessageFactory::createBtMessage
BtSuggestPieceMessage* m =
BtSuggestPieceMessage::create(data, dataLength);
if(!metadataGetMode_) {
- SharedHandle<BtMessageValidator> validator
+ std::shared_ptr<BtMessageValidator> validator
(new IndexBtMessageValidator(m, downloadContext_->getNumPieces()));
m->setBtMessageValidator(validator);
}
@@ -210,7 +210,7 @@ DefaultBtMessageFactory::createBtMessage
case BtAllowedFastMessage::ID: {
BtAllowedFastMessage* m = BtAllowedFastMessage::create(data, dataLength);
if(!metadataGetMode_) {
- SharedHandle<BtMessageValidator> validator
+ std::shared_ptr<BtMessageValidator> validator
(new IndexBtMessageValidator(m, downloadContext_->getNumPieces()));
m->setBtMessageValidator(validator);
}
@@ -258,13 +258,13 @@ void DefaultBtMessageFactory::setCommonProperty(AbstractBtMessage* msg)
}
}
-SharedHandle<BtHandshakeMessage>
+std::shared_ptr<BtHandshakeMessage>
DefaultBtMessageFactory::createHandshakeMessage
(const unsigned char* data, size_t dataLength)
{
- SharedHandle<BtHandshakeMessage> msg =
+ std::shared_ptr<BtHandshakeMessage> msg =
BtHandshakeMessage::create(data, dataLength);
- SharedHandle<BtMessageValidator> validator
+ std::shared_ptr<BtMessageValidator> validator
(new BtHandshakeMessageValidator
(msg.get(), bittorrent::getInfoHash(downloadContext_)));
msg->setBtMessageValidator(validator);
@@ -272,20 +272,20 @@ DefaultBtMessageFactory::createHandshakeMessage
return msg;
}
-SharedHandle<BtHandshakeMessage>
+std::shared_ptr<BtHandshakeMessage>
DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* infoHash,
const unsigned char* peerId)
{
- SharedHandle<BtHandshakeMessage> msg
+ std::shared_ptr<BtHandshakeMessage> msg
(new BtHandshakeMessage(infoHash, peerId));
msg->setDHTEnabled(dhtEnabled_);
setCommonProperty(msg.get());
return msg;
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createRequestMessage
-(const SharedHandle<Piece>& piece, size_t blockIndex)
+(const std::shared_ptr<Piece>& piece, size_t blockIndex)
{
BtRequestMessage* msg
(new BtRequestMessage(piece->getIndex(),
@@ -293,134 +293,134 @@ DefaultBtMessageFactory::createRequestMessage
piece->getBlockLength(blockIndex),
blockIndex));
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createCancelMessage
(size_t index, int32_t begin, int32_t length)
{
BtCancelMessage* msg(new BtCancelMessage(index, begin, length));
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createPieceMessage
(size_t index, int32_t begin, int32_t length)
{
BtPieceMessage* msg(new BtPieceMessage(index, begin, length));
msg->setDownloadContext(downloadContext_);
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createHaveMessage(size_t index)
{
BtHaveMessage* msg(new BtHaveMessage(index));
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createChokeMessage()
{
BtChokeMessage* msg(new BtChokeMessage());
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createUnchokeMessage()
{
BtUnchokeMessage* msg(new BtUnchokeMessage());
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createInterestedMessage()
{
BtInterestedMessage* msg(new BtInterestedMessage());
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createNotInterestedMessage()
{
BtNotInterestedMessage* msg(new BtNotInterestedMessage());
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createBitfieldMessage()
{
BtBitfieldMessage* msg
(new BtBitfieldMessage(pieceStorage_->getBitfield(),
pieceStorage_->getBitfieldLength()));
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createKeepAliveMessage()
{
BtKeepAliveMessage* msg(new BtKeepAliveMessage());
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createHaveAllMessage()
{
BtHaveAllMessage* msg(new BtHaveAllMessage());
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createHaveNoneMessage()
{
BtHaveNoneMessage* msg(new BtHaveNoneMessage());
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createRejectMessage
(size_t index, int32_t begin, int32_t length)
{
BtRejectMessage* msg(new BtRejectMessage(index, begin, length));
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createAllowedFastMessage(size_t index)
{
BtAllowedFastMessage* msg(new BtAllowedFastMessage(index));
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createPortMessage(uint16_t port)
{
BtPortMessage* msg(new BtPortMessage(port));
setCommonProperty(msg);
- return SharedHandle<BtMessage>(msg);
+ return std::shared_ptr<BtMessage>(msg);
}
-SharedHandle<BtMessage>
+std::shared_ptr<BtMessage>
DefaultBtMessageFactory::createBtExtendedMessage
-(const SharedHandle<ExtensionMessage>& msg)
+(const std::shared_ptr<ExtensionMessage>& msg)
{
BtExtendedMessage* m(new BtExtendedMessage(msg));
setCommonProperty(m);
- return SharedHandle<BtMessage>(m);
+ return std::shared_ptr<BtMessage>(m);
}
void DefaultBtMessageFactory::setTaskQueue(DHTTaskQueue* taskQueue)
@@ -433,25 +433,25 @@ void DefaultBtMessageFactory::setTaskFactory(DHTTaskFactory* taskFactory)
taskFactory_ = taskFactory;
}
-void DefaultBtMessageFactory::setPeer(const SharedHandle<Peer>& peer)
+void DefaultBtMessageFactory::setPeer(const std::shared_ptr<Peer>& peer)
{
peer_ = peer;
}
void DefaultBtMessageFactory::setDownloadContext
-(const SharedHandle<DownloadContext>& downloadContext)
+(const std::shared_ptr<DownloadContext>& downloadContext)
{
downloadContext_ = downloadContext;
}
void DefaultBtMessageFactory::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
void DefaultBtMessageFactory::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
@@ -463,7 +463,7 @@ void DefaultBtMessageFactory::setBtMessageDispatcher
}
void DefaultBtMessageFactory::setExtensionMessageFactory
-(const SharedHandle<ExtensionMessageFactory>& factory)
+(const std::shared_ptr<ExtensionMessageFactory>& factory)
{
extensionMessageFactory_ = factory;
}
diff --git a/src/DefaultBtMessageFactory.h b/src/DefaultBtMessageFactory.h
index c6875e6d..df9c08d7 100644
--- a/src/DefaultBtMessageFactory.h
+++ b/src/DefaultBtMessageFactory.h
@@ -57,10 +57,10 @@ class DHTTaskFactory;
class DefaultBtMessageFactory : public BtMessageFactory {
private:
cuid_t cuid_;
- SharedHandle<DownloadContext> downloadContext_;
- SharedHandle<PieceStorage> pieceStorage_;
- SharedHandle<PeerStorage> peerStorage_;
- SharedHandle<Peer> peer_;
+ std::shared_ptr<DownloadContext> downloadContext_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
+ std::shared_ptr<Peer> peer_;
bool dhtEnabled_;
@@ -70,7 +70,7 @@ private:
PeerConnection* peerConnection_;
- SharedHandle<ExtensionMessageFactory> extensionMessageFactory_;
+ std::shared_ptr<ExtensionMessageFactory> extensionMessageFactory_;
DHTNode* localNode_;
@@ -88,60 +88,60 @@ public:
virtual ~DefaultBtMessageFactory();
- virtual SharedHandle<BtMessage>
+ virtual std::shared_ptr<BtMessage>
createBtMessage(const unsigned char* msg, size_t msgLength);
- virtual SharedHandle<BtHandshakeMessage>
+ virtual std::shared_ptr<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* msg, size_t msgLength);
- virtual SharedHandle<BtHandshakeMessage>
+ virtual std::shared_ptr<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* infoHash,
const unsigned char* peerId);
- virtual SharedHandle<BtMessage>
- createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex);
+ virtual std::shared_ptr<BtMessage>
+ createRequestMessage(const std::shared_ptr<Piece>& piece, size_t blockIndex);
- virtual SharedHandle<BtMessage>
+ virtual std::shared_ptr<BtMessage>
createCancelMessage(size_t index, int32_t begin, int32_t length);
- virtual SharedHandle<BtMessage>
+ virtual std::shared_ptr<BtMessage>
createPieceMessage(size_t index, int32_t begin, int32_t length);
- virtual SharedHandle<BtMessage> createHaveMessage(size_t index);
+ virtual std::shared_ptr<BtMessage> createHaveMessage(size_t index);
- virtual SharedHandle<BtMessage> createChokeMessage();
+ virtual std::shared_ptr<BtMessage> createChokeMessage();
- virtual SharedHandle<BtMessage> createUnchokeMessage();
+ virtual std::shared_ptr<BtMessage> createUnchokeMessage();
- virtual SharedHandle<BtMessage> createInterestedMessage();
+ virtual std::shared_ptr<BtMessage> createInterestedMessage();
- virtual SharedHandle<BtMessage> createNotInterestedMessage();
+ virtual std::shared_ptr<BtMessage> createNotInterestedMessage();
- virtual SharedHandle<BtMessage> createBitfieldMessage();
+ virtual std::shared_ptr<BtMessage> createBitfieldMessage();
- virtual SharedHandle<BtMessage> createKeepAliveMessage();
+ virtual std::shared_ptr<BtMessage> createKeepAliveMessage();
- virtual SharedHandle<BtMessage> createHaveAllMessage();
+ virtual std::shared_ptr<BtMessage> createHaveAllMessage();
- virtual SharedHandle<BtMessage> createHaveNoneMessage();
+ virtual std::shared_ptr<BtMessage> createHaveNoneMessage();
- virtual SharedHandle<BtMessage>
+ virtual std::shared_ptr<BtMessage>
createRejectMessage(size_t index, int32_t begin, int32_t length);
- virtual SharedHandle<BtMessage> createAllowedFastMessage(size_t index);
+ virtual std::shared_ptr<BtMessage> createAllowedFastMessage(size_t index);
- virtual SharedHandle<BtMessage> createPortMessage(uint16_t port);
+ virtual std::shared_ptr<BtMessage> createPortMessage(uint16_t port);
- virtual SharedHandle<BtMessage>
- createBtExtendedMessage(const SharedHandle<ExtensionMessage>& msg);
+ virtual std::shared_ptr<BtMessage>
+ createBtExtendedMessage(const std::shared_ptr<ExtensionMessage>& msg);
- void setPeer(const SharedHandle<Peer>& peer);
+ void setPeer(const std::shared_ptr<Peer>& peer);
- void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& downloadContext);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
void setCuid(cuid_t cuid)
{
@@ -160,7 +160,7 @@ public:
void setPeerConnection(PeerConnection* connection);
void setExtensionMessageFactory
- (const SharedHandle<ExtensionMessageFactory>& factory);
+ (const std::shared_ptr<ExtensionMessageFactory>& factory);
void setLocalNode(DHTNode* localNode);
diff --git a/src/DefaultBtMessageReceiver.cc b/src/DefaultBtMessageReceiver.cc
index ae406657..1e90f016 100644
--- a/src/DefaultBtMessageReceiver.cc
+++ b/src/DefaultBtMessageReceiver.cc
@@ -60,7 +60,7 @@ DefaultBtMessageReceiver::DefaultBtMessageReceiver():
messageFactory_(0)
{}
-SharedHandle<BtHandshakeMessage>
+std::shared_ptr<BtHandshakeMessage>
DefaultBtMessageReceiver::receiveHandshake(bool quickReply)
{
A2_LOG_DEBUG
@@ -68,7 +68,7 @@ DefaultBtMessageReceiver::receiveHandshake(bool quickReply)
static_cast<unsigned long>(peerConnection_->getBufferLength())));
unsigned char data[BtHandshakeMessage::MESSAGE_LENGTH];
size_t dataLength = BtHandshakeMessage::MESSAGE_LENGTH;
- SharedHandle<BtHandshakeMessage> msg;
+ std::shared_ptr<BtHandshakeMessage> msg;
if(handshakeSent_ || !quickReply || peerConnection_->getBufferLength() < 48) {
if(peerConnection_->receiveHandshake(data, dataLength)) {
msg = messageFactory_->createHandshakeMessage(data, dataLength);
@@ -100,40 +100,39 @@ DefaultBtMessageReceiver::receiveHandshake(bool quickReply)
return msg;
}
-SharedHandle<BtHandshakeMessage>
+std::shared_ptr<BtHandshakeMessage>
DefaultBtMessageReceiver::receiveAndSendHandshake()
{
return receiveHandshake(true);
}
void DefaultBtMessageReceiver::sendHandshake() {
- SharedHandle<BtMessage> msg =
+ std::shared_ptr<BtMessage> msg =
messageFactory_->createHandshakeMessage
(bittorrent::getInfoHash(downloadContext_), bittorrent::getStaticPeerId());
dispatcher_->addMessageToQueue(msg);
dispatcher_->sendMessages();
}
-SharedHandle<BtMessage> DefaultBtMessageReceiver::receiveMessage() {
+std::shared_ptr<BtMessage> DefaultBtMessageReceiver::receiveMessage() {
size_t dataLength = 0;
// Give 0 to PeerConnection::receiveMessage() to prevent memcpy.
if(!peerConnection_->receiveMessage(0, dataLength)) {
- return SharedHandle<BtMessage>();
+ return std::shared_ptr<BtMessage>();
}
- SharedHandle<BtMessage> msg =
+ std::shared_ptr<BtMessage> msg =
messageFactory_->createBtMessage(peerConnection_->getMsgPayloadBuffer(),
dataLength);
msg->validate();
if(msg->getId() == BtPieceMessage::ID) {
- SharedHandle<BtPieceMessage> piecemsg =
- static_pointer_cast<BtPieceMessage>(msg);
+ auto piecemsg = std::static_pointer_cast<BtPieceMessage>(msg);
piecemsg->setMsgPayload(peerConnection_->getMsgPayloadBuffer());
}
return msg;
}
void DefaultBtMessageReceiver::setDownloadContext
-(const SharedHandle<DownloadContext>& downloadContext)
+(const std::shared_ptr<DownloadContext>& downloadContext)
{
downloadContext_ = downloadContext;
}
diff --git a/src/DefaultBtMessageReceiver.h b/src/DefaultBtMessageReceiver.h
index 05a0b07d..5624545a 100644
--- a/src/DefaultBtMessageReceiver.h
+++ b/src/DefaultBtMessageReceiver.h
@@ -49,7 +49,7 @@ class BtMessageFactory;
class DefaultBtMessageReceiver : public BtMessageReceiver {
private:
bool handshakeSent_;
- SharedHandle<DownloadContext> downloadContext_;
+ std::shared_ptr<DownloadContext> downloadContext_;
PeerConnection* peerConnection_;
BtMessageDispatcher* dispatcher_;
BtMessageFactory* messageFactory_;
@@ -58,14 +58,14 @@ private:
public:
DefaultBtMessageReceiver();
- virtual SharedHandle<BtHandshakeMessage> receiveHandshake
+ virtual std::shared_ptr<BtHandshakeMessage> receiveHandshake
(bool quickReply = false);
- virtual SharedHandle<BtHandshakeMessage> receiveAndSendHandshake();
+ virtual std::shared_ptr<BtHandshakeMessage> receiveAndSendHandshake();
- virtual SharedHandle<BtMessage> receiveMessage();
+ virtual std::shared_ptr<BtMessage> receiveMessage();
- void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& downloadContext);
void setPeerConnection(PeerConnection* peerConnection);
diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc
index 44d9939a..5f5c2ca9 100644
--- a/src/DefaultBtProgressInfoFile.cc
+++ b/src/DefaultBtProgressInfoFile.cc
@@ -65,7 +65,7 @@ namespace aria2 {
namespace {
std::string createFilename
-(const SharedHandle<DownloadContext>& dctx, const std::string& suffix)
+(const std::shared_ptr<DownloadContext>& dctx, const std::string& suffix)
{
std::string t = dctx->getBasePath();
t += suffix;
@@ -74,8 +74,8 @@ std::string createFilename
} // namespace
DefaultBtProgressInfoFile::DefaultBtProgressInfoFile
-(const SharedHandle<DownloadContext>& dctx,
- const SharedHandle<PieceStorage>& pieceStorage,
+(const std::shared_ptr<DownloadContext>& dctx,
+ const std::shared_ptr<PieceStorage>& pieceStorage,
const Option* option)
: dctx_(dctx),
pieceStorage_(pieceStorage),
@@ -93,7 +93,7 @@ void DefaultBtProgressInfoFile::updateFilename()
bool DefaultBtProgressInfoFile::isTorrentDownload()
{
#ifdef ENABLE_BITTORRENT
- return btRuntime_;
+ return btRuntime_.get();
#else // !ENABLE_BITTORRENT
return false;
#endif // !ENABLE_BITTORRENT
@@ -174,10 +174,10 @@ void DefaultBtProgressInfoFile::save()
// TODO implement this
uint32_t numInFlightPieceNL = htonl(pieceStorage_->countInFlightPiece());
WRITE_CHECK(fp, &numInFlightPieceNL, sizeof(numInFlightPieceNL));
- std::vector<SharedHandle<Piece> > inFlightPieces;
+ std::vector<std::shared_ptr<Piece> > inFlightPieces;
inFlightPieces.reserve(pieceStorage_->countInFlightPiece());
pieceStorage_->getInFlightPieces(inFlightPieces);
- for(std::vector<SharedHandle<Piece> >::const_iterator itr =
+ for(std::vector<std::shared_ptr<Piece> >::const_iterator itr =
inFlightPieces.begin(), eoi = inFlightPieces.end();
itr != eoi; ++itr) {
uint32_t indexNL = htonl((*itr)->getIndex());
@@ -313,7 +313,7 @@ void DefaultBtProgressInfoFile::load()
if(version >= 1) {
numInFlightPiece = ntohl(numInFlightPiece);
}
- std::vector<SharedHandle<Piece> > inFlightPieces;
+ std::vector<std::shared_ptr<Piece> > inFlightPieces;
inFlightPieces.reserve(numInFlightPiece);
while(numInFlightPiece--) {
uint32_t index;
@@ -332,7 +332,7 @@ void DefaultBtProgressInfoFile::load()
if(!(length <= static_cast<uint32_t>(dctx_->getPieceLength()))) {
throw DL_ABORT_EX(fmt("piece length out of range: %u", length));
}
- SharedHandle<Piece> piece(new Piece(index, length));
+ std::shared_ptr<Piece> piece(new Piece(index, length));
uint32_t bitfieldLength;
READ_CHECK(fp, &bitfieldLength, sizeof(bitfieldLength));
if(version >= 1) {
@@ -405,13 +405,13 @@ bool DefaultBtProgressInfoFile::exists()
#ifdef ENABLE_BITTORRENT
void DefaultBtProgressInfoFile::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
void DefaultBtProgressInfoFile::setBtRuntime
-(const SharedHandle<BtRuntime>& btRuntime)
+(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
diff --git a/src/DefaultBtProgressInfoFile.h b/src/DefaultBtProgressInfoFile.h
index f81a2fae..5c821d77 100644
--- a/src/DefaultBtProgressInfoFile.h
+++ b/src/DefaultBtProgressInfoFile.h
@@ -36,7 +36,8 @@
#define D_DEFAULT_BT_PROGRESS_INFO_FILE_H
#include "BtProgressInfoFile.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -48,19 +49,19 @@ class Option;
class DefaultBtProgressInfoFile : public BtProgressInfoFile {
private:
- SharedHandle<DownloadContext> dctx_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<DownloadContext> dctx_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
#ifdef ENABLE_BITTORRENT
- SharedHandle<PeerStorage> peerStorage_;
- SharedHandle<BtRuntime> btRuntime_;
+ std::shared_ptr<PeerStorage> peerStorage_;
+ std::shared_ptr<BtRuntime> btRuntime_;
#endif // ENABLE_BITTORRENT
const Option* option_;
std::string filename_;
bool isTorrentDownload();
public:
- DefaultBtProgressInfoFile(const SharedHandle<DownloadContext>& btContext,
- const SharedHandle<PieceStorage>& pieceStorage,
+ DefaultBtProgressInfoFile(const std::shared_ptr<DownloadContext>& btContext,
+ const std::shared_ptr<PieceStorage>& pieceStorage,
const Option* option);
virtual ~DefaultBtProgressInfoFile();
@@ -80,9 +81,9 @@ public:
#ifdef ENABLE_BITTORRENT
// for torrents
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
#endif // ENABLE_BITTORRENT
static const std::string& getSuffix()
diff --git a/src/DefaultBtRequestFactory.cc b/src/DefaultBtRequestFactory.cc
index e10b2e60..449afba7 100644
--- a/src/DefaultBtRequestFactory.cc
+++ b/src/DefaultBtRequestFactory.cc
@@ -59,7 +59,7 @@ DefaultBtRequestFactory::DefaultBtRequestFactory()
DefaultBtRequestFactory::~DefaultBtRequestFactory() {}
-void DefaultBtRequestFactory::addTargetPiece(const SharedHandle<Piece>& piece)
+void DefaultBtRequestFactory::addTargetPiece(const std::shared_ptr<Piece>& piece)
{
pieces_.push_back(piece);
}
@@ -73,7 +73,7 @@ public:
AbortCompletedPieceRequest(BtMessageDispatcher* dispatcher):
dispatcher_(dispatcher) {}
- void operator()(const SharedHandle<Piece>& piece)
+ void operator()(const std::shared_ptr<Piece>& piece)
{
if(piece->pieceComplete()) {
dispatcher_->doAbortOutstandingRequestAction(piece);
@@ -91,7 +91,7 @@ void DefaultBtRequestFactory::removeCompletedPiece() {
}
void DefaultBtRequestFactory::removeTargetPiece
-(const SharedHandle<Piece>& piece)
+(const std::shared_ptr<Piece>& piece)
{
pieces_.erase(std::remove_if(pieces_.begin(), pieces_.end(),
derefEqual(piece)),
@@ -103,19 +103,19 @@ void DefaultBtRequestFactory::removeTargetPiece
namespace {
class ProcessChokedPiece {
private:
- SharedHandle<Peer> peer_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<Peer> peer_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
cuid_t cuid_;
public:
- ProcessChokedPiece(const SharedHandle<Peer>& peer,
- const SharedHandle<PieceStorage>& pieceStorage,
+ ProcessChokedPiece(const std::shared_ptr<Peer>& peer,
+ const std::shared_ptr<PieceStorage>& pieceStorage,
cuid_t cuid):
peer_(peer),
pieceStorage_(pieceStorage),
cuid_(cuid)
{}
- void operator()(const SharedHandle<Piece>& piece)
+ void operator()(const std::shared_ptr<Piece>& piece)
{
if(!peer_->isInPeerAllowedIndexSet(piece->getIndex())) {
pieceStorage_->cancelPiece(piece, cuid_);
@@ -127,11 +127,11 @@ public:
namespace {
class FindChokedPiece {
private:
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
public:
- FindChokedPiece(const SharedHandle<Peer>& peer):peer_(peer) {}
+ FindChokedPiece(const std::shared_ptr<Peer>& peer):peer_(peer) {}
- bool operator()(const SharedHandle<Piece>& piece)
+ bool operator()(const std::shared_ptr<Piece>& piece)
{
return !peer_->isInPeerAllowedIndexSet(piece->getIndex());
}
@@ -148,7 +148,7 @@ void DefaultBtRequestFactory::doChokedAction()
}
void DefaultBtRequestFactory::removeAllTargetPiece() {
- for(std::deque<SharedHandle<Piece> >::iterator itr = pieces_.begin(),
+ for(std::deque<std::shared_ptr<Piece> >::iterator itr = pieces_.begin(),
eoi = pieces_.end(); itr != eoi; ++itr) {
dispatcher_->doAbortOutstandingRequestAction(*itr);
pieceStorage_->cancelPiece(*itr, cuid_);
@@ -157,7 +157,7 @@ void DefaultBtRequestFactory::removeAllTargetPiece() {
}
void DefaultBtRequestFactory::createRequestMessages
-(std::vector<SharedHandle<BtMessage> >& requests, size_t max)
+(std::vector<std::shared_ptr<BtMessage> >& requests, size_t max)
{
if(requests.size() >= max) {
return;
@@ -165,9 +165,9 @@ void DefaultBtRequestFactory::createRequestMessages
size_t getnum = max-requests.size();
std::vector<size_t> blockIndexes;
blockIndexes.reserve(getnum);
- for(std::deque<SharedHandle<Piece> >::iterator itr = pieces_.begin(),
+ for(std::deque<std::shared_ptr<Piece> >::iterator itr = pieces_.begin(),
eoi = pieces_.end(); itr != eoi && getnum; ++itr) {
- SharedHandle<Piece>& piece = *itr;
+ std::shared_ptr<Piece>& piece = *itr;
if(piece->getMissingUnusedBlockIndex(blockIndexes, getnum)) {
getnum -= blockIndexes.size();
for(std::vector<size_t>::const_iterator i = blockIndexes.begin(),
@@ -187,11 +187,11 @@ void DefaultBtRequestFactory::createRequestMessages
}
void DefaultBtRequestFactory::createRequestMessagesOnEndGame
-(std::vector<SharedHandle<BtMessage> >& requests, size_t max)
+(std::vector<std::shared_ptr<BtMessage> >& requests, size_t max)
{
- for(std::deque<SharedHandle<Piece> >::iterator itr = pieces_.begin(),
+ for(std::deque<std::shared_ptr<Piece> >::iterator itr = pieces_.begin(),
eoi = pieces_.end(); itr != eoi && requests.size() < max; ++itr) {
- SharedHandle<Piece>& piece = *itr;
+ std::shared_ptr<Piece>& piece = *itr;
const size_t mislen = piece->getBitfieldLength();
array_ptr<unsigned char> misbitfield(new unsigned char[mislen]);
@@ -242,7 +242,7 @@ public:
return numMissingBlock_;
}
- void operator()(const SharedHandle<Piece>& piece)
+ void operator()(const std::shared_ptr<Piece>& piece)
{
numMissingBlock_ += piece->countMissingBlock();
}
@@ -263,12 +263,12 @@ void DefaultBtRequestFactory::getTargetPieceIndexes
}
void DefaultBtRequestFactory::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
-void DefaultBtRequestFactory::setPeer(const SharedHandle<Peer>& peer)
+void DefaultBtRequestFactory::setPeer(const std::shared_ptr<Peer>& peer)
{
peer_ = peer;
}
diff --git a/src/DefaultBtRequestFactory.h b/src/DefaultBtRequestFactory.h
index 33534085..d845da70 100644
--- a/src/DefaultBtRequestFactory.h
+++ b/src/DefaultBtRequestFactory.h
@@ -51,20 +51,20 @@ class Piece;
class DefaultBtRequestFactory : public BtRequestFactory {
private:
- SharedHandle<PieceStorage> pieceStorage_;
- SharedHandle<Peer> peer_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
+ std::shared_ptr<Peer> peer_;
BtMessageDispatcher* dispatcher_;
BtMessageFactory* messageFactory_;
- std::deque<SharedHandle<Piece> > pieces_;
+ std::deque<std::shared_ptr<Piece> > pieces_;
cuid_t cuid_;
public:
DefaultBtRequestFactory();
virtual ~DefaultBtRequestFactory();
- virtual void addTargetPiece(const SharedHandle<Piece>& piece);
+ virtual void addTargetPiece(const std::shared_ptr<Piece>& piece);
- virtual void removeTargetPiece(const SharedHandle<Piece>& piece);
+ virtual void removeTargetPiece(const std::shared_ptr<Piece>& piece);
virtual void removeAllTargetPiece();
@@ -79,21 +79,21 @@ public:
virtual void doChokedAction();
virtual void createRequestMessages
- (std::vector<SharedHandle<BtMessage> >& requests, size_t max);
+ (std::vector<std::shared_ptr<BtMessage> >& requests, size_t max);
virtual void createRequestMessagesOnEndGame
- (std::vector<SharedHandle<BtMessage> >& requests, size_t max);
+ (std::vector<std::shared_ptr<BtMessage> >& requests, size_t max);
virtual void getTargetPieceIndexes(std::vector<size_t>& indexes) const;
- std::deque<SharedHandle<Piece> >& getTargetPieces()
+ std::deque<std::shared_ptr<Piece> >& getTargetPieces()
{
return pieces_;
}
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
- void setPeer(const SharedHandle<Peer>& peer);
+ void setPeer(const std::shared_ptr<Peer>& peer);
void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);
diff --git a/src/DefaultDiskWriterFactory.cc b/src/DefaultDiskWriterFactory.cc
index 7107eae8..b2bd9be2 100644
--- a/src/DefaultDiskWriterFactory.cc
+++ b/src/DefaultDiskWriterFactory.cc
@@ -37,10 +37,10 @@
namespace aria2 {
-SharedHandle<DiskWriter> DefaultDiskWriterFactory::newDiskWriter
+std::shared_ptr<DiskWriter> DefaultDiskWriterFactory::newDiskWriter
(const std::string& filename)
{
- return SharedHandle<DiskWriter>(new DefaultDiskWriter(filename));
+ return std::shared_ptr<DiskWriter>(new DefaultDiskWriter(filename));
}
} // namespace aria2
diff --git a/src/DefaultDiskWriterFactory.h b/src/DefaultDiskWriterFactory.h
index b321d7d1..f13f07e9 100644
--- a/src/DefaultDiskWriterFactory.h
+++ b/src/DefaultDiskWriterFactory.h
@@ -44,7 +44,7 @@ class DiskWriter;
class DefaultDiskWriterFactory:public DiskWriterFactory
{
public:
- virtual SharedHandle<DiskWriter> newDiskWriter(const std::string& filename);
+ virtual std::shared_ptr<DiskWriter> newDiskWriter(const std::string& filename);
};
} // namespace aria2
diff --git a/src/DefaultExtensionMessageFactory.cc b/src/DefaultExtensionMessageFactory.cc
index fc37a3b9..202b1ca4 100644
--- a/src/DefaultExtensionMessageFactory.cc
+++ b/src/DefaultExtensionMessageFactory.cc
@@ -64,8 +64,8 @@ DefaultExtensionMessageFactory::DefaultExtensionMessageFactory()
{}
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory
-(const SharedHandle<Peer>& peer,
- const SharedHandle<ExtensionMessageRegistry>& registry)
+(const std::shared_ptr<Peer>& peer,
+ const std::shared_ptr<ExtensionMessageRegistry>& registry)
: peer_(peer),
registry_(registry),
messageFactory_(0),
@@ -75,7 +75,7 @@ DefaultExtensionMessageFactory::DefaultExtensionMessageFactory
DefaultExtensionMessageFactory::~DefaultExtensionMessageFactory() {}
-SharedHandle<ExtensionMessage>
+std::shared_ptr<ExtensionMessage>
DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t length)
{
uint8_t extensionMessageID = *data;
@@ -85,7 +85,7 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
HandshakeExtensionMessage::create(data, length);
m->setPeer(peer_);
m->setDownloadContext(dctx_);
- return SharedHandle<ExtensionMessage>(m);
+ return std::shared_ptr<ExtensionMessage>(m);
} else {
const char* extensionName = registry_->getExtensionName(extensionMessageID);
if(!extensionName) {
@@ -97,7 +97,7 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
// uTorrent compatible Peer-Exchange
UTPexExtensionMessage* m = UTPexExtensionMessage::create(data, length);
m->setPeerStorage(peerStorage_);
- return SharedHandle<ExtensionMessage>(m);
+ return std::shared_ptr<ExtensionMessage>(m);
} else if(strcmp(extensionName, "ut_metadata") == 0) {
if(length == 0) {
throw DL_ABORT_EX
@@ -106,7 +106,7 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
static_cast<unsigned long>(length)));
}
size_t end;
- SharedHandle<ValueBase> decoded =
+ std::shared_ptr<ValueBase> decoded =
bencode2::decode(data+1, length - 1, end);
const Dict* dict = downcast<Dict>(decoded);
if(!dict) {
@@ -129,7 +129,7 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
m->setPeer(peer_);
m->setBtMessageFactory(messageFactory_);
m->setBtMessageDispatcher(dispatcher_);
- return SharedHandle<ExtensionMessage>(m);
+ return std::shared_ptr<ExtensionMessage>(m);
}
case 1: {
if(end == length) {
@@ -147,14 +147,14 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
m->setUTMetadataRequestTracker(tracker_);
m->setPieceStorage(dctx_->getOwnerRequestGroup()->getPieceStorage());
m->setDownloadContext(dctx_);
- return SharedHandle<ExtensionMessage>(m);
+ return std::shared_ptr<ExtensionMessage>(m);
}
case 2: {
UTMetadataRejectExtensionMessage* m
(new UTMetadataRejectExtensionMessage(extensionMessageID));
m->setIndex(index->i());
// No need to inject tracker because peer will be disconnected.
- return SharedHandle<ExtensionMessage>(m);
+ return std::shared_ptr<ExtensionMessage>(m);
}
default:
throw DL_ABORT_EX
@@ -171,12 +171,12 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
}
void DefaultExtensionMessageFactory::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
-void DefaultExtensionMessageFactory::setPeer(const SharedHandle<Peer>& peer)
+void DefaultExtensionMessageFactory::setPeer(const std::shared_ptr<Peer>& peer)
{
peer_ = peer;
}
diff --git a/src/DefaultExtensionMessageFactory.h b/src/DefaultExtensionMessageFactory.h
index 908855cb..ab56d33d 100644
--- a/src/DefaultExtensionMessageFactory.h
+++ b/src/DefaultExtensionMessageFactory.h
@@ -49,13 +49,13 @@ class UTMetadataRequestTracker;
class DefaultExtensionMessageFactory:public ExtensionMessageFactory {
private:
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
- SharedHandle<ExtensionMessageRegistry> registry_;
+ std::shared_ptr<ExtensionMessageRegistry> registry_;
- SharedHandle<DownloadContext> dctx_;
+ std::shared_ptr<DownloadContext> dctx_;
BtMessageFactory* messageFactory_;
@@ -66,25 +66,25 @@ public:
DefaultExtensionMessageFactory();
DefaultExtensionMessageFactory
- (const SharedHandle<Peer>& peer,
- const SharedHandle<ExtensionMessageRegistry>& registry);
+ (const std::shared_ptr<Peer>& peer,
+ const std::shared_ptr<ExtensionMessageRegistry>& registry);
virtual ~DefaultExtensionMessageFactory();
- virtual SharedHandle<ExtensionMessage>
+ virtual std::shared_ptr<ExtensionMessage>
createMessage(const unsigned char* data, size_t length);
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
- void setPeer(const SharedHandle<Peer>& peer);
+ void setPeer(const std::shared_ptr<Peer>& peer);
void setExtensionMessageRegistry
- (const SharedHandle<ExtensionMessageRegistry>& registry)
+ (const std::shared_ptr<ExtensionMessageRegistry>& registry)
{
registry_ = registry;
}
- void setDownloadContext(const SharedHandle<DownloadContext>& dctx)
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& dctx)
{
dctx_ = dctx;
}
diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc
index 235f2c5d..473522de 100644
--- a/src/DefaultPeerStorage.cc
+++ b/src/DefaultPeerStorage.cc
@@ -77,18 +77,18 @@ size_t DefaultPeerStorage::countAllPeer() const
return unusedPeers_.size() + usedPeers_.size();
}
-bool DefaultPeerStorage::isPeerAlreadyAdded(const SharedHandle<Peer>& peer)
+bool DefaultPeerStorage::isPeerAlreadyAdded(const std::shared_ptr<Peer>& peer)
{
return uniqPeers_.count(std::make_pair(peer->getIPAddress(),
peer->getOrigPort()));
}
-void DefaultPeerStorage::addUniqPeer(const SharedHandle<Peer>& peer)
+void DefaultPeerStorage::addUniqPeer(const std::shared_ptr<Peer>& peer)
{
uniqPeers_.insert(std::make_pair(peer->getIPAddress(), peer->getOrigPort()));
}
-bool DefaultPeerStorage::addPeer(const SharedHandle<Peer>& peer)
+bool DefaultPeerStorage::addPeer(const std::shared_ptr<Peer>& peer)
{
if(isPeerAlreadyAdded(peer)) {
A2_LOG_DEBUG(fmt("Adding %s:%u is rejected because it has been already"
@@ -112,13 +112,13 @@ bool DefaultPeerStorage::addPeer(const SharedHandle<Peer>& peer)
return true;
}
-void DefaultPeerStorage::addPeer(const std::vector<SharedHandle<Peer> >& peers)
+void DefaultPeerStorage::addPeer(const std::vector<std::shared_ptr<Peer> >& peers)
{
size_t added = 0;
size_t addMax = std::min(maxPeerListSize_, MAX_PEER_LIST_UPDATE);
- for(std::vector<SharedHandle<Peer> >::const_iterator itr = peers.begin(),
+ for(std::vector<std::shared_ptr<Peer> >::const_iterator itr = peers.begin(),
eoi = peers.end(); itr != eoi && added < addMax; ++itr) {
- const SharedHandle<Peer>& peer = *itr;
+ const std::shared_ptr<Peer>& peer = *itr;
if(isPeerAlreadyAdded(peer)) {
A2_LOG_DEBUG(fmt("Adding %s:%u is rejected because it has been already"
" added.",
@@ -144,11 +144,11 @@ void DefaultPeerStorage::addPeer(const std::vector<SharedHandle<Peer> >& peers)
static_cast<unsigned long>(unusedPeers_.size())));
}
-void DefaultPeerStorage::addDroppedPeer(const SharedHandle<Peer>& peer)
+void DefaultPeerStorage::addDroppedPeer(const std::shared_ptr<Peer>& peer)
{
// Make sure that duplicated peers exist in droppedPeers_. If
// exists, erase older one.
- for(std::deque<SharedHandle<Peer> >::iterator i = droppedPeers_.begin(),
+ for(std::deque<std::shared_ptr<Peer> >::iterator i = droppedPeers_.begin(),
eoi = droppedPeers_.end(); i != eoi; ++i) {
if((*i)->getIPAddress() == peer->getIPAddress() &&
(*i)->getPort() == peer->getPort()) {
@@ -162,7 +162,7 @@ void DefaultPeerStorage::addDroppedPeer(const SharedHandle<Peer>& peer)
}
}
-const std::deque<SharedHandle<Peer> >& DefaultPeerStorage::getUnusedPeers()
+const std::deque<std::shared_ptr<Peer> >& DefaultPeerStorage::getUnusedPeers()
{
return unusedPeers_;
}
@@ -172,7 +172,7 @@ const PeerSet& DefaultPeerStorage::getUsedPeers()
return usedPeers_;
}
-const std::deque<SharedHandle<Peer> >& DefaultPeerStorage::getDroppedPeers()
+const std::deque<std::shared_ptr<Peer> >& DefaultPeerStorage::getDroppedPeers()
{
return droppedPeers_;
}
@@ -222,28 +222,28 @@ void DefaultPeerStorage::deleteUnusedPeer(size_t delSize) {
}
}
-SharedHandle<Peer> DefaultPeerStorage::checkoutPeer(cuid_t cuid)
+std::shared_ptr<Peer> DefaultPeerStorage::checkoutPeer(cuid_t cuid)
{
if(!isPeerAvailable()) {
- return SharedHandle<Peer>();
+ return std::shared_ptr<Peer>();
}
- SharedHandle<Peer> peer = unusedPeers_.front();
+ std::shared_ptr<Peer> peer = unusedPeers_.front();
unusedPeers_.pop_front();
peer->usedBy(cuid);
usedPeers_.insert(peer);
- A2_LOG_DEBUG(fmt("Checkout peer %s:%u to CUID#%"PRId64,
+ A2_LOG_DEBUG(fmt("Checkout peer %s:%u to CUID#%" PRId64,
peer->getIPAddress().c_str(), peer->getPort(),
peer->usedBy()));
return peer;
}
-void DefaultPeerStorage::onErasingPeer(const SharedHandle<Peer>& peer)
+void DefaultPeerStorage::onErasingPeer(const std::shared_ptr<Peer>& peer)
{
uniqPeers_.erase(std::make_pair(peer->getIPAddress(),
peer->getOrigPort()));
}
-void DefaultPeerStorage::onReturningPeer(const SharedHandle<Peer>& peer)
+void DefaultPeerStorage::onReturningPeer(const std::shared_ptr<Peer>& peer)
{
if(peer->isActive()) {
if(peer->isDisconnectedGracefully() && !peer->isIncomingPeer()) {
@@ -259,9 +259,9 @@ void DefaultPeerStorage::onReturningPeer(const SharedHandle<Peer>& peer)
peer->usedBy(0);
}
-void DefaultPeerStorage::returnPeer(const SharedHandle<Peer>& peer)
+void DefaultPeerStorage::returnPeer(const std::shared_ptr<Peer>& peer)
{
- A2_LOG_DEBUG(fmt("Peer %s:%u returned from CUID#%"PRId64,
+ A2_LOG_DEBUG(fmt("Peer %s:%u returned from CUID#%" PRId64,
peer->getIPAddress().c_str(), peer->getPort(),
peer->usedBy()));
if(usedPeers_.erase(peer)) {
@@ -294,12 +294,12 @@ void DefaultPeerStorage::executeChoke()
}
}
-void DefaultPeerStorage::setPieceStorage(const SharedHandle<PieceStorage>& ps)
+void DefaultPeerStorage::setPieceStorage(const std::shared_ptr<PieceStorage>& ps)
{
pieceStorage_ = ps;
}
-void DefaultPeerStorage::setBtRuntime(const SharedHandle<BtRuntime>& btRuntime)
+void DefaultPeerStorage::setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
diff --git a/src/DefaultPeerStorage.h b/src/DefaultPeerStorage.h
index 77e9b00d..3e43d798 100644
--- a/src/DefaultPeerStorage.h
+++ b/src/DefaultPeerStorage.h
@@ -51,20 +51,20 @@ class PieceStorage;
class DefaultPeerStorage : public PeerStorage {
private:
- SharedHandle<BtRuntime> btRuntime_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<BtRuntime> btRuntime_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
size_t maxPeerListSize_;
// This contains ip address and port pair and is used to ensure that
// no duplicate peers are stored.
std::set<std::pair<std::string, uint16_t> > uniqPeers_;
// Unused (not connected) peers, sorted by last added.
- std::deque<SharedHandle<Peer> > unusedPeers_;
+ std::deque<std::shared_ptr<Peer> > unusedPeers_;
// The set of used peers. Some of them are not connected yet. To
// know it is connected or not, call Peer::isActive().
PeerSet usedPeers_;
- std::deque<SharedHandle<Peer> > droppedPeers_;
+ std::deque<std::shared_ptr<Peer> > droppedPeers_;
BtSeederStateChoke* seederStateChoke_;
BtLeecherStateChoke* leecherStateChoke_;
@@ -74,29 +74,29 @@ private:
std::map<std::string, time_t> badPeers_;
Timer lastBadPeerCleaned_;
- bool isPeerAlreadyAdded(const SharedHandle<Peer>& peer);
- void addUniqPeer(const SharedHandle<Peer>& peer);
+ bool isPeerAlreadyAdded(const std::shared_ptr<Peer>& peer);
+ void addUniqPeer(const std::shared_ptr<Peer>& peer);
- void addDroppedPeer(const SharedHandle<Peer>& peer);
+ void addDroppedPeer(const std::shared_ptr<Peer>& peer);
public:
DefaultPeerStorage();
virtual ~DefaultPeerStorage();
// TODO We need addAndCheckoutPeer for incoming peers
- virtual bool addPeer(const SharedHandle<Peer>& peer);
+ virtual bool addPeer(const std::shared_ptr<Peer>& peer);
virtual size_t countAllPeer() const;
- SharedHandle<Peer> getPeer(const std::string& ipaddr, uint16_t port) const;
+ std::shared_ptr<Peer> getPeer(const std::string& ipaddr, uint16_t port) const;
- virtual void addPeer(const std::vector<SharedHandle<Peer> >& peers);
+ virtual void addPeer(const std::vector<std::shared_ptr<Peer> >& peers);
- const std::deque<SharedHandle<Peer> >& getUnusedPeers();
+ const std::deque<std::shared_ptr<Peer> >& getUnusedPeers();
virtual const PeerSet& getUsedPeers();
- virtual const std::deque<SharedHandle<Peer> >& getDroppedPeers();
+ virtual const std::deque<std::shared_ptr<Peer> >& getDroppedPeers();
virtual bool isPeerAvailable();
@@ -104,9 +104,9 @@ public:
virtual void addBadPeer(const std::string& ipaddr);
- virtual SharedHandle<Peer> checkoutPeer(cuid_t cuid);
+ virtual std::shared_ptr<Peer> checkoutPeer(cuid_t cuid);
- virtual void returnPeer(const SharedHandle<Peer>& peer);
+ virtual void returnPeer(const std::shared_ptr<Peer>& peer);
virtual bool chokeRoundIntervalElapsed();
@@ -114,13 +114,13 @@ public:
void deleteUnusedPeer(size_t delSize);
- void onErasingPeer(const SharedHandle<Peer>& peer);
+ void onErasingPeer(const std::shared_ptr<Peer>& peer);
- void onReturningPeer(const SharedHandle<Peer>& peer);
+ void onReturningPeer(const std::shared_ptr<Peer>& peer);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
void setMaxPeerListSize(size_t maxPeerListSize)
{
diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc
index 46012a90..cef39f04 100644
--- a/src/DefaultPieceStorage.cc
+++ b/src/DefaultPieceStorage.cc
@@ -74,7 +74,7 @@
namespace aria2 {
DefaultPieceStorage::DefaultPieceStorage
-(const SharedHandle<DownloadContext>& downloadContext, const Option* option)
+(const std::shared_ptr<DownloadContext>& downloadContext, const Option* option)
: downloadContext_(downloadContext),
bitfieldMan_(new BitfieldMan(downloadContext->getPieceLength(),
downloadContext->getTotalLength())),
@@ -102,12 +102,12 @@ DefaultPieceStorage::~DefaultPieceStorage()
delete bitfieldMan_;
}
-SharedHandle<Piece> DefaultPieceStorage::checkOutPiece
+std::shared_ptr<Piece> DefaultPieceStorage::checkOutPiece
(size_t index, cuid_t cuid)
{
bitfieldMan_->setUseBit(index);
- SharedHandle<Piece> piece = findUsedPiece(index);
+ std::shared_ptr<Piece> piece = findUsedPiece(index);
if(!piece) {
piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index)));
#ifdef ENABLE_MESSAGE_DIGEST
@@ -133,9 +133,9 @@ SharedHandle<Piece> DefaultPieceStorage::checkOutPiece
* Newly instantiated piece is not added to usedPieces.
* Because it is waste of memory and there is no chance to use them later.
*/
-SharedHandle<Piece> DefaultPieceStorage::getPiece(size_t index)
+std::shared_ptr<Piece> DefaultPieceStorage::getPiece(size_t index)
{
- SharedHandle<Piece> piece;
+ std::shared_ptr<Piece> piece;
if(index <= bitfieldMan_->getMaxIndex()) {
piece = findUsedPiece(index);
if(!piece) {
@@ -148,16 +148,16 @@ SharedHandle<Piece> DefaultPieceStorage::getPiece(size_t index)
return piece;
}
-void DefaultPieceStorage::addUsedPiece(const SharedHandle<Piece>& piece)
+void DefaultPieceStorage::addUsedPiece(const std::shared_ptr<Piece>& piece)
{
usedPieces_.insert(piece);
A2_LOG_DEBUG(fmt("usedPieces_.size()=%lu",
static_cast<unsigned long>(usedPieces_.size())));
}
-SharedHandle<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const
+std::shared_ptr<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const
{
- SharedHandle<Piece> p(new Piece());
+ std::shared_ptr<Piece> p(new Piece());
p->setIndex(index);
UsedPieceSet::iterator i = usedPieces_.find(p);
@@ -171,14 +171,14 @@ SharedHandle<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const
#ifdef ENABLE_BITTORRENT
-bool DefaultPieceStorage::hasMissingPiece(const SharedHandle<Peer>& peer)
+bool DefaultPieceStorage::hasMissingPiece(const std::shared_ptr<Peer>& peer)
{
return bitfieldMan_->hasMissingPiece(peer->getBitfield(),
peer->getBitfieldLength());
}
void DefaultPieceStorage::getMissingPiece
-(std::vector<SharedHandle<Piece> >& pieces,
+(std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
const unsigned char* bitfield,
size_t length,
@@ -203,7 +203,7 @@ void DefaultPieceStorage::getMissingPiece
std::random_shuffle(indexes.begin(), indexes.end());
for(std::vector<size_t>::const_iterator i = indexes.begin(),
eoi = indexes.end(); i != eoi && misBlock < minMissingBlocks; ++i) {
- SharedHandle<Piece> piece = checkOutPiece(*i, cuid);
+ std::shared_ptr<Piece> piece = checkOutPiece(*i, cuid);
if(piece->getUsedBySegment()) {
// We don't share piece downloaded via HTTP/FTP
piece->removeUser(cuid);
@@ -241,7 +241,7 @@ void unsetExcludedIndexes(BitfieldMan& bitfield,
} // namespace
void DefaultPieceStorage::createFastIndexBitfield
-(BitfieldMan& bitfield, const SharedHandle<Peer>& peer)
+(BitfieldMan& bitfield, const std::shared_ptr<Peer>& peer)
{
for(std::set<size_t>::const_iterator itr =
peer->getPeerAllowedIndexSet().begin(),
@@ -253,9 +253,9 @@ void DefaultPieceStorage::createFastIndexBitfield
}
void DefaultPieceStorage::getMissingPiece
-(std::vector<SharedHandle<Piece> >& pieces,
+(std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
cuid_t cuid)
{
getMissingPiece(pieces, minMissingBlocks,
@@ -265,9 +265,9 @@ void DefaultPieceStorage::getMissingPiece
void DefaultPieceStorage::getMissingPiece
-(std::vector<SharedHandle<Piece> >& pieces,
+(std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid)
{
@@ -281,9 +281,9 @@ void DefaultPieceStorage::getMissingPiece
}
void DefaultPieceStorage::getMissingFastPiece
-(std::vector<SharedHandle<Piece> >& pieces,
+(std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
cuid_t cuid)
{
if(peer->isFastExtensionEnabled() && peer->countPeerAllowedIndexSet() > 0) {
@@ -298,9 +298,9 @@ void DefaultPieceStorage::getMissingFastPiece
}
void DefaultPieceStorage::getMissingFastPiece
-(std::vector<SharedHandle<Piece> >& pieces,
+(std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid)
{
@@ -316,56 +316,56 @@ void DefaultPieceStorage::getMissingFastPiece
}
}
-SharedHandle<Piece>
+std::shared_ptr<Piece>
DefaultPieceStorage::getMissingPiece
-(const SharedHandle<Peer>& peer,
+(const std::shared_ptr<Peer>& peer,
cuid_t cuid)
{
- std::vector<SharedHandle<Piece> > pieces;
+ std::vector<std::shared_ptr<Piece> > pieces;
getMissingPiece(pieces, 1, peer, cuid);
if(pieces.empty()) {
- return SharedHandle<Piece>();
+ return std::shared_ptr<Piece>();
} else {
return pieces.front();
}
}
-SharedHandle<Piece> DefaultPieceStorage::getMissingPiece
-(const SharedHandle<Peer>& peer,
+std::shared_ptr<Piece> DefaultPieceStorage::getMissingPiece
+(const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid)
{
- std::vector<SharedHandle<Piece> > pieces;
+ std::vector<std::shared_ptr<Piece> > pieces;
getMissingPiece(pieces, 1, peer, excludedIndexes, cuid);
if(pieces.empty()) {
- return SharedHandle<Piece>();
+ return std::shared_ptr<Piece>();
} else {
return pieces.front();
}
}
-SharedHandle<Piece> DefaultPieceStorage::getMissingFastPiece
-(const SharedHandle<Peer>& peer,
+std::shared_ptr<Piece> DefaultPieceStorage::getMissingFastPiece
+(const std::shared_ptr<Peer>& peer,
cuid_t cuid)
{
- std::vector<SharedHandle<Piece> > pieces;
+ std::vector<std::shared_ptr<Piece> > pieces;
getMissingFastPiece(pieces, 1, peer, cuid);
if(pieces.empty()) {
- return SharedHandle<Piece>();
+ return std::shared_ptr<Piece>();
} else {
return pieces.front();
}
}
-SharedHandle<Piece> DefaultPieceStorage::getMissingFastPiece
-(const SharedHandle<Peer>& peer,
+std::shared_ptr<Piece> DefaultPieceStorage::getMissingFastPiece
+(const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid)
{
- std::vector<SharedHandle<Piece> > pieces;
+ std::vector<std::shared_ptr<Piece> > pieces;
getMissingFastPiece(pieces, 1, peer, excludedIndexes, cuid);
if(pieces.empty()) {
- return SharedHandle<Piece>();
+ return std::shared_ptr<Piece>();
} else {
return pieces.front();
}
@@ -379,7 +379,7 @@ bool DefaultPieceStorage::hasMissingUnusedPiece()
return bitfieldMan_->getFirstMissingUnusedIndex(index);
}
-SharedHandle<Piece> DefaultPieceStorage::getMissingPiece
+std::shared_ptr<Piece> DefaultPieceStorage::getMissingPiece
(size_t minSplitSize,
const unsigned char* ignoreBitfield,
size_t length,
@@ -390,22 +390,22 @@ SharedHandle<Piece> DefaultPieceStorage::getMissingPiece
(index, minSplitSize, ignoreBitfield, length)) {
return checkOutPiece(index, cuid);
} else {
- return SharedHandle<Piece>();
+ return std::shared_ptr<Piece>();
}
}
-SharedHandle<Piece> DefaultPieceStorage::getMissingPiece
+std::shared_ptr<Piece> DefaultPieceStorage::getMissingPiece
(size_t index,
cuid_t cuid)
{
if(hasPiece(index) || isPieceUsed(index)) {
- return SharedHandle<Piece>();
+ return std::shared_ptr<Piece>();
} else {
return checkOutPiece(index, cuid);
}
}
-void DefaultPieceStorage::deleteUsedPiece(const SharedHandle<Piece>& piece)
+void DefaultPieceStorage::deleteUsedPiece(const std::shared_ptr<Piece>& piece)
{
if(!piece) {
return;
@@ -434,7 +434,7 @@ void DefaultPieceStorage::deleteUsedPiece(const SharedHandle<Piece>& piece)
// size_t deleted = 0;
// for(Pieces::iterator itr = usedPieces.begin();
// itr != usedPieces.end() && deleted < delNum;) {
-// SharedHandle<Piece>& piece = *itr;
+// std::shared_ptr<Piece>& piece = *itr;
// if(!bitfieldMan->isUseBitSet(piece->getIndex()) &&
// piece->countCompleteBlock() <= piece->countBlock()*(fillRate/100.0)) {
// logger->info(MSG_DELETING_USED_PIECE,
@@ -450,7 +450,7 @@ void DefaultPieceStorage::deleteUsedPiece(const SharedHandle<Piece>& piece)
// return deleted;
// }
-void DefaultPieceStorage::completePiece(const SharedHandle<Piece>& piece)
+void DefaultPieceStorage::completePiece(const std::shared_ptr<Piece>& piece)
{
if(!piece) {
return;
@@ -477,7 +477,7 @@ void DefaultPieceStorage::completePiece(const SharedHandle<Piece>& piece)
}
#ifdef ENABLE_BITTORRENT
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
- SharedHandle<TorrentAttribute> torrentAttrs =
+ std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(downloadContext_);
if(!torrentAttrs->metadata.empty()) {
#ifdef __MINGW32__
@@ -509,7 +509,7 @@ bool DefaultPieceStorage::isSelectiveDownloadingMode()
// not unittested
void DefaultPieceStorage::cancelPiece
-(const SharedHandle<Piece>& piece, cuid_t cuid)
+(const std::shared_ptr<Piece>& piece, cuid_t cuid)
{
if(!piece) {
return;
@@ -587,10 +587,10 @@ int64_t DefaultPieceStorage::getInFlightPieceFilteredCompletedLength() const
// not unittested
void DefaultPieceStorage::setupFileFilter()
{
- const std::vector<SharedHandle<FileEntry> >& fileEntries =
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
downloadContext_->getFileEntries();
bool allSelected = true;
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
fileEntries.begin(), eoi = fileEntries.end();
i != eoi; ++i) {
if(!(*i)->isRequested()) {
@@ -601,7 +601,7 @@ void DefaultPieceStorage::setupFileFilter()
if(allSelected) {
return;
}
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
if((*i)->isRequested()) {
bitfieldMan_->addFilter((*i)->getOffset(), (*i)->getLength());
@@ -641,7 +641,7 @@ void DefaultPieceStorage::initStorage()
(downloadContext_->getFileEntries().begin(),
downloadContext_->getFileEntries().end());
- SharedHandle<DiskWriter> writer =
+ std::shared_ptr<DiskWriter> writer =
diskWriterFactory_->newDiskWriter(directDiskAdaptor->getFilePath());
directDiskAdaptor->setDiskWriter(writer);
diskAdaptor_.reset(directDiskAdaptor);
@@ -679,7 +679,7 @@ const unsigned char* DefaultPieceStorage::getBitfield()
return bitfieldMan_->getBitfield();
}
-SharedHandle<DiskAdaptor> DefaultPieceStorage::getDiskAdaptor() {
+std::shared_ptr<DiskAdaptor> DefaultPieceStorage::getDiskAdaptor() {
return diskAdaptor_;
}
@@ -781,7 +781,7 @@ void DefaultPieceStorage::markPiecesDone(int64_t length)
}
size_t r = (length%bitfieldMan_->getBlockLength())/Piece::BLOCK_LENGTH;
if(r > 0) {
- SharedHandle<Piece> p
+ std::shared_ptr<Piece> p
(new Piece(numPiece, bitfieldMan_->getBlockLength(numPiece)));
for(size_t i = 0; i < r; ++i) {
@@ -805,7 +805,7 @@ void DefaultPieceStorage::markPieceMissing(size_t index)
}
void DefaultPieceStorage::addInFlightPiece
-(const std::vector<SharedHandle<Piece> >& pieces)
+(const std::vector<std::shared_ptr<Piece> >& pieces)
{
usedPieces_.insert(pieces.begin(), pieces.end());
}
@@ -816,13 +816,13 @@ size_t DefaultPieceStorage::countInFlightPiece()
}
void DefaultPieceStorage::getInFlightPieces
-(std::vector<SharedHandle<Piece> >& pieces)
+(std::vector<std::shared_ptr<Piece> >& pieces)
{
pieces.insert(pieces.end(), usedPieces_.begin(), usedPieces_.end());
}
void DefaultPieceStorage::setDiskWriterFactory
-(const SharedHandle<DiskWriterFactory>& diskWriterFactory)
+(const std::shared_ptr<DiskWriterFactory>& diskWriterFactory)
{
diskWriterFactory_ = diskWriterFactory;
}
diff --git a/src/DefaultPieceStorage.h b/src/DefaultPieceStorage.h
index 328d0876..b0d6e316 100644
--- a/src/DefaultPieceStorage.h
+++ b/src/DefaultPieceStorage.h
@@ -75,12 +75,12 @@ public:
class DefaultPieceStorage : public PieceStorage {
private:
- SharedHandle<DownloadContext> downloadContext_;
+ std::shared_ptr<DownloadContext> downloadContext_;
BitfieldMan* bitfieldMan_;
- SharedHandle<DiskAdaptor> diskAdaptor_;
- SharedHandle<DiskWriterFactory> diskWriterFactory_;
- typedef std::set<SharedHandle<Piece>,
- DerefLess<SharedHandle<Piece> > > UsedPieceSet;
+ std::shared_ptr<DiskAdaptor> diskAdaptor_;
+ std::shared_ptr<DiskWriterFactory> diskWriterFactory_;
+ typedef std::set<std::shared_ptr<Piece>,
+ DerefLess<std::shared_ptr<Piece> > > UsedPieceSet;
UsedPieceSet usedPieces_;
bool endGame_;
@@ -88,29 +88,29 @@ private:
const Option* option_;
std::deque<HaveEntry> haves_;
- SharedHandle<PieceStatMan> pieceStatMan_;
+ std::shared_ptr<PieceStatMan> pieceStatMan_;
- SharedHandle<PieceSelector> pieceSelector_;
- SharedHandle<StreamPieceSelector> streamPieceSelector_;
+ std::shared_ptr<PieceSelector> pieceSelector_;
+ std::shared_ptr<StreamPieceSelector> streamPieceSelector_;
WrDiskCache* wrDiskCache_;
#ifdef ENABLE_BITTORRENT
void getMissingPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
const unsigned char* bitfield,
size_t length,
cuid_t cuid);
void createFastIndexBitfield(BitfieldMan& bitfield,
- const SharedHandle<Peer>& peer);
+ const std::shared_ptr<Peer>& peer);
#endif // ENABLE_BITTORRENT
- SharedHandle<Piece> checkOutPiece(size_t index, cuid_t cuid);
+ std::shared_ptr<Piece> checkOutPiece(size_t index, cuid_t cuid);
// size_t deleteUsedPiecesByFillRate(int fillRate, size_t toDelete);
// void reduceUsedPieces(size_t upperBound);
- void deleteUsedPiece(const SharedHandle<Piece>& piece);
- SharedHandle<Piece> findUsedPiece(size_t index) const;
+ void deleteUsedPiece(const std::shared_ptr<Piece>& piece);
+ std::shared_ptr<Piece> findUsedPiece(size_t index) const;
// Returns the sum of completed length of in-flight pieces
int64_t getInFlightPieceCompletedLength() const;
@@ -122,56 +122,56 @@ public:
// random when more than 2 pieces has the same rarity.
// If it is set to false, a piece whose index is smallest has the highest
// priority.
- DefaultPieceStorage(const SharedHandle<DownloadContext>& downloadContext,
+ DefaultPieceStorage(const std::shared_ptr<DownloadContext>& downloadContext,
const Option* option);
virtual ~DefaultPieceStorage();
#ifdef ENABLE_BITTORRENT
- virtual bool hasMissingPiece(const SharedHandle<Peer>& peer);
+ virtual bool hasMissingPiece(const std::shared_ptr<Peer>& peer);
virtual void getMissingPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
cuid_t cuid);
virtual void getMissingPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid);
virtual void getMissingFastPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
cuid_t cuid);
virtual void getMissingFastPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid);
- virtual SharedHandle<Piece> getMissingPiece
- (const SharedHandle<Peer>& peer,
+ virtual std::shared_ptr<Piece> getMissingPiece
+ (const std::shared_ptr<Peer>& peer,
cuid_t cuid);
- virtual SharedHandle<Piece> getMissingPiece
- (const SharedHandle<Peer>& peer,
+ virtual std::shared_ptr<Piece> getMissingPiece
+ (const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid);
- SharedHandle<Piece> getMissingFastPiece
- (const SharedHandle<Peer>& peer,
+ std::shared_ptr<Piece> getMissingFastPiece
+ (const std::shared_ptr<Peer>& peer,
cuid_t cuid);
- SharedHandle<Piece> getMissingFastPiece
- (const SharedHandle<Peer>& peer,
+ std::shared_ptr<Piece> getMissingFastPiece
+ (const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid);
@@ -179,19 +179,19 @@ public:
virtual bool hasMissingUnusedPiece();
- virtual SharedHandle<Piece> getMissingPiece
+ virtual std::shared_ptr<Piece> getMissingPiece
(size_t minSplitSize,
const unsigned char* ignoreBitfield,
size_t length,
cuid_t cuid);
- virtual SharedHandle<Piece> getMissingPiece(size_t index, cuid_t cuid);
+ virtual std::shared_ptr<Piece> getMissingPiece(size_t index, cuid_t cuid);
- virtual SharedHandle<Piece> getPiece(size_t index);
+ virtual std::shared_ptr<Piece> getPiece(size_t index);
- virtual void completePiece(const SharedHandle<Piece>& piece);
+ virtual void completePiece(const std::shared_ptr<Piece>& piece);
- virtual void cancelPiece(const SharedHandle<Piece>& piece, cuid_t cuid);
+ virtual void cancelPiece(const std::shared_ptr<Piece>& piece, cuid_t cuid);
virtual bool hasPiece(size_t index);
@@ -242,7 +242,7 @@ public:
endGame_ = true;
}
- virtual SharedHandle<DiskAdaptor> getDiskAdaptor();
+ virtual std::shared_ptr<DiskAdaptor> getDiskAdaptor();
virtual WrDiskCache* getWrDiskCache();
@@ -265,12 +265,12 @@ public:
virtual void markPieceMissing(size_t index);
virtual void addInFlightPiece
- (const std::vector<SharedHandle<Piece> >& pieces);
+ (const std::vector<std::shared_ptr<Piece> >& pieces);
virtual size_t countInFlightPiece();
virtual void getInFlightPieces
- (std::vector<SharedHandle<Piece> >& pieces);
+ (std::vector<std::shared_ptr<Piece> >& pieces);
virtual void addPieceStats(size_t index);
@@ -291,22 +291,22 @@ public:
/**
* This method is made private for test purpose only.
*/
- void addUsedPiece(const SharedHandle<Piece>& piece);
+ void addUsedPiece(const std::shared_ptr<Piece>& piece);
void setDiskWriterFactory
- (const SharedHandle<DiskWriterFactory>& diskWriterFactory);
+ (const std::shared_ptr<DiskWriterFactory>& diskWriterFactory);
- const SharedHandle<PieceStatMan>& getPieceStatMan() const
+ const std::shared_ptr<PieceStatMan>& getPieceStatMan() const
{
return pieceStatMan_;
}
- void setPieceSelector(const SharedHandle<PieceSelector>& pieceSelector)
+ void setPieceSelector(const std::shared_ptr<PieceSelector>& pieceSelector)
{
pieceSelector_ = pieceSelector;
}
- const SharedHandle<PieceSelector>& getPieceSelector() const
+ const std::shared_ptr<PieceSelector>& getPieceSelector() const
{
return pieceSelector_;
}
diff --git a/src/DiskAdaptor.h b/src/DiskAdaptor.h
index b7d1b1f5..6e46fa4e 100644
--- a/src/DiskAdaptor.h
+++ b/src/DiskAdaptor.h
@@ -39,9 +39,9 @@
#include <string>
#include <vector>
+#include <memory>
#include "TimeA2.h"
-#include "SharedHandle.h"
namespace aria2 {
@@ -78,12 +78,12 @@ public:
fileEntries_.assign(first, last);
}
- const std::vector<SharedHandle<FileEntry> >& getFileEntries() const
+ const std::vector<std::shared_ptr<FileEntry> >& getFileEntries() const
{
return fileEntries_;
}
- virtual SharedHandle<FileAllocationIterator> fileAllocationIterator() = 0;
+ virtual std::shared_ptr<FileAllocationIterator> fileAllocationIterator() = 0;
virtual void enableReadOnly() {}
@@ -120,7 +120,7 @@ public:
}
private:
- std::vector<SharedHandle<FileEntry> > fileEntries_;
+ std::vector<std::shared_ptr<FileEntry> > fileEntries_;
FileAllocationMethod fileAllocationMethod_;
};
diff --git a/src/DiskWriterFactory.h b/src/DiskWriterFactory.h
index 125ec098..56a8cef0 100644
--- a/src/DiskWriterFactory.h
+++ b/src/DiskWriterFactory.h
@@ -38,8 +38,7 @@
#include "common.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -49,7 +48,7 @@ class DiskWriterFactory {
public:
virtual ~DiskWriterFactory() {}
- virtual SharedHandle<DiskWriter> newDiskWriter(const std::string& filename)=0;
+ virtual std::shared_ptr<DiskWriter> newDiskWriter(const std::string& filename)=0;
};
} // namespace aria2
diff --git a/src/DlAbortEx.cc b/src/DlAbortEx.cc
index 81490ca4..c5de3b93 100644
--- a/src/DlAbortEx.cc
+++ b/src/DlAbortEx.cc
@@ -36,9 +36,9 @@
namespace aria2 {
-SharedHandle<Exception> DlAbortEx::copy() const
+std::shared_ptr<Exception> DlAbortEx::copy() const
{
- SharedHandle<Exception> e(new DlAbortEx(*this));
+ std::shared_ptr<Exception> e(new DlAbortEx(*this));
return e;
}
diff --git a/src/DlAbortEx.h b/src/DlAbortEx.h
index 3498b1fb..e49e827d 100644
--- a/src/DlAbortEx.h
+++ b/src/DlAbortEx.h
@@ -40,7 +40,7 @@ namespace aria2 {
class DlAbortEx:public RecoverableException {
protected:
- virtual SharedHandle<Exception> copy() const;
+ virtual std::shared_ptr<Exception> copy() const;
public:
DlAbortEx(const char* file, int line, const std::string& msg);
diff --git a/src/DlRetryEx.cc b/src/DlRetryEx.cc
index 8bbbfa33..98bf7eff 100644
--- a/src/DlRetryEx.cc
+++ b/src/DlRetryEx.cc
@@ -36,9 +36,9 @@
namespace aria2 {
-SharedHandle<Exception> DlRetryEx::copy() const
+std::shared_ptr<Exception> DlRetryEx::copy() const
{
- SharedHandle<Exception> e(new DlRetryEx(*this));
+ std::shared_ptr<Exception> e(new DlRetryEx(*this));
return e;
}
diff --git a/src/DlRetryEx.h b/src/DlRetryEx.h
index dcecb357..98a0ff59 100644
--- a/src/DlRetryEx.h
+++ b/src/DlRetryEx.h
@@ -40,7 +40,7 @@ namespace aria2 {
class DlRetryEx:public RecoverableException {
protected:
- virtual SharedHandle<Exception> copy() const;
+ virtual std::shared_ptr<Exception> copy() const;
public:
DlRetryEx(const char* file, int line, const std::string& msg);
diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc
index 0c17e83b..b6d7e1cc 100644
--- a/src/DownloadCommand.cc
+++ b/src/DownloadCommand.cc
@@ -81,12 +81,12 @@ const size_t BUFSIZE = 16*1024;
DownloadCommand::DownloadCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s,
- const SharedHandle<SocketRecvBuffer>& socketRecvBuffer)
+ const std::shared_ptr<SocketCore>& s,
+ const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer)
: AbstractCommand(cuid, req, fileEntry, requestGroup, e, s, socketRecvBuffer),
startupIdleTime_(10),
lowestDownloadSpeedLimit_(0),
@@ -123,9 +123,9 @@ DownloadCommand::~DownloadCommand() {
namespace {
void flushWrDiskCacheEntry(WrDiskCache* wrDiskCache,
- const SharedHandle<Segment>& segment)
+ const std::shared_ptr<Segment>& segment)
{
- const SharedHandle<Piece>& piece = segment->getPiece();
+ const std::shared_ptr<Piece>& piece = segment->getPiece();
if(piece->getWrDiskCacheEntry()) {
piece->flushWrCache(wrDiskCache);
if(piece->getWrDiskCacheEntry()->getError() !=
@@ -149,9 +149,9 @@ bool DownloadCommand::executeInternal() {
}
setReadCheckSocket(getSocket());
- const SharedHandle<DiskAdaptor>& diskAdaptor =
+ const std::shared_ptr<DiskAdaptor>& diskAdaptor =
getPieceStorage()->getDiskAdaptor();
- SharedHandle<Segment> segment = getSegments().front();
+ std::shared_ptr<Segment> segment = getSegments().front();
bool eof = false;
if(getSocketRecvBuffer()->bufferEmpty()) {
// Only read from socket when buffer is empty. Imagine that When
@@ -328,7 +328,7 @@ bool DownloadCommand::prepareForNextSegment() {
}
#ifdef ENABLE_MESSAGE_DIGEST
if(getDownloadContext()->getPieceHashType().empty()) {
- SharedHandle<CheckIntegrityEntry> entry
+ std::shared_ptr<CheckIntegrityEntry> entry
(new ChecksumCheckIntegrityEntry(getRequestGroup()));
if(entry->isValidationReady()) {
entry->initValidator();
@@ -346,7 +346,7 @@ bool DownloadCommand::prepareForNextSegment() {
// The number of segments should be 1 in order to pass through the next
// segment.
if(getSegments().size() == 1) {
- SharedHandle<Segment> tempSegment = getSegments().front();
+ std::shared_ptr<Segment> tempSegment = getSegments().front();
if(!tempSegment->complete()) {
return prepareForRetry(0);
}
@@ -355,7 +355,7 @@ bool DownloadCommand::prepareForNextSegment() {
(tempSegment->getPosition()+tempSegment->getLength())) {
return prepareForRetry(0);
}
- SharedHandle<Segment> nextSegment = getSegmentMan()->getSegmentWithIndex
+ std::shared_ptr<Segment> nextSegment = getSegmentMan()->getSegmentWithIndex
(getCuid(), tempSegment->getIndex()+1);
if(!nextSegment) {
nextSegment = getSegmentMan()->getCleanSegmentIfOwnerIsIdle
@@ -379,7 +379,7 @@ bool DownloadCommand::prepareForNextSegment() {
#ifdef ENABLE_MESSAGE_DIGEST
-void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
+void DownloadCommand::validatePieceHash(const std::shared_ptr<Segment>& segment,
const std::string& expectedHash,
const std::string& actualHash)
{
@@ -403,14 +403,14 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
#endif // ENABLE_MESSAGE_DIGEST
void DownloadCommand::completeSegment(cuid_t cuid,
- const SharedHandle<Segment>& segment)
+ const std::shared_ptr<Segment>& segment)
{
flushWrDiskCacheEntry(getPieceStorage()->getWrDiskCache(), segment);
getSegmentMan()->completeSegment(cuid, segment);
}
void DownloadCommand::installStreamFilter
-(const SharedHandle<StreamFilter>& streamFilter)
+(const std::shared_ptr<StreamFilter>& streamFilter)
{
if(!streamFilter) {
return;
diff --git a/src/DownloadCommand.h b/src/DownloadCommand.h
index 544da2a6..a36722b2 100644
--- a/src/DownloadCommand.h
+++ b/src/DownloadCommand.h
@@ -51,25 +51,25 @@ class DownloadCommand : public AbstractCommand {
private:
time_t startupIdleTime_;
int lowestDownloadSpeedLimit_;
- SharedHandle<PeerStat> peerStat_;
+ std::shared_ptr<PeerStat> peerStat_;
bool pieceHashValidationEnabled_;
#ifdef ENABLE_MESSAGE_DIGEST
- SharedHandle<MessageDigest> messageDigest_;
+ std::shared_ptr<MessageDigest> messageDigest_;
#endif // ENABLE_MESSAGE_DIGEST
- void validatePieceHash(const SharedHandle<Segment>& segment,
+ void validatePieceHash(const std::shared_ptr<Segment>& segment,
const std::string& expectedPieceHash,
const std::string& actualPieceHash);
void checkLowestDownloadSpeed() const;
- void completeSegment(cuid_t cuid, const SharedHandle<Segment>& segment);
+ void completeSegment(cuid_t cuid, const std::shared_ptr<Segment>& segment);
- SharedHandle<StreamFilter> streamFilter_;
+ std::shared_ptr<StreamFilter> streamFilter_;
bool sinkFilterOnly_;
protected:
@@ -81,20 +81,20 @@ protected:
virtual int64_t getRequestEndOffset() const = 0;
public:
DownloadCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s,
- const SharedHandle<SocketRecvBuffer>& socketRecvBuffer);
+ const std::shared_ptr<SocketCore>& s,
+ const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer);
virtual ~DownloadCommand();
- const SharedHandle<StreamFilter>& getStreamFilter() const
+ const std::shared_ptr<StreamFilter>& getStreamFilter() const
{
return streamFilter_;
}
- void installStreamFilter(const SharedHandle<StreamFilter>& streamFilter);
+ void installStreamFilter(const std::shared_ptr<StreamFilter>& streamFilter);
void setStartupIdleTime(time_t startupIdleTime)
{
diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc
index 1191259a..7bb307e7 100644
--- a/src/DownloadContext.cc
+++ b/src/DownloadContext.cc
@@ -67,7 +67,7 @@ DownloadContext::DownloadContext(int32_t pieceLength,
downloadStopTime_(0),
acceptMetalink_(true)
{
- SharedHandle<FileEntry> fileEntry(new FileEntry(path, totalLength, 0));
+ std::shared_ptr<FileEntry> fileEntry(new FileEntry(path, totalLength, 0));
fileEntries_.push_back(fileEntry);
}
@@ -91,19 +91,19 @@ int64_t DownloadContext::calculateSessionTime() const
return startTime.differenceInMillis(downloadStopTime_);
}
-SharedHandle<FileEntry>
+std::shared_ptr<FileEntry>
DownloadContext::findFileEntryByOffset(int64_t offset) const
{
if(fileEntries_.empty() ||
(offset > 0 && fileEntries_.back()->getLastOffset() <= offset)) {
- return SharedHandle<FileEntry>();
+ return std::shared_ptr<FileEntry>();
}
- SharedHandle<FileEntry> obj(new FileEntry());
+ std::shared_ptr<FileEntry> obj(new FileEntry());
obj->setOffset(offset);
- std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
std::upper_bound(fileEntries_.begin(), fileEntries_.end(), obj,
- DerefLess<SharedHandle<FileEntry> >());
+ DerefLess<std::shared_ptr<FileEntry> >());
if(i != fileEntries_.end() && (*i)->getOffset() == offset) {
return *i;
} else {
@@ -148,17 +148,17 @@ void DownloadContext::setFileFilter(SegList<int>& sgl)
}
void DownloadContext::setAttribute
-(ContextAttributeType key, const SharedHandle<ContextAttribute>& value)
+(ContextAttributeType key, const std::shared_ptr<ContextAttribute>& value)
{
assert(key < MAX_CTX_ATTR);
attrs_[key] = value;
}
-const SharedHandle<ContextAttribute>& DownloadContext::getAttribute
+const std::shared_ptr<ContextAttribute>& DownloadContext::getAttribute
(ContextAttributeType key)
{
assert(key < MAX_CTX_ATTR);
- const SharedHandle<ContextAttribute>& attr = attrs_[key];
+ const std::shared_ptr<ContextAttribute>& attr = attrs_[key];
if(attr) {
return attr;
} else {
@@ -170,12 +170,12 @@ const SharedHandle<ContextAttribute>& DownloadContext::getAttribute
bool DownloadContext::hasAttribute(ContextAttributeType key) const
{
assert(key < MAX_CTX_ATTR);
- return attrs_[key];
+ return attrs_[key].get();
}
void DownloadContext::releaseRuntimeResource()
{
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
fileEntries_.begin(), eoi = fileEntries_.end(); i != eoi; ++i) {
(*i)->putBackRequest();
(*i)->releaseRuntimeResource();
@@ -211,22 +211,22 @@ const std::string& DownloadContext::getBasePath() const
}
}
-SharedHandle<FileEntry>
+std::shared_ptr<FileEntry>
DownloadContext::getFirstRequestedFileEntry() const
{
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
fileEntries_.begin(), eoi = fileEntries_.end(); i != eoi; ++i) {
if((*i)->isRequested()) {
return *i;
}
}
- return SharedHandle<FileEntry>();
+ return std::shared_ptr<FileEntry>();
}
size_t DownloadContext::countRequestedFileEntry() const
{
size_t numFiles = 0;
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
fileEntries_.begin(), eoi = fileEntries_.end(); i != eoi; ++i) {
if((*i)->isRequested()) {
++numFiles;
@@ -274,7 +274,7 @@ void DownloadContext::setBasePath(const std::string& basePath)
basePath_ = basePath;
}
-void DownloadContext::setSignature(const SharedHandle<Signature>& signature)
+void DownloadContext::setSignature(const std::shared_ptr<Signature>& signature)
{
signature_ = signature;
}
diff --git a/src/DownloadContext.h b/src/DownloadContext.h
index 8ba146e3..ee5df7be 100644
--- a/src/DownloadContext.h
+++ b/src/DownloadContext.h
@@ -40,8 +40,8 @@
#include <cassert>
#include <string>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
#include "A2STR.h"
#include "ValueBase.h"
@@ -58,7 +58,7 @@ class FileEntry;
class DownloadContext
{
private:
- std::vector<SharedHandle<FileEntry> > fileEntries_;
+ std::vector<std::shared_ptr<FileEntry> > fileEntries_;
std::vector<std::string> pieceHashes_;
@@ -78,13 +78,13 @@ private:
RequestGroup* ownerRequestGroup_;
- std::vector<SharedHandle<ContextAttribute> > attrs_;
+ std::vector<std::shared_ptr<ContextAttribute> > attrs_;
NetStat netStat_;
Timer downloadStopTime_;
- SharedHandle<Signature> signature_;
+ std::shared_ptr<Signature> signature_;
// This member variable is required to avoid to use parse Metalink
// (including both Metalink XML and Metalink/HTTP) twice.
bool acceptMetalink_;
@@ -123,12 +123,12 @@ public:
void markTotalLengthIsKnown() { knowsTotalLength_ = true; }
- const std::vector<SharedHandle<FileEntry> >& getFileEntries() const
+ const std::vector<std::shared_ptr<FileEntry> >& getFileEntries() const
{
return fileEntries_;
}
- const SharedHandle<FileEntry>& getFirstFileEntry() const
+ const std::shared_ptr<FileEntry>& getFirstFileEntry() const
{
assert(!fileEntries_.empty());
return fileEntries_[0];
@@ -136,8 +136,8 @@ public:
// This function returns first FileEntry whose isRequested() returns
// true. If there is no such FileEntry, returns
- // SharedHandle<FileEntry>().
- SharedHandle<FileEntry> getFirstRequestedFileEntry() const;
+ // std::shared_ptr<FileEntry>().
+ std::shared_ptr<FileEntry> getFirstRequestedFileEntry() const;
size_t countRequestedFileEntry() const;
@@ -169,9 +169,9 @@ public:
void setBasePath(const std::string& basePath);
- const SharedHandle<Signature>& getSignature() const { return signature_; }
+ const std::shared_ptr<Signature>& getSignature() const { return signature_; }
- void setSignature(const SharedHandle<Signature>& signature);
+ void setSignature(const std::shared_ptr<Signature>& signature);
RequestGroup* getOwnerRequestGroup() { return ownerRequestGroup_; }
@@ -204,9 +204,9 @@ public:
}
void setAttribute
- (ContextAttributeType key, const SharedHandle<ContextAttribute>& value);
+ (ContextAttributeType key, const std::shared_ptr<ContextAttribute>& value);
- const SharedHandle<ContextAttribute>& getAttribute(ContextAttributeType key);
+ const std::shared_ptr<ContextAttribute>& getAttribute(ContextAttributeType key);
bool hasAttribute(ContextAttributeType key) const;
@@ -221,9 +221,9 @@ public:
int64_t calculateSessionTime() const;
- // Returns FileEntry at given offset. SharedHandle<FileEntry>() is
+ // Returns FileEntry at given offset. std::shared_ptr<FileEntry>() is
// returned if no such FileEntry is found.
- SharedHandle<FileEntry> findFileEntryByOffset(int64_t offset) const;
+ std::shared_ptr<FileEntry> findFileEntryByOffset(int64_t offset) const;
void releaseRuntimeResource();
diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc
index 18aa963b..071d2340 100644
--- a/src/DownloadEngine.cc
+++ b/src/DownloadEngine.cc
@@ -86,7 +86,7 @@ volatile sig_atomic_t globalHaltRequested = 0;
} // namespace global
-DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll)
+DownloadEngine::DownloadEngine(const std::shared_ptr<EventPoll>& eventPoll)
: eventPoll_(eventPoll),
haltRequested_(0),
noWait_(true),
@@ -186,28 +186,28 @@ void DownloadEngine::waitData()
eventPoll_->poll(tv);
}
-bool DownloadEngine::addSocketForReadCheck(const SharedHandle<SocketCore>& socket,
+bool DownloadEngine::addSocketForReadCheck(const std::shared_ptr<SocketCore>& socket,
Command* command)
{
return eventPoll_->addEvents(socket->getSockfd(), command,
EventPoll::EVENT_READ);
}
-bool DownloadEngine::deleteSocketForReadCheck(const SharedHandle<SocketCore>& socket,
+bool DownloadEngine::deleteSocketForReadCheck(const std::shared_ptr<SocketCore>& socket,
Command* command)
{
return eventPoll_->deleteEvents(socket->getSockfd(), command,
EventPoll::EVENT_READ);
}
-bool DownloadEngine::addSocketForWriteCheck(const SharedHandle<SocketCore>& socket,
+bool DownloadEngine::addSocketForWriteCheck(const std::shared_ptr<SocketCore>& socket,
Command* command)
{
return eventPoll_->addEvents(socket->getSockfd(), command,
EventPoll::EVENT_WRITE);
}
-bool DownloadEngine::deleteSocketForWriteCheck(const SharedHandle<SocketCore>& socket,
+bool DownloadEngine::deleteSocketForWriteCheck(const std::shared_ptr<SocketCore>& socket,
Command* command)
{
return eventPoll_->deleteEvents(socket->getSockfd(), command,
@@ -258,20 +258,20 @@ void DownloadEngine::requestForceHalt()
requestGroupMan_->forceHalt();
}
-void DownloadEngine::setStatCalc(const SharedHandle<StatCalc>& statCalc)
+void DownloadEngine::setStatCalc(const std::shared_ptr<StatCalc>& statCalc)
{
statCalc_ = statCalc;
}
#ifdef ENABLE_ASYNC_DNS
bool DownloadEngine::addNameResolverCheck
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
return eventPoll_->addNameResolver(resolver, command);
}
bool DownloadEngine::deleteNameResolverCheck
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
return eventPoll_->deleteNameResolver(resolver, command);
}
@@ -336,7 +336,7 @@ void DownloadEngine::poolSocket
const std::string& username,
const std::string& proxyhost,
uint16_t proxyport,
- const SharedHandle<SocketCore>& sock,
+ const std::shared_ptr<SocketCore>& sock,
const std::string& options,
time_t timeout)
{
@@ -349,7 +349,7 @@ void DownloadEngine::poolSocket
uint16_t port,
const std::string& proxyhost,
uint16_t proxyport,
- const SharedHandle<SocketCore>& sock,
+ const std::shared_ptr<SocketCore>& sock,
time_t timeout)
{
SocketPoolEntry e(sock, timeout);
@@ -358,7 +358,7 @@ void DownloadEngine::poolSocket
namespace {
bool getPeerInfo(std::pair<std::string, uint16_t>& res,
- const SharedHandle<SocketCore>& socket)
+ const std::shared_ptr<SocketCore>& socket)
{
try {
socket->getPeerInfo(res);
@@ -372,9 +372,9 @@ bool getPeerInfo(std::pair<std::string, uint16_t>& res,
}
} // namespace
-void DownloadEngine::poolSocket(const SharedHandle<Request>& request,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<SocketCore>& socket,
+void DownloadEngine::poolSocket(const std::shared_ptr<Request>& request,
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<SocketCore>& socket,
time_t timeout)
{
if(!proxyRequest) {
@@ -392,10 +392,10 @@ void DownloadEngine::poolSocket(const SharedHandle<Request>& request,
}
void DownloadEngine::poolSocket
-(const SharedHandle<Request>& request,
+(const std::shared_ptr<Request>& request,
const std::string& username,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<SocketCore>& socket,
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<SocketCore>& socket,
const std::string& options,
time_t timeout)
{
@@ -432,12 +432,12 @@ DownloadEngine::findSocketPoolEntry(const std::string& key)
return socketPool_.end();
}
-SharedHandle<SocketCore>
+std::shared_ptr<SocketCore>
DownloadEngine::popPooledSocket
(const std::string& ipaddr, uint16_t port,
const std::string& proxyhost, uint16_t proxyport)
{
- SharedHandle<SocketCore> s;
+ std::shared_ptr<SocketCore> s;
std::multimap<std::string, SocketPoolEntry>::iterator i =
findSocketPoolEntry
(createSockPoolKey(ipaddr, port, A2STR::NIL, proxyhost, proxyport));
@@ -448,14 +448,14 @@ DownloadEngine::popPooledSocket
return s;
}
-SharedHandle<SocketCore>
+std::shared_ptr<SocketCore>
DownloadEngine::popPooledSocket
(std::string& options,
const std::string& ipaddr, uint16_t port,
const std::string& username,
const std::string& proxyhost, uint16_t proxyport)
{
- SharedHandle<SocketCore> s;
+ std::shared_ptr<SocketCore> s;
std::multimap<std::string, SocketPoolEntry>::iterator i =
findSocketPoolEntry
(createSockPoolKey(ipaddr, port, username, proxyhost, proxyport));
@@ -467,11 +467,11 @@ DownloadEngine::popPooledSocket
return s;
}
-SharedHandle<SocketCore>
+std::shared_ptr<SocketCore>
DownloadEngine::popPooledSocket
(const std::vector<std::string>& ipaddrs, uint16_t port)
{
- SharedHandle<SocketCore> s;
+ std::shared_ptr<SocketCore> s;
for(std::vector<std::string>::const_iterator i = ipaddrs.begin(),
eoi = ipaddrs.end(); i != eoi; ++i) {
s = popPooledSocket(*i, port, A2STR::NIL, 0);
@@ -482,13 +482,13 @@ DownloadEngine::popPooledSocket
return s;
}
-SharedHandle<SocketCore>
+std::shared_ptr<SocketCore>
DownloadEngine::popPooledSocket
(std::string& options,
const std::vector<std::string>& ipaddrs, uint16_t port,
const std::string& username)
{
- SharedHandle<SocketCore> s;
+ std::shared_ptr<SocketCore> s;
for(std::vector<std::string>::const_iterator i = ipaddrs.begin(),
eoi = ipaddrs.end(); i != eoi; ++i) {
s = popPooledSocket(options, *i, port, username, A2STR::NIL, 0);
@@ -500,7 +500,7 @@ DownloadEngine::popPooledSocket
}
DownloadEngine::SocketPoolEntry::SocketPoolEntry
-(const SharedHandle<SocketCore>& socket,
+(const std::shared_ptr<SocketCore>& socket,
const std::string& options,
time_t timeout)
: socket_(socket),
@@ -509,7 +509,7 @@ DownloadEngine::SocketPoolEntry::SocketPoolEntry
{}
DownloadEngine::SocketPoolEntry::SocketPoolEntry
-(const SharedHandle<SocketCore>& socket, time_t timeout)
+(const std::shared_ptr<SocketCore>& socket, time_t timeout)
: socket_(socket),
timeout_(timeout)
{}
@@ -551,7 +551,7 @@ void DownloadEngine::removeCachedIPAddress
}
void DownloadEngine::setAuthConfigFactory
-(const SharedHandle<AuthConfigFactory>& factory)
+(const std::shared_ptr<AuthConfigFactory>& factory)
{
authConfigFactory_ = factory;
}
@@ -572,19 +572,19 @@ void DownloadEngine::addCommand(Command* command)
}
void DownloadEngine::setRequestGroupMan
-(const SharedHandle<RequestGroupMan>& rgman)
+(const std::shared_ptr<RequestGroupMan>& rgman)
{
requestGroupMan_ = rgman;
}
void DownloadEngine::setFileAllocationMan
-(const SharedHandle<FileAllocationMan>& faman)
+(const std::shared_ptr<FileAllocationMan>& faman)
{
fileAllocationMan_ = faman;
}
void DownloadEngine::setCheckIntegrityMan
-(const SharedHandle<CheckIntegrityMan>& ciman)
+(const std::shared_ptr<CheckIntegrityMan>& ciman)
{
checkIntegrityMan_ = ciman;
}
@@ -604,7 +604,7 @@ void DownloadEngine::setAsyncDNSServers(ares_addr_node* asyncDNSServers)
#ifdef ENABLE_WEBSOCKET
void DownloadEngine::setWebSocketSessionMan
-(const SharedHandle<rpc::WebSocketSessionMan>& wsman)
+(const std::shared_ptr<rpc::WebSocketSessionMan>& wsman)
{
webSocketSessionMan_ = wsman;
}
diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h
index b26d3dda..242769fe 100644
--- a/src/DownloadEngine.h
+++ b/src/DownloadEngine.h
@@ -41,8 +41,8 @@
#include <deque>
#include <map>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "a2netcompat.h"
#include "TimerA2.h"
#include "a2io.h"
@@ -80,15 +80,15 @@ private:
std::string sessionId_;
- SharedHandle<EventPoll> eventPoll_;
+ std::shared_ptr<EventPoll> eventPoll_;
- SharedHandle<StatCalc> statCalc_;
+ std::shared_ptr<StatCalc> statCalc_;
int haltRequested_;
class SocketPoolEntry {
private:
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<SocketCore> socket_;
// protocol specific option string
std::string options_;
@@ -96,18 +96,18 @@ private:
Timer registeredTime_;
public:
- SocketPoolEntry(const SharedHandle<SocketCore>& socket,
+ SocketPoolEntry(const std::shared_ptr<SocketCore>& socket,
const std::string& option,
time_t timeout);
- SocketPoolEntry(const SharedHandle<SocketCore>& socket,
+ SocketPoolEntry(const std::shared_ptr<SocketCore>& socket,
time_t timeout);
~SocketPoolEntry();
bool isTimeout() const;
- const SharedHandle<SocketCore>& getSocket() const
+ const std::shared_ptr<SocketCore>& getSocket() const
{
return socket_;
}
@@ -133,10 +133,10 @@ private:
std::deque<Command*> routineCommands_;
- SharedHandle<CookieStorage> cookieStorage_;
+ std::shared_ptr<CookieStorage> cookieStorage_;
#ifdef ENABLE_BITTORRENT
- SharedHandle<BtRegistry> btRegistry_;
+ std::shared_ptr<BtRegistry> btRegistry_;
#endif // ENABLE_BITTORRENT
CUIDCounter cuidCounter_;
@@ -145,12 +145,12 @@ private:
ares_addr_node* asyncDNSServers_;
#endif // HAVE_ARES_ADDR_NODE
- SharedHandle<DNSCache> dnsCache_;
+ std::shared_ptr<DNSCache> dnsCache_;
- SharedHandle<AuthConfigFactory> authConfigFactory_;
+ std::shared_ptr<AuthConfigFactory> authConfigFactory_;
#ifdef ENABLE_WEBSOCKET
- SharedHandle<rpc::WebSocketSessionMan> webSocketSessionMan_;
+ std::shared_ptr<rpc::WebSocketSessionMan> webSocketSessionMan_;
#endif // ENABLE_WEBSOCKET
/**
@@ -168,12 +168,12 @@ private:
findSocketPoolEntry(const std::string& key);
std::deque<Command*> commands_;
- SharedHandle<RequestGroupMan> requestGroupMan_;
- SharedHandle<FileAllocationMan> fileAllocationMan_;
- SharedHandle<CheckIntegrityMan> checkIntegrityMan_;
+ std::shared_ptr<RequestGroupMan> requestGroupMan_;
+ std::shared_ptr<FileAllocationMan> fileAllocationMan_;
+ std::shared_ptr<CheckIntegrityMan> checkIntegrityMan_;
Option* option_;
public:
- DownloadEngine(const SharedHandle<EventPoll>& eventPoll);
+ DownloadEngine(const std::shared_ptr<EventPoll>& eventPoll);
~DownloadEngine();
@@ -183,20 +183,20 @@ public:
// processed. Otherwise, returns 0.
int run(bool oneshot=false);
- bool addSocketForReadCheck(const SharedHandle<SocketCore>& socket,
+ bool addSocketForReadCheck(const std::shared_ptr<SocketCore>& socket,
Command* command);
- bool deleteSocketForReadCheck(const SharedHandle<SocketCore>& socket,
+ bool deleteSocketForReadCheck(const std::shared_ptr<SocketCore>& socket,
Command* command);
- bool addSocketForWriteCheck(const SharedHandle<SocketCore>& socket,
+ bool addSocketForWriteCheck(const std::shared_ptr<SocketCore>& socket,
Command* command);
- bool deleteSocketForWriteCheck(const SharedHandle<SocketCore>& socket,
+ bool deleteSocketForWriteCheck(const std::shared_ptr<SocketCore>& socket,
Command* command);
#ifdef ENABLE_ASYNC_DNS
- bool addNameResolverCheck(const SharedHandle<AsyncNameResolver>& resolver,
+ bool addNameResolverCheck(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command);
- bool deleteNameResolverCheck(const SharedHandle<AsyncNameResolver>& resolver,
+ bool deleteNameResolverCheck(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command);
#endif // ENABLE_ASYNC_DNS
@@ -204,26 +204,26 @@ public:
void addCommand(Command* command);
- const SharedHandle<RequestGroupMan>& getRequestGroupMan() const
+ const std::shared_ptr<RequestGroupMan>& getRequestGroupMan() const
{
return requestGroupMan_;
}
- void setRequestGroupMan(const SharedHandle<RequestGroupMan>& rgman);
+ void setRequestGroupMan(const std::shared_ptr<RequestGroupMan>& rgman);
- const SharedHandle<FileAllocationMan>& getFileAllocationMan() const
+ const std::shared_ptr<FileAllocationMan>& getFileAllocationMan() const
{
return fileAllocationMan_;
}
- void setFileAllocationMan(const SharedHandle<FileAllocationMan>& faman);
+ void setFileAllocationMan(const std::shared_ptr<FileAllocationMan>& faman);
- const SharedHandle<CheckIntegrityMan>& getCheckIntegrityMan() const
+ const std::shared_ptr<CheckIntegrityMan>& getCheckIntegrityMan() const
{
return checkIntegrityMan_;
}
- void setCheckIntegrityMan(const SharedHandle<CheckIntegrityMan>& ciman);
+ void setCheckIntegrityMan(const std::shared_ptr<CheckIntegrityMan>& ciman);
Option* getOption() const
{
@@ -235,7 +235,7 @@ public:
option_ = op;
}
- void setStatCalc(const SharedHandle<StatCalc>& statCalc);
+ void setStatCalc(const std::shared_ptr<StatCalc>& statCalc);
bool isHaltRequested() const
{
@@ -258,57 +258,57 @@ public:
void poolSocket(const std::string& ipaddr, uint16_t port,
const std::string& username,
const std::string& proxyhost, uint16_t proxyport,
- const SharedHandle<SocketCore>& sock,
+ const std::shared_ptr<SocketCore>& sock,
const std::string& options,
time_t timeout = 15);
- void poolSocket(const SharedHandle<Request>& request,
+ void poolSocket(const std::shared_ptr<Request>& request,
const std::string& username,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<SocketCore>& socket,
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<SocketCore>& socket,
const std::string& options,
time_t timeout = 15);
void poolSocket(const std::string& ipaddr, uint16_t port,
const std::string& proxyhost, uint16_t proxyport,
- const SharedHandle<SocketCore>& sock,
+ const std::shared_ptr<SocketCore>& sock,
time_t timeout = 15);
- void poolSocket(const SharedHandle<Request>& request,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<SocketCore>& socket,
+ void poolSocket(const std::shared_ptr<Request>& request,
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<SocketCore>& socket,
time_t timeout = 15);
- SharedHandle<SocketCore> popPooledSocket
+ std::shared_ptr<SocketCore> popPooledSocket
(const std::string& ipaddr,
uint16_t port,
const std::string& proxyhost, uint16_t proxyport);
- SharedHandle<SocketCore> popPooledSocket
+ std::shared_ptr<SocketCore> popPooledSocket
(std::string& options,
const std::string& ipaddr,
uint16_t port,
const std::string& username,
const std::string& proxyhost, uint16_t proxyport);
- SharedHandle<SocketCore>
+ std::shared_ptr<SocketCore>
popPooledSocket
(const std::vector<std::string>& ipaddrs, uint16_t port);
- SharedHandle<SocketCore>
+ std::shared_ptr<SocketCore>
popPooledSocket
(std::string& options,
const std::vector<std::string>& ipaddrs,
uint16_t port,
const std::string& username);
- const SharedHandle<CookieStorage>& getCookieStorage() const
+ const std::shared_ptr<CookieStorage>& getCookieStorage() const
{
return cookieStorage_;
}
#ifdef ENABLE_BITTORRENT
- const SharedHandle<BtRegistry>& getBtRegistry() const
+ const std::shared_ptr<BtRegistry>& getBtRegistry() const
{
return btRegistry_;
}
@@ -334,9 +334,9 @@ public:
void removeCachedIPAddress(const std::string& hostname, uint16_t port);
- void setAuthConfigFactory(const SharedHandle<AuthConfigFactory>& factory);
+ void setAuthConfigFactory(const std::shared_ptr<AuthConfigFactory>& factory);
- const SharedHandle<AuthConfigFactory>& getAuthConfigFactory() const
+ const std::shared_ptr<AuthConfigFactory>& getAuthConfigFactory() const
{
return authConfigFactory_;
}
@@ -359,8 +359,8 @@ public:
#ifdef ENABLE_WEBSOCKET
void setWebSocketSessionMan
- (const SharedHandle<rpc::WebSocketSessionMan>& wsman);
- const SharedHandle<rpc::WebSocketSessionMan>& getWebSocketSessionMan() const
+ (const std::shared_ptr<rpc::WebSocketSessionMan>& wsman);
+ const std::shared_ptr<rpc::WebSocketSessionMan>& getWebSocketSessionMan() const
{
return webSocketSessionMan_;
}
diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc
index 164b1b15..8c7ace30 100644
--- a/src/DownloadEngineFactory.cc
+++ b/src/DownloadEngineFactory.cc
@@ -84,17 +84,17 @@ namespace aria2 {
DownloadEngineFactory::DownloadEngineFactory() {}
-SharedHandle<DownloadEngine>
+std::shared_ptr<DownloadEngine>
DownloadEngineFactory::newDownloadEngine
-(Option* op, const std::vector<SharedHandle<RequestGroup> >& requestGroups)
+(Option* op, const std::vector<std::shared_ptr<RequestGroup> >& requestGroups)
{
const size_t MAX_CONCURRENT_DOWNLOADS =
op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS);
- SharedHandle<EventPoll> eventPoll;
+ std::shared_ptr<EventPoll> eventPoll;
const std::string& pollMethod = op->get(PREF_EVENT_POLL);
#ifdef HAVE_LIBUV
if (pollMethod == V_LIBUV) {
- SharedHandle<LibuvEventPoll> ep(new LibuvEventPoll());
+ std::shared_ptr<LibuvEventPoll> ep(new LibuvEventPoll());
if (!ep->good()) {
throw DL_ABORT_EX("Initializing LibuvEventPoll failed."
" Try --event-poll=select");
@@ -105,7 +105,7 @@ DownloadEngineFactory::newDownloadEngine
#endif // HAVE_LIBUV
#ifdef HAVE_EPOLL
if(pollMethod == V_EPOLL) {
- SharedHandle<EpollEventPoll> ep(new EpollEventPoll());
+ std::shared_ptr<EpollEventPoll> ep(new EpollEventPoll());
if(ep->good()) {
eventPoll = ep;
} else {
@@ -116,7 +116,7 @@ DownloadEngineFactory::newDownloadEngine
#endif // HAVE_EPLL
#ifdef HAVE_KQUEUE
if(pollMethod == V_KQUEUE) {
- SharedHandle<KqueueEventPoll> kp(new KqueueEventPoll());
+ std::shared_ptr<KqueueEventPoll> kp(new KqueueEventPoll());
if(kp->good()) {
eventPoll = kp;
} else {
@@ -127,7 +127,7 @@ DownloadEngineFactory::newDownloadEngine
#endif // HAVE_KQUEUE
#ifdef HAVE_PORT_ASSOCIATE
if(pollMethod == V_PORT) {
- SharedHandle<PortEventPoll> pp(new PortEventPoll());
+ std::shared_ptr<PortEventPoll> pp(new PortEventPoll());
if(pp->good()) {
eventPoll = pp;
} else {
@@ -146,19 +146,19 @@ DownloadEngineFactory::newDownloadEngine
} else {
abort();
}
- SharedHandle<DownloadEngine> e(new DownloadEngine(eventPoll));
+ std::shared_ptr<DownloadEngine> e(new DownloadEngine(eventPoll));
e->setOption(op);
- SharedHandle<RequestGroupMan>
+ std::shared_ptr<RequestGroupMan>
requestGroupMan(new RequestGroupMan(requestGroups, MAX_CONCURRENT_DOWNLOADS,
op));
requestGroupMan->initWrDiskCache();
e->setRequestGroupMan(requestGroupMan);
e->setFileAllocationMan
- (SharedHandle<FileAllocationMan>(new FileAllocationMan()));
+ (std::shared_ptr<FileAllocationMan>(new FileAllocationMan()));
#ifdef ENABLE_MESSAGE_DIGEST
e->setCheckIntegrityMan
- (SharedHandle<CheckIntegrityMan>(new CheckIntegrityMan()));
+ (std::shared_ptr<CheckIntegrityMan>(new CheckIntegrityMan()));
#endif // ENABLE_MESSAGE_DIGEST
e->addRoutineCommand(new FillRequestGroupCommand(e->newCUID(), e.get()));
e->addRoutineCommand(new FileAllocationDispatcherCommand
diff --git a/src/DownloadEngineFactory.h b/src/DownloadEngineFactory.h
index 1d42a252..14c75b5a 100644
--- a/src/DownloadEngineFactory.h
+++ b/src/DownloadEngineFactory.h
@@ -38,8 +38,7 @@
#include "common.h"
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -51,9 +50,9 @@ class DownloadEngineFactory {
public:
DownloadEngineFactory();
- SharedHandle<DownloadEngine>
+ std::shared_ptr<DownloadEngine>
newDownloadEngine
- (Option* op, const std::vector<SharedHandle<RequestGroup> >& requestGroups);
+ (Option* op, const std::vector<std::shared_ptr<RequestGroup> >& requestGroups);
};
} // namespace aria2
diff --git a/src/DownloadFailureException.cc b/src/DownloadFailureException.cc
index 90411460..07ce3da9 100644
--- a/src/DownloadFailureException.cc
+++ b/src/DownloadFailureException.cc
@@ -36,9 +36,9 @@
namespace aria2 {
-SharedHandle<Exception> DownloadFailureException::copy() const
+std::shared_ptr<Exception> DownloadFailureException::copy() const
{
- SharedHandle<Exception> e(new DownloadFailureException(*this));
+ std::shared_ptr<Exception> e(new DownloadFailureException(*this));
return e;
}
diff --git a/src/DownloadFailureException.h b/src/DownloadFailureException.h
index a4f29206..2d147a34 100644
--- a/src/DownloadFailureException.h
+++ b/src/DownloadFailureException.h
@@ -44,7 +44,7 @@ namespace aria2 {
*/
class DownloadFailureException:public RecoverableException {
protected:
- virtual SharedHandle<Exception> copy() const;
+ virtual std::shared_ptr<Exception> copy() const;
public:
DownloadFailureException(const char* file, int line, const std::string& msg);
diff --git a/src/DownloadHandler.cc b/src/DownloadHandler.cc
index bde2b746..48b53636 100644
--- a/src/DownloadHandler.cc
+++ b/src/DownloadHandler.cc
@@ -49,7 +49,7 @@ bool DownloadHandler::canHandle(const RequestGroup* requestGroup) const
}
void DownloadHandler::setCriteria
-(const SharedHandle<RequestGroupCriteria>& criteria)
+(const std::shared_ptr<RequestGroupCriteria>& criteria)
{
criteria_ = criteria;
}
diff --git a/src/DownloadHandler.h b/src/DownloadHandler.h
index a042eec7..220a126f 100644
--- a/src/DownloadHandler.h
+++ b/src/DownloadHandler.h
@@ -38,8 +38,7 @@
#include "common.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -49,7 +48,7 @@ class RequestGroupCriteria;
class DownloadHandler
{
private:
- SharedHandle<RequestGroupCriteria> criteria_;
+ std::shared_ptr<RequestGroupCriteria> criteria_;
public:
DownloadHandler();
@@ -57,7 +56,7 @@ public:
bool canHandle(const RequestGroup* requestGroup) const;
- void setCriteria(const SharedHandle<RequestGroupCriteria>& criteria);
+ void setCriteria(const std::shared_ptr<RequestGroupCriteria>& criteria);
};
} // namespace aria2
diff --git a/src/DownloadHandlerFactory.cc b/src/DownloadHandlerFactory.cc
index 7ca0a904..3263fc71 100644
--- a/src/DownloadHandlerFactory.cc
+++ b/src/DownloadHandlerFactory.cc
@@ -44,35 +44,35 @@ namespace aria2 {
#ifdef ENABLE_METALINK
-SharedHandle<PreDownloadHandler>
+std::shared_ptr<PreDownloadHandler>
DownloadHandlerFactory::metalinkPreDownloadHandler_;
-SharedHandle<PostDownloadHandler>
+std::shared_ptr<PostDownloadHandler>
DownloadHandlerFactory::metalinkPostDownloadHandler_;
#endif // ENABLE_METALINK
#ifdef ENABLE_BITTORRENT
-SharedHandle<PreDownloadHandler>
+std::shared_ptr<PreDownloadHandler>
DownloadHandlerFactory::btPreDownloadHandler_;
-SharedHandle<PostDownloadHandler>
+std::shared_ptr<PostDownloadHandler>
DownloadHandlerFactory::btPostDownloadHandler_;
-SharedHandle<PostDownloadHandler>
+std::shared_ptr<PostDownloadHandler>
DownloadHandlerFactory::btMetadataPostDownloadHandler_;
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
-SharedHandle<PreDownloadHandler>
+std::shared_ptr<PreDownloadHandler>
DownloadHandlerFactory::getMetalinkPreDownloadHandler()
{
if(!metalinkPreDownloadHandler_) {
metalinkPreDownloadHandler_.reset(new MemoryBufferPreDownloadHandler());
- SharedHandle<RequestGroupCriteria> criteria
+ std::shared_ptr<RequestGroupCriteria> criteria
(new ContentTypeRequestGroupCriteria
(getMetalinkContentTypes(), getMetalinkExtensions()));
metalinkPreDownloadHandler_->setCriteria(criteria);
@@ -80,7 +80,7 @@ DownloadHandlerFactory::getMetalinkPreDownloadHandler()
return metalinkPreDownloadHandler_;
}
-SharedHandle<PostDownloadHandler>
+std::shared_ptr<PostDownloadHandler>
DownloadHandlerFactory::getMetalinkPostDownloadHandler()
{
if(!metalinkPostDownloadHandler_) {
@@ -93,14 +93,14 @@ DownloadHandlerFactory::getMetalinkPostDownloadHandler()
#ifdef ENABLE_BITTORRENT
-SharedHandle<PreDownloadHandler>
+std::shared_ptr<PreDownloadHandler>
DownloadHandlerFactory::getBtPreDownloadHandler()
{
if(!btPreDownloadHandler_) {
btPreDownloadHandler_.reset
(new bittorrent::MemoryBencodePreDownloadHandler());
- SharedHandle<RequestGroupCriteria> criteria
+ std::shared_ptr<RequestGroupCriteria> criteria
(new ContentTypeRequestGroupCriteria
(getBtContentTypes(), getBtExtensions()));
btPreDownloadHandler_->setCriteria(criteria);
@@ -108,7 +108,7 @@ DownloadHandlerFactory::getBtPreDownloadHandler()
return btPreDownloadHandler_;
}
-SharedHandle<PostDownloadHandler>
+std::shared_ptr<PostDownloadHandler>
DownloadHandlerFactory::getBtPostDownloadHandler()
{
if(!btPostDownloadHandler_) {
@@ -117,7 +117,7 @@ DownloadHandlerFactory::getBtPostDownloadHandler()
return btPostDownloadHandler_;
}
-SharedHandle<PostDownloadHandler>
+std::shared_ptr<PostDownloadHandler>
DownloadHandlerFactory::getUTMetadataPostDownloadHandler()
{
if(!btMetadataPostDownloadHandler_) {
diff --git a/src/DownloadHandlerFactory.h b/src/DownloadHandlerFactory.h
index 34c7cd23..5aff1f89 100644
--- a/src/DownloadHandlerFactory.h
+++ b/src/DownloadHandlerFactory.h
@@ -36,7 +36,9 @@
#define D_DOWNLOAD_HANDLER_FACTORY_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "MemoryBufferPreDownloadHandler.h"
#ifdef ENABLE_BITTORRENT
# include "MemoryBencodePreDownloadHandler.h"
@@ -56,40 +58,40 @@ class DownloadHandlerFactory
{
private:
#ifdef ENABLE_METALINK
- static SharedHandle<PreDownloadHandler>
+ static std::shared_ptr<PreDownloadHandler>
metalinkPreDownloadHandler_;
- static SharedHandle<PostDownloadHandler>
+ static std::shared_ptr<PostDownloadHandler>
metalinkPostDownloadHandler_;
#endif // ENABLE_METALINK
#ifdef ENABLE_BITTORRENT
- static SharedHandle<PreDownloadHandler>
+ static std::shared_ptr<PreDownloadHandler>
btPreDownloadHandler_;
- static SharedHandle<PostDownloadHandler>
+ static std::shared_ptr<PostDownloadHandler>
btPostDownloadHandler_;
- static SharedHandle<PostDownloadHandler>
+ static std::shared_ptr<PostDownloadHandler>
btMetadataPostDownloadHandler_;
#endif // ENABLE_BITTORRENT
public:
#ifdef ENABLE_METALINK
- static SharedHandle<PreDownloadHandler>
+ static std::shared_ptr<PreDownloadHandler>
getMetalinkPreDownloadHandler();
- static SharedHandle<PostDownloadHandler>
+ static std::shared_ptr<PostDownloadHandler>
getMetalinkPostDownloadHandler();
#endif // ENABLE_METALINK
#ifdef ENABLE_BITTORRENT
- static SharedHandle<PreDownloadHandler>
+ static std::shared_ptr<PreDownloadHandler>
getBtPreDownloadHandler();
- static SharedHandle<PostDownloadHandler>
+ static std::shared_ptr<PostDownloadHandler>
getBtPostDownloadHandler();
- static SharedHandle<PostDownloadHandler>
+ static std::shared_ptr<PostDownloadHandler>
getUTMetadataPostDownloadHandler();
#endif // ENABLE_BITTORRENT
};
diff --git a/src/DownloadResult.h b/src/DownloadResult.h
index b6972ad0..729e97d2 100644
--- a/src/DownloadResult.h
+++ b/src/DownloadResult.h
@@ -41,8 +41,8 @@
#include <string>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "error_code.h"
#include "RequestGroup.h"
@@ -54,9 +54,9 @@ class MetadataInfo;
struct DownloadResult
{
- SharedHandle<GroupId> gid;
+ std::shared_ptr<GroupId> gid;
- std::vector<SharedHandle<FileEntry> > fileEntries;
+ std::vector<std::shared_ptr<FileEntry> > fileEntries;
bool inMemoryDownload;
@@ -75,9 +75,9 @@ struct DownloadResult
// RequestGroup.cc::belongsToGID_.
a2_gid_t belongsTo;
- SharedHandle<Option> option;
+ std::shared_ptr<Option> option;
- SharedHandle<MetadataInfo> metadataInfo;
+ std::shared_ptr<MetadataInfo> metadataInfo;
int64_t totalLength;
diff --git a/src/EpollEventPoll.cc b/src/EpollEventPoll.cc
index 75408037..773310d5 100644
--- a/src/EpollEventPoll.cc
+++ b/src/EpollEventPoll.cc
@@ -168,7 +168,7 @@ int translateEvents(EventPoll::EventType events)
bool EpollEventPoll::addEvents(sock_t socket,
const EpollEventPoll::KEvent& event)
{
- SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
+ std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
KSocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
int r = 0;
int errNum = 0;
@@ -220,7 +220,7 @@ bool EpollEventPoll::addEvents(sock_t socket, Command* command,
#ifdef ENABLE_ASYNC_DNS
bool EpollEventPoll::addEvents(sock_t socket, Command* command, int events,
- const SharedHandle<AsyncNameResolver>& rs)
+ const std::shared_ptr<AsyncNameResolver>& rs)
{
return addEvents(socket, KADNSEvent(rs, command, socket, events));
}
@@ -229,7 +229,7 @@ bool EpollEventPoll::addEvents(sock_t socket, Command* command, int events,
bool EpollEventPoll::deleteEvents(sock_t socket,
const EpollEventPoll::KEvent& event)
{
- SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
+ std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
KSocketEntrySet::iterator i = socketEntries_.find(socketEntry);
if(i == socketEntries_.end()) {
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
@@ -268,7 +268,7 @@ bool EpollEventPoll::deleteEvents(sock_t socket,
#ifdef ENABLE_ASYNC_DNS
bool EpollEventPoll::deleteEvents(sock_t socket, Command* command,
- const SharedHandle<AsyncNameResolver>& rs)
+ const std::shared_ptr<AsyncNameResolver>& rs)
{
return deleteEvents(socket, KADNSEvent(rs, command, socket, 0));
}
@@ -283,9 +283,9 @@ bool EpollEventPoll::deleteEvents(sock_t socket, Command* command,
#ifdef ENABLE_ASYNC_DNS
bool EpollEventPoll::addNameResolver
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
- SharedHandle<KAsyncNameResolverEntry> entry
+ std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
KAsyncNameResolverEntrySet::iterator itr =
nameResolverEntries_.lower_bound(entry);
@@ -299,9 +299,9 @@ bool EpollEventPoll::addNameResolver
}
bool EpollEventPoll::deleteNameResolver
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
- SharedHandle<KAsyncNameResolverEntry> entry
+ std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
KAsyncNameResolverEntrySet::iterator itr =
nameResolverEntries_.find(entry);
diff --git a/src/EpollEventPoll.h b/src/EpollEventPoll.h
index 390fd07a..4529dc01 100644
--- a/src/EpollEventPoll.h
+++ b/src/EpollEventPoll.h
@@ -70,12 +70,12 @@ private:
friend int accumulateEvent(int events, const KEvent& event);
private:
- typedef std::set<SharedHandle<KSocketEntry>,
- DerefLess<SharedHandle<KSocketEntry> > > KSocketEntrySet;
+ typedef std::set<std::shared_ptr<KSocketEntry>,
+ DerefLess<std::shared_ptr<KSocketEntry> > > KSocketEntrySet;
KSocketEntrySet socketEntries_;
#ifdef ENABLE_ASYNC_DNS
- typedef std::set<SharedHandle<KAsyncNameResolverEntry>,
- DerefLess<SharedHandle<KAsyncNameResolverEntry> > >
+ typedef std::set<std::shared_ptr<KAsyncNameResolverEntry>,
+ DerefLess<std::shared_ptr<KAsyncNameResolverEntry> > >
KAsyncNameResolverEntrySet;
KAsyncNameResolverEntrySet nameResolverEntries_;
#endif // ENABLE_ASYNC_DNS
@@ -93,10 +93,10 @@ private:
bool deleteEvents(sock_t socket, const KEvent& event);
bool addEvents(sock_t socket, Command* command, int events,
- const SharedHandle<AsyncNameResolver>& rs);
+ const std::shared_ptr<AsyncNameResolver>& rs);
bool deleteEvents(sock_t socket, Command* command,
- const SharedHandle<AsyncNameResolver>& rs);
+ const std::shared_ptr<AsyncNameResolver>& rs);
public:
EpollEventPoll();
@@ -114,10 +114,10 @@ public:
Command* command, EventPoll::EventType events);
#ifdef ENABLE_ASYNC_DNS
- virtual bool addNameResolver(const SharedHandle<AsyncNameResolver>& resolver,
+ virtual bool addNameResolver(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command);
virtual bool deleteNameResolver
- (const SharedHandle<AsyncNameResolver>& resolver, Command* command);
+ (const std::shared_ptr<AsyncNameResolver>& resolver, Command* command);
#endif // ENABLE_ASYNC_DNS
static const int IEV_READ = EPOLLIN;
diff --git a/src/Event.h b/src/Event.h
index 2cf6c0ac..249b2ce5 100644
--- a/src/Event.h
+++ b/src/Event.h
@@ -40,8 +40,8 @@
#include <deque>
#include <algorithm>
#include <functional>
+#include <memory>
-#include "SharedHandle.h"
#include "a2netcompat.h"
#include "Command.h"
#ifdef ENABLE_ASYNC_DNS
@@ -59,10 +59,10 @@ public:
virtual int getEvents() const = 0;
- virtual void addSelf(const SharedHandle<SocketEntry>& socketEntry) const = 0;
+ virtual void addSelf(const std::shared_ptr<SocketEntry>& socketEntry) const = 0;
virtual void removeSelf
- (const SharedHandle<SocketEntry>& socketEntry) const = 0;
+ (const std::shared_ptr<SocketEntry>& socketEntry) const = 0;
};
template<typename SocketEntry, typename EventPoll>
@@ -124,12 +124,12 @@ public:
}
}
- virtual void addSelf(const SharedHandle<SocketEntry>& socketEntry) const
+ virtual void addSelf(const std::shared_ptr<SocketEntry>& socketEntry) const
{
socketEntry->addCommandEvent(*this);
}
- virtual void removeSelf(const SharedHandle<SocketEntry>& socketEntry) const
+ virtual void removeSelf(const std::shared_ptr<SocketEntry>& socketEntry) const
{
socketEntry->removeCommandEvent(*this);
}
@@ -140,12 +140,12 @@ public:
template<typename SocketEntry, typename EventPoll>
class ADNSEvent : public Event<SocketEntry> {
private:
- SharedHandle<AsyncNameResolver> resolver_;
+ std::shared_ptr<AsyncNameResolver> resolver_;
Command* command_;
sock_t socket_;
int events_;
public:
- ADNSEvent(const SharedHandle<AsyncNameResolver>& resolver, Command* command,
+ ADNSEvent(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command,
sock_t socket, int events):
resolver_(resolver), command_(command), socket_(socket), events_(events) {}
@@ -179,12 +179,12 @@ public:
command_->setStatusActive();
}
- virtual void addSelf(const SharedHandle<SocketEntry>& socketEntry) const
+ virtual void addSelf(const std::shared_ptr<SocketEntry>& socketEntry) const
{
socketEntry->addADNSEvent(*this);
}
- virtual void removeSelf(const SharedHandle<SocketEntry>& socketEntry) const
+ virtual void removeSelf(const std::shared_ptr<SocketEntry>& socketEntry) const
{
socketEntry->removeADNSEvent(*this);
}
@@ -308,7 +308,7 @@ public:
template<typename EventPoll>
class AsyncNameResolverEntry {
private:
- SharedHandle<AsyncNameResolver> nameResolver_;
+ std::shared_ptr<AsyncNameResolver> nameResolver_;
Command* command_;
@@ -317,7 +317,7 @@ private:
sock_t sockets_[ARES_GETSOCK_MAXNUM];
public:
- AsyncNameResolverEntry(const SharedHandle<AsyncNameResolver>& nameResolver,
+ AsyncNameResolverEntry(const std::shared_ptr<AsyncNameResolver>& nameResolver,
Command* command):
nameResolver_(nameResolver), command_(command), socketsSize_(0) {}
diff --git a/src/EventPoll.h b/src/EventPoll.h
index 7217ef25..9d02d9b9 100644
--- a/src/EventPoll.h
+++ b/src/EventPoll.h
@@ -36,7 +36,9 @@
#define D_EVENT_POLL_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "a2time.h"
#include "a2netcompat.h"
@@ -66,10 +68,10 @@ public:
EventType events) = 0;
#ifdef ENABLE_ASYNC_DNS
- virtual bool addNameResolver(const SharedHandle<AsyncNameResolver>& resolver,
+ virtual bool addNameResolver(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command) = 0;
virtual bool deleteNameResolver
- (const SharedHandle<AsyncNameResolver>& resolver, Command* command) = 0;
+ (const std::shared_ptr<AsyncNameResolver>& resolver, Command* command) = 0;
#endif // ENABLE_ASYNC_DNS
};
diff --git a/src/Exception.cc b/src/Exception.cc
index 1492b59b..8fa7c0bc 100644
--- a/src/Exception.cc
+++ b/src/Exception.cc
@@ -124,7 +124,7 @@ std::string Exception::stackTrace() const
}
s << "errorCode=" << errorCode_ << " ";
s << what() << "\n";
- SharedHandle<Exception> e = cause_;
+ std::shared_ptr<Exception> e = cause_;
while(e) {
s << " -> " << "[" << e->file_ << ":" << e->line_ << "] ";
if(e->getErrNum()) {
diff --git a/src/Exception.h b/src/Exception.h
index e8fb76cb..e7a7ace6 100644
--- a/src/Exception.h
+++ b/src/Exception.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "error_code.h"
namespace aria2 {
@@ -57,9 +57,9 @@ private:
error_code::Value errorCode_;
// Exception that this object wraps. Normally this cause_ is the
// root cause of this exception.
- SharedHandle<Exception> cause_;
+ std::shared_ptr<Exception> cause_;
protected:
- virtual SharedHandle<Exception> copy() const = 0;
+ virtual std::shared_ptr<Exception> copy() const = 0;
public:
Exception(const char* file, int line, const std::string& msg);
diff --git a/src/ExtensionMessageFactory.h b/src/ExtensionMessageFactory.h
index 9a49d9d0..6cde2041 100644
--- a/src/ExtensionMessageFactory.h
+++ b/src/ExtensionMessageFactory.h
@@ -36,7 +36,8 @@
#define D_EXTENSION_MESSAGE_FACTORY_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -46,7 +47,7 @@ class ExtensionMessageFactory {
public:
virtual ~ExtensionMessageFactory() {}
- virtual SharedHandle<ExtensionMessage>
+ virtual std::shared_ptr<ExtensionMessage>
createMessage(const unsigned char* data, size_t length) = 0;
};
diff --git a/src/FatalException.cc b/src/FatalException.cc
index e8b19687..7d545599 100644
--- a/src/FatalException.cc
+++ b/src/FatalException.cc
@@ -36,9 +36,9 @@
namespace aria2 {
-SharedHandle<Exception> FatalException::copy() const
+std::shared_ptr<Exception> FatalException::copy() const
{
- SharedHandle<Exception> e(new FatalException(*this));
+ std::shared_ptr<Exception> e(new FatalException(*this));
return e;
}
diff --git a/src/FatalException.h b/src/FatalException.h
index 852ae613..8b777a25 100644
--- a/src/FatalException.h
+++ b/src/FatalException.h
@@ -40,7 +40,7 @@ namespace aria2 {
class FatalException:public Exception {
protected:
- virtual SharedHandle<Exception> copy() const;
+ virtual std::shared_ptr<Exception> copy() const;
public:
FatalException(const char* file, int line, const std::string& msg);
diff --git a/src/FeatureConfig.cc b/src/FeatureConfig.cc
index c78043f5..a61c9283 100644
--- a/src/FeatureConfig.cc
+++ b/src/FeatureConfig.cc
@@ -173,23 +173,23 @@ std::string usedLibs()
{
std::string res;
#ifdef HAVE_ZLIB
- res += "zlib/"ZLIB_VERSION" ";
+ res += "zlib/" ZLIB_VERSION " ";
#endif // HAVE_ZLIB
#ifdef HAVE_LIBXML2
- res += "libxml2/"LIBXML_DOTTED_VERSION" ";
+ res += "libxml2/" LIBXML_DOTTED_VERSION " ";
#endif // HAVE_LIBXML2
#ifdef HAVE_LIBEXPAT
res += fmt("expat/%d.%d.%d ",
XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION);
#endif // HAVE_LIBEXPAT
#ifdef HAVE_SQLITE3
- res += "sqlite3/"SQLITE_VERSION" ";
+ res += "sqlite3/" SQLITE_VERSION " ";
#endif // HAVE_SQLITE3
#ifdef HAVE_APPLETLS
res += "appleTLS ";
#endif // HAVE_APPLETLS
#ifdef HAVE_LIBGNUTLS
- res += "GnuTLS/"GNUTLS_VERSION" ";
+ res += "GnuTLS/" GNUTLS_VERSION " ";
#endif // HAVE_LIBGNUTLS
#ifdef HAVE_OPENSSL
res += fmt("OpenSSL/%ld.%ld.%ld",
@@ -211,10 +211,10 @@ std::string usedLibs()
__GNU_MP_VERSION_PATCHLEVEL);
#endif // HAVE_LIBGMP
#ifdef HAVE_LIBGCRYPT
- res += "libgcrypt/"GCRYPT_VERSION" ";
+ res += "libgcrypt/" GCRYPT_VERSION " ";
#endif // HAVE_LIBGCRYPT
#ifdef HAVE_LIBCARES
- res += "c-ares/"ARES_VERSION_STR" ";
+ res += "c-ares/" ARES_VERSION_STR " ";
#endif // HAVE_LIBCARES
if(!res.empty()) {
res.erase(res.length()-1);
diff --git a/src/FeedbackURISelector.cc b/src/FeedbackURISelector.cc
index 7e2f6563..903abd0b 100644
--- a/src/FeedbackURISelector.cc
+++ b/src/FeedbackURISelector.cc
@@ -50,7 +50,7 @@
namespace aria2 {
FeedbackURISelector::FeedbackURISelector
-(const SharedHandle<ServerStatMan>& serverStatMan)
+(const std::shared_ptr<ServerStatMan>& serverStatMan)
: serverStatMan_(serverStatMan)
{}
@@ -100,7 +100,7 @@ std::string FeedbackURISelector::selectRarer
}
std::string host = uri::getFieldString(us, USR_HOST, (*i).c_str());
std::string protocol = uri::getFieldString(us, USR_SCHEME, (*i).c_str());
- SharedHandle<ServerStat> ss = serverStatMan_->find(host, protocol);
+ std::shared_ptr<ServerStat> ss = serverStatMan_->find(host, protocol);
if(ss && ss->isError()) {
A2_LOG_DEBUG(fmt("Error not considered: %s", (*i).c_str()));
continue;
@@ -128,7 +128,7 @@ std::string FeedbackURISelector::selectFaster
const size_t NUM_URI = 10;
// Ignore low speed server
const int SPEED_THRESHOLD = 20*1024;
- std::vector<std::pair<SharedHandle<ServerStat>, std::string> > fastCands;
+ std::vector<std::pair<std::shared_ptr<ServerStat>, std::string> > fastCands;
std::vector<std::string> normCands;
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi && fastCands.size() < NUM_URI; ++i) {
@@ -143,7 +143,7 @@ std::string FeedbackURISelector::selectFaster
continue;
}
std::string protocol = uri::getFieldString(us, USR_SCHEME, (*i).c_str());
- SharedHandle<ServerStat> ss = serverStatMan_->find(host, protocol);
+ std::shared_ptr<ServerStat> ss = serverStatMan_->find(host, protocol);
if(!ss) {
normCands.push_back(*i);
} else if(ss->isOK()) {
diff --git a/src/FeedbackURISelector.h b/src/FeedbackURISelector.h
index 6f5ced64..dedc8f1d 100644
--- a/src/FeedbackURISelector.h
+++ b/src/FeedbackURISelector.h
@@ -35,7 +35,8 @@
#ifndef D_FEEDBACK_URI_SELECTOR_H
#define D_FEEDBACK_URI_SELECTOR_H
#include "URISelector.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -43,7 +44,7 @@ class ServerStatMan;
class FeedbackURISelector:public URISelector {
private:
- SharedHandle<ServerStatMan> serverStatMan_;
+ std::shared_ptr<ServerStatMan> serverStatMan_;
std::string selectRarer
(const std::deque<std::string>& uris,
@@ -53,7 +54,7 @@ private:
(const std::deque<std::string>& uris,
const std::vector<std::pair<size_t, std::string> >& usedHosts);
public:
- FeedbackURISelector(const SharedHandle<ServerStatMan>& serverStatMan);
+ FeedbackURISelector(const std::shared_ptr<ServerStatMan>& serverStatMan);
virtual ~FeedbackURISelector();
diff --git a/src/FileAllocationCommand.cc b/src/FileAllocationCommand.cc
index 5486503a..54c4e7a5 100644
--- a/src/FileAllocationCommand.cc
+++ b/src/FileAllocationCommand.cc
@@ -54,7 +54,7 @@ namespace aria2 {
FileAllocationCommand::FileAllocationCommand
(cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e,
- const SharedHandle<FileAllocationEntry>& fileAllocationEntry):
+ const std::shared_ptr<FileAllocationEntry>& fileAllocationEntry):
RealtimeCommand(cuid, requestGroup, e),
fileAllocationEntry_(fileAllocationEntry) {}
diff --git a/src/FileAllocationCommand.h b/src/FileAllocationCommand.h
index ef38b5a2..cad28e4c 100644
--- a/src/FileAllocationCommand.h
+++ b/src/FileAllocationCommand.h
@@ -36,7 +36,9 @@
#define D_FILE_ALLOCATION_COMMAND_H
#include "RealtimeCommand.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "TimerA2.h"
namespace aria2 {
@@ -45,12 +47,12 @@ class FileAllocationEntry;
class FileAllocationCommand : public RealtimeCommand {
private:
- SharedHandle<FileAllocationEntry> fileAllocationEntry_;
+ std::shared_ptr<FileAllocationEntry> fileAllocationEntry_;
Timer timer_;
public:
FileAllocationCommand(cuid_t cuid, RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<FileAllocationEntry>& fileAllocationEntry);
+ const std::shared_ptr<FileAllocationEntry>& fileAllocationEntry);
virtual ~FileAllocationCommand();
diff --git a/src/FileAllocationDispatcherCommand.cc b/src/FileAllocationDispatcherCommand.cc
index 00c282e9..70e6573a 100644
--- a/src/FileAllocationDispatcherCommand.cc
+++ b/src/FileAllocationDispatcherCommand.cc
@@ -45,13 +45,13 @@ namespace aria2 {
FileAllocationDispatcherCommand::FileAllocationDispatcherCommand
(cuid_t cuid,
- const SharedHandle<FileAllocationMan>& fileAllocMan,
+ const std::shared_ptr<FileAllocationMan>& fileAllocMan,
DownloadEngine* e)
: SequentialDispatcherCommand<FileAllocationEntry>(cuid, fileAllocMan, e)
{}
Command* FileAllocationDispatcherCommand::createCommand
-(const SharedHandle<FileAllocationEntry>& entry)
+(const std::shared_ptr<FileAllocationEntry>& entry)
{
cuid_t newCUID = getDownloadEngine()->newCUID();
A2_LOG_INFO(fmt(MSG_FILE_ALLOCATION_DISPATCH, newCUID));
diff --git a/src/FileAllocationDispatcherCommand.h b/src/FileAllocationDispatcherCommand.h
index 88c03af6..f41fb1b7 100644
--- a/src/FileAllocationDispatcherCommand.h
+++ b/src/FileAllocationDispatcherCommand.h
@@ -47,11 +47,11 @@ class FileAllocationDispatcherCommand :
public:
FileAllocationDispatcherCommand
(cuid_t cuid,
- const SharedHandle<FileAllocationMan>& fileAllocMan,
+ const std::shared_ptr<FileAllocationMan>& fileAllocMan,
DownloadEngine* e);
protected:
virtual Command* createCommand
- (const SharedHandle<FileAllocationEntry>& entry);
+ (const std::shared_ptr<FileAllocationEntry>& entry);
};
} // namespace aria2
diff --git a/src/FileAllocationEntry.h b/src/FileAllocationEntry.h
index 26228413..74a455d5 100644
--- a/src/FileAllocationEntry.h
+++ b/src/FileAllocationEntry.h
@@ -38,8 +38,8 @@
#include "RequestGroupEntry.h"
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "ProgressAwareEntry.h"
namespace aria2 {
@@ -50,7 +50,7 @@ class DownloadEngine;
class FileAllocationEntry : public RequestGroupEntry, public ProgressAwareEntry {
private:
- SharedHandle<FileAllocationIterator> fileAllocationIterator_;
+ std::shared_ptr<FileAllocationIterator> fileAllocationIterator_;
public:
FileAllocationEntry(RequestGroup* requestGroup, Command* nextCommand = 0);
diff --git a/src/FileAllocationIterator.h b/src/FileAllocationIterator.h
index f2b8b2c8..86562c24 100644
--- a/src/FileAllocationIterator.h
+++ b/src/FileAllocationIterator.h
@@ -36,7 +36,7 @@
#define D_FILE_ALLOCATION_ITERATOR_H
#include "common.h"
-#include "SharedHandle.h"
+
#include <unistd.h>
namespace aria2 {
diff --git a/src/FileEntry.cc b/src/FileEntry.cc
index edf0a36e..e3be45eb 100644
--- a/src/FileEntry.cc
+++ b/src/FileEntry.cc
@@ -52,8 +52,8 @@
namespace aria2 {
bool FileEntry::RequestFaster::operator()
- (const SharedHandle<Request>& lhs,
- const SharedHandle<Request>& rhs) const
+ (const std::shared_ptr<Request>& lhs,
+ const std::shared_ptr<Request>& rhs) const
{
if(!lhs->getPeerStat()) {
return false;
@@ -139,15 +139,15 @@ OutputIterator enumerateInFlightHosts
}
} // namespace
-SharedHandle<Request>
+std::shared_ptr<Request>
FileEntry::getRequest
-(const SharedHandle<URISelector>& selector,
+(const std::shared_ptr<URISelector>& selector,
bool uriReuse,
const std::vector<std::pair<size_t, std::string> >& usedHosts,
const std::string& referer,
const std::string& method)
{
- SharedHandle<Request> req;
+ std::shared_ptr<Request> req;
if(requestPool_.empty()) {
std::vector<std::string> inFlightHosts;
enumerateInFlightHosts(inFlightRequests_.begin(), inFlightRequests_.end(),
@@ -215,54 +215,54 @@ FileEntry::getRequest
return req;
}
-SharedHandle<Request>
-FileEntry::findFasterRequest(const SharedHandle<Request>& base)
+std::shared_ptr<Request>
+FileEntry::findFasterRequest(const std::shared_ptr<Request>& base)
{
const int startupIdleTime = 10;
if(requestPool_.empty() ||
lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) {
- return SharedHandle<Request>();
+ return std::shared_ptr<Request>();
}
- const SharedHandle<PeerStat>& fastest =
+ const std::shared_ptr<PeerStat>& fastest =
(*requestPool_.begin())->getPeerStat();
if(!fastest) {
- return SharedHandle<Request>();
+ return std::shared_ptr<Request>();
}
- const SharedHandle<PeerStat>& basestat = base->getPeerStat();
+ const std::shared_ptr<PeerStat>& basestat = base->getPeerStat();
// TODO hard coded value. See PREF_STARTUP_IDLE_TIME
if(!basestat ||
(basestat->getDownloadStartTime().
difference(global::wallclock()) >= startupIdleTime &&
fastest->getAvgDownloadSpeed()*0.8 > basestat->calculateDownloadSpeed())){
// TODO we should consider that "fastest" is very slow.
- SharedHandle<Request> fastestRequest = *requestPool_.begin();
+ std::shared_ptr<Request> fastestRequest = *requestPool_.begin();
requestPool_.erase(requestPool_.begin());
inFlightRequests_.insert(fastestRequest);
lastFasterReplace_ = global::wallclock();
return fastestRequest;
}
- return SharedHandle<Request>();
+ return std::shared_ptr<Request>();
}
-SharedHandle<Request>
+std::shared_ptr<Request>
FileEntry::findFasterRequest
-(const SharedHandle<Request>& base,
+(const std::shared_ptr<Request>& base,
const std::vector<std::pair<size_t, std::string> >& usedHosts,
- const SharedHandle<ServerStatMan>& serverStatMan)
+ const std::shared_ptr<ServerStatMan>& serverStatMan)
{
const int startupIdleTime = 10;
const int SPEED_THRESHOLD = 20*1024;
if(lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) {
- return SharedHandle<Request>();
+ return std::shared_ptr<Request>();
}
std::vector<std::string> inFlightHosts;
enumerateInFlightHosts(inFlightRequests_.begin(), inFlightRequests_.end(),
std::back_inserter(inFlightHosts));
- const SharedHandle<PeerStat>& basestat = base->getPeerStat();
+ const std::shared_ptr<PeerStat>& basestat = base->getPeerStat();
A2_LOG_DEBUG("Search faster server using ServerStat.");
// Use first 10 good URIs to introduce some randomness.
const size_t NUM_URI = 10;
- std::vector<std::pair<SharedHandle<ServerStat>, std::string> > fastCands;
+ std::vector<std::pair<std::shared_ptr<ServerStat>, std::string> > fastCands;
std::vector<std::string> normCands;
for(std::deque<std::string>::const_iterator i = uris_.begin(),
eoi = uris_.end(); i != eoi && fastCands.size() < NUM_URI; ++i) {
@@ -284,7 +284,7 @@ FileEntry::findFasterRequest
A2_LOG_DEBUG(fmt("%s is in usedHosts, not considered", (*i).c_str()));
continue;
}
- SharedHandle<ServerStat> ss = serverStatMan->find(host, protocol);
+ std::shared_ptr<ServerStat> ss = serverStatMan->find(host, protocol);
if(ss && ss->isOK()) {
if((basestat &&
ss->getDownloadSpeed() > basestat->calculateDownloadSpeed()*1.5) ||
@@ -295,7 +295,7 @@ FileEntry::findFasterRequest
}
if(!fastCands.empty()) {
std::sort(fastCands.begin(), fastCands.end(), ServerStatFaster());
- SharedHandle<Request> fastestRequest(new Request());
+ std::shared_ptr<Request> fastestRequest(new Request());
const std::string& uri = fastCands.front().second;
A2_LOG_DEBUG(fmt("Selected %s from fastCands", uri.c_str()));
fastestRequest->setUri(uri);
@@ -307,12 +307,12 @@ FileEntry::findFasterRequest
return fastestRequest;
}
A2_LOG_DEBUG("No faster server found.");
- return SharedHandle<Request>();
+ return std::shared_ptr<Request>();
}
-void FileEntry::storePool(const SharedHandle<Request>& request)
+void FileEntry::storePool(const std::shared_ptr<Request>& request)
{
- const SharedHandle<PeerStat>& peerStat = request->getPeerStat();
+ const std::shared_ptr<PeerStat>& peerStat = request->getPeerStat();
if(peerStat) {
// We need to calculate average download speed here in order to
// store Request in the right position in the pool.
@@ -321,7 +321,7 @@ void FileEntry::storePool(const SharedHandle<Request>& request)
requestPool_.insert(request);
}
-void FileEntry::poolRequest(const SharedHandle<Request>& request)
+void FileEntry::poolRequest(const std::shared_ptr<Request>& request)
{
removeRequest(request);
if(!request->removalRequested()) {
@@ -329,7 +329,7 @@ void FileEntry::poolRequest(const SharedHandle<Request>& request)
}
}
-bool FileEntry::removeRequest(const SharedHandle<Request>& request)
+bool FileEntry::removeRequest(const std::shared_ptr<Request>& request)
{
return inFlightRequests_.erase(request) == 1;
}
@@ -497,7 +497,7 @@ bool FileEntry::removeUri(const std::string& uri)
}
} else {
spentUris_.erase(itr);
- SharedHandle<Request> req;
+ std::shared_ptr<Request> req;
InFlightRequestSet::iterator riter =
findRequestByUri(inFlightRequests_.begin(), inFlightRequests_.end(), uri);
if(riter == inFlightRequests_.end()) {
@@ -588,7 +588,7 @@ bool FileEntry::emptyRequestUri() const
void writeFilePath
(std::ostream& o,
- const SharedHandle<FileEntry>& entry,
+ const std::shared_ptr<FileEntry>& entry,
bool memory)
{
if(entry->getPath().empty()) {
diff --git a/src/FileEntry.h b/src/FileEntry.h
index 9ba57f00..765d3104 100644
--- a/src/FileEntry.h
+++ b/src/FileEntry.h
@@ -42,8 +42,8 @@
#include <vector>
#include <ostream>
#include <set>
+#include <memory>
-#include "SharedHandle.h"
#include "File.h"
#include "Request.h"
#include "URIResult.h"
@@ -60,7 +60,7 @@ class ServerStatMan;
class FileEntry {
public:
- typedef std::set<SharedHandle<Request>, RefLess<Request> >
+ typedef std::set<std::shared_ptr<Request>, RefLess<Request> >
InFlightRequestSet;
private:
std::string path_;
@@ -72,11 +72,11 @@ private:
class RequestFaster {
public:
- bool operator()(const SharedHandle<Request>& lhs,
- const SharedHandle<Request>& rhs) const;
+ bool operator()(const std::shared_ptr<Request>& lhs,
+ const std::shared_ptr<Request>& rhs) const;
};
- typedef std::set<SharedHandle<Request>, RequestFaster> RequestPool;
+ typedef std::set<std::shared_ptr<Request>, RequestFaster> RequestPool;
RequestPool requestPool_;
InFlightRequestSet inFlightRequests_;
std::string contentType_;
@@ -88,7 +88,7 @@ private:
std::string originalName_;
Timer lastFasterReplace_;
- void storePool(const SharedHandle<Request>& request);
+ void storePool(const std::shared_ptr<Request>& request);
public:
FileEntry();
@@ -178,8 +178,8 @@ public:
// returns Request object either because uris_ is empty or all URI
// are not be usable because maxConnectionPerServer_ limit, then
// reuse used URIs and do selection again.
- SharedHandle<Request> getRequest
- (const SharedHandle<URISelector>& selector,
+ std::shared_ptr<Request> getRequest
+ (const std::shared_ptr<URISelector>& selector,
bool uriReuse,
const std::vector<std::pair<size_t, std::string> >& usedHosts,
const std::string& referer = A2STR::NIL,
@@ -188,18 +188,18 @@ public:
// Finds pooled Request object which is faster than passed one,
// comparing their PeerStat objects. If such Request is found, it is
// removed from the pool and returned.
- SharedHandle<Request> findFasterRequest(const SharedHandle<Request>& base);
+ std::shared_ptr<Request> findFasterRequest(const std::shared_ptr<Request>& base);
// Finds faster server using ServerStatMan.
- SharedHandle<Request>
+ std::shared_ptr<Request>
findFasterRequest
- (const SharedHandle<Request>& base,
+ (const std::shared_ptr<Request>& base,
const std::vector<std::pair<size_t, std::string> >& usedHosts,
- const SharedHandle<ServerStatMan>& serverStatMan);
+ const std::shared_ptr<ServerStatMan>& serverStatMan);
- void poolRequest(const SharedHandle<Request>& request);
+ void poolRequest(const std::shared_ptr<Request>& request);
- bool removeRequest(const SharedHandle<Request>& request);
+ bool removeRequest(const std::shared_ptr<Request>& request);
size_t countInFlightRequest() const;
@@ -277,9 +277,9 @@ public:
// Returns the first FileEntry which isRequested() method returns
// true. If no such FileEntry exists, then returns
-// SharedHandle<FileEntry>().
+// std::shared_ptr<FileEntry>().
template<typename InputIterator>
-SharedHandle<FileEntry> getFirstRequestedFileEntry
+std::shared_ptr<FileEntry> getFirstRequestedFileEntry
(InputIterator first, InputIterator last)
{
for(; first != last; ++first) {
@@ -287,7 +287,7 @@ SharedHandle<FileEntry> getFirstRequestedFileEntry
return *first;
}
}
- return SharedHandle<FileEntry>();
+ return std::shared_ptr<FileEntry>();
}
// Counts the number of files selected in the given iterator range
@@ -321,7 +321,7 @@ bool isUriSuppliedForRequsetFileEntry(InputIterator first, InputIterator last)
// FileEntry, writes "n/a" to o.
void writeFilePath
(std::ostream& o,
- const SharedHandle<FileEntry>& entry,
+ const std::shared_ptr<FileEntry>& entry,
bool memory);
// Writes first filename to given o. If memory is true, the output is
@@ -333,7 +333,7 @@ template<typename InputIterator>
void writeFilePath
(InputIterator first, InputIterator last, std::ostream& o, bool memory)
{
- SharedHandle<FileEntry> e = getFirstRequestedFileEntry(first, last);
+ std::shared_ptr<FileEntry> e = getFirstRequestedFileEntry(first, last);
if(!e) {
o << "n/a";
} else {
diff --git a/src/FillRequestGroupCommand.cc b/src/FillRequestGroupCommand.cc
index 414402f5..ddfbb8b6 100644
--- a/src/FillRequestGroupCommand.cc
+++ b/src/FillRequestGroupCommand.cc
@@ -60,7 +60,7 @@ bool FillRequestGroupCommand::execute()
if(e_->isHaltRequested()) {
return true;
}
- const SharedHandle<RequestGroupMan>& rgman = e_->getRequestGroupMan();
+ const std::shared_ptr<RequestGroupMan>& rgman = e_->getRequestGroupMan();
if(rgman->queueCheckRequested()) {
while(rgman->queueCheckRequested()) {
try {
diff --git a/src/FillRequestGroupCommand.h b/src/FillRequestGroupCommand.h
index 1702d514..dba0801d 100644
--- a/src/FillRequestGroupCommand.h
+++ b/src/FillRequestGroupCommand.h
@@ -36,7 +36,6 @@
#define D_FILL_REQUEST_GROUP_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
#include "a2time.h"
namespace aria2 {
diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc
index d05872cf..7e773cd2 100644
--- a/src/FtpConnection.cc
+++ b/src/FtpConnection.cc
@@ -62,9 +62,9 @@ namespace aria2 {
FtpConnection::FtpConnection
(cuid_t cuid,
- const SharedHandle<SocketCore>& socket,
- const SharedHandle<Request>& req,
- const SharedHandle<AuthConfig>& authConfig,
+ const std::shared_ptr<SocketCore>& socket,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<AuthConfig>& authConfig,
const Option* op)
: cuid_(cuid),
socket_(socket),
@@ -199,17 +199,17 @@ bool FtpConnection::sendPasv()
return socketBuffer_.sendBufferIsEmpty();
}
-SharedHandle<SocketCore> FtpConnection::createServerSocket()
+std::shared_ptr<SocketCore> FtpConnection::createServerSocket()
{
std::pair<std::string, uint16_t> addrinfo;
socket_->getAddrInfo(addrinfo);
- SharedHandle<SocketCore> serverSocket(new SocketCore());
+ std::shared_ptr<SocketCore> serverSocket(new SocketCore());
serverSocket->bind(addrinfo.first.c_str(), 0, AF_UNSPEC);
serverSocket->beginListen();
return serverSocket;
}
-bool FtpConnection::sendEprt(const SharedHandle<SocketCore>& serverSocket)
+bool FtpConnection::sendEprt(const std::shared_ptr<SocketCore>& serverSocket)
{
if(socketBuffer_.sendBufferIsEmpty()) {
sockaddr_union sockaddr;
@@ -229,7 +229,7 @@ bool FtpConnection::sendEprt(const SharedHandle<SocketCore>& serverSocket)
return socketBuffer_.sendBufferIsEmpty();
}
-bool FtpConnection::sendPort(const SharedHandle<SocketCore>& serverSocket)
+bool FtpConnection::sendPort(const std::shared_ptr<SocketCore>& serverSocket)
{
if(socketBuffer_.sendBufferIsEmpty()) {
std::pair<std::string, uint16_t> addrinfo;
@@ -249,7 +249,7 @@ bool FtpConnection::sendPort(const SharedHandle<SocketCore>& serverSocket)
return socketBuffer_.sendBufferIsEmpty();
}
-bool FtpConnection::sendRest(const SharedHandle<Segment>& segment)
+bool FtpConnection::sendRest(const std::shared_ptr<Segment>& segment)
{
if(socketBuffer_.sendBufferIsEmpty()) {
std::string request =
diff --git a/src/FtpConnection.h b/src/FtpConnection.h
index b6d3f12f..b751f50c 100644
--- a/src/FtpConnection.h
+++ b/src/FtpConnection.h
@@ -39,8 +39,8 @@
#include <utility>
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "TimeA2.h"
#include "SocketBuffer.h"
#include "Command.h"
@@ -56,10 +56,10 @@ class AuthConfig;
class FtpConnection {
private:
cuid_t cuid_;
- SharedHandle<SocketCore> socket_;
- SharedHandle<Request> req_;
+ std::shared_ptr<SocketCore> socket_;
+ std::shared_ptr<Request> req_;
- SharedHandle<AuthConfig> authConfig_;
+ std::shared_ptr<AuthConfig> authConfig_;
const Option* option_;
@@ -77,9 +77,9 @@ private:
//prepare for large banners
static const size_t MAX_RECV_BUFFER = 65536;
public:
- FtpConnection(cuid_t cuid, const SharedHandle<SocketCore>& socket,
- const SharedHandle<Request>& req,
- const SharedHandle<AuthConfig>& authConfig,
+ FtpConnection(cuid_t cuid, const std::shared_ptr<SocketCore>& socket,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<AuthConfig>& authConfig,
const Option* op);
~FtpConnection();
bool sendUser();
@@ -91,10 +91,10 @@ public:
bool sendSize();
bool sendEpsv();
bool sendPasv();
- SharedHandle<SocketCore> createServerSocket();
- bool sendEprt(const SharedHandle<SocketCore>& serverSocket);
- bool sendPort(const SharedHandle<SocketCore>& serverSocket);
- bool sendRest(const SharedHandle<Segment>& segment);
+ std::shared_ptr<SocketCore> createServerSocket();
+ bool sendEprt(const std::shared_ptr<SocketCore>& serverSocket);
+ bool sendPort(const std::shared_ptr<SocketCore>& serverSocket);
+ bool sendRest(const std::shared_ptr<Segment>& segment);
bool sendRetr();
int receiveResponse();
diff --git a/src/FtpDownloadCommand.cc b/src/FtpDownloadCommand.cc
index 84e6bc58..81f55541 100644
--- a/src/FtpDownloadCommand.cc
+++ b/src/FtpDownloadCommand.cc
@@ -50,15 +50,15 @@ namespace aria2 {
FtpDownloadCommand::FtpDownloadCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<FtpConnection>& ftpConnection,
+ const std::shared_ptr<FtpConnection>& ftpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& dataSocket,
- const SharedHandle<SocketCore>& ctrlSocket)
+ const std::shared_ptr<SocketCore>& dataSocket,
+ const std::shared_ptr<SocketCore>& ctrlSocket)
:DownloadCommand(cuid, req, fileEntry, requestGroup, e, dataSocket,
- SharedHandle<SocketRecvBuffer>
+ std::shared_ptr<SocketRecvBuffer>
(new SocketRecvBuffer(dataSocket))),
ftpConnection_(ftpConnection),
ctrlSocket_(ctrlSocket) {}
diff --git a/src/FtpDownloadCommand.h b/src/FtpDownloadCommand.h
index 24eeabe8..77b41172 100644
--- a/src/FtpDownloadCommand.h
+++ b/src/FtpDownloadCommand.h
@@ -43,21 +43,21 @@ class FtpConnection;
class FtpDownloadCommand : public DownloadCommand {
private:
- SharedHandle<FtpConnection> ftpConnection_;
+ std::shared_ptr<FtpConnection> ftpConnection_;
- SharedHandle<SocketCore> ctrlSocket_;
+ std::shared_ptr<SocketCore> ctrlSocket_;
protected:
virtual bool prepareForNextSegment();
virtual int64_t getRequestEndOffset() const;
public:
FtpDownloadCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<FtpConnection>& ftpConnection,
+ const std::shared_ptr<FtpConnection>& ftpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& dataSocket,
- const SharedHandle<SocketCore>& ctrlSocket);
+ const std::shared_ptr<SocketCore>& dataSocket,
+ const std::shared_ptr<SocketCore>& ctrlSocket);
virtual ~FtpDownloadCommand();
};
diff --git a/src/FtpFinishDownloadCommand.cc b/src/FtpFinishDownloadCommand.cc
index 1af8fdce..3002f631 100644
--- a/src/FtpFinishDownloadCommand.cc
+++ b/src/FtpFinishDownloadCommand.cc
@@ -56,12 +56,12 @@ namespace aria2 {
FtpFinishDownloadCommand::FtpFinishDownloadCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<FtpConnection>& ftpConnection,
+ const std::shared_ptr<FtpConnection>& ftpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket)
+ const std::shared_ptr<SocketCore>& socket)
:AbstractCommand(cuid, req, fileEntry, requestGroup, e, socket),
ftpConnection_(ftpConnection)
{}
diff --git a/src/FtpFinishDownloadCommand.h b/src/FtpFinishDownloadCommand.h
index fc9e24f3..fb3f1be2 100644
--- a/src/FtpFinishDownloadCommand.h
+++ b/src/FtpFinishDownloadCommand.h
@@ -43,19 +43,19 @@ class FtpConnection;
class FtpFinishDownloadCommand : public AbstractCommand {
private:
- SharedHandle<FtpConnection> ftpConnection_;
+ std::shared_ptr<FtpConnection> ftpConnection_;
protected:
virtual bool execute();
virtual bool executeInternal();
public:
FtpFinishDownloadCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<FtpConnection>& ftpConnection,
+ const std::shared_ptr<FtpConnection>& ftpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket);
+ const std::shared_ptr<SocketCore>& socket);
virtual ~FtpFinishDownloadCommand();
};
diff --git a/src/FtpInitiateConnectionCommand.cc b/src/FtpInitiateConnectionCommand.cc
index 80ebfb82..9b026a89 100644
--- a/src/FtpInitiateConnectionCommand.cc
+++ b/src/FtpInitiateConnectionCommand.cc
@@ -65,8 +65,8 @@ namespace aria2 {
FtpInitiateConnectionCommand::FtpInitiateConnectionCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e)
:InitiateConnectionCommand(cuid, req, fileEntry, requestGroup, e) {}
@@ -76,12 +76,12 @@ FtpInitiateConnectionCommand::~FtpInitiateConnectionCommand() {}
Command* FtpInitiateConnectionCommand::createNextCommand
(const std::string& hostname, const std::string& addr, uint16_t port,
const std::vector<std::string>& resolvedAddresses,
- const SharedHandle<Request>& proxyRequest)
+ const std::shared_ptr<Request>& proxyRequest)
{
Command* command;
if(proxyRequest) {
std::string options;
- SharedHandle<SocketCore> pooledSocket;
+ std::shared_ptr<SocketCore> pooledSocket;
std::string proxyMethod = resolveProxyMethod(getRequest()->getProtocol());
if(proxyMethod == V_GET) {
pooledSocket = getDownloadEngine()->popPooledSocket
@@ -112,11 +112,11 @@ Command* FtpInitiateConnectionCommand::createNextCommand
if(proxyMethod == V_GET) {
// Use GET for FTP via HTTP proxy.
getRequest()->setMethod(Request::METHOD_GET);
- SharedHandle<HttpRequestConnectChain> chain
+ std::shared_ptr<HttpRequestConnectChain> chain
(new HttpRequestConnectChain());
c->setControlChain(chain);
} else if(proxyMethod == V_TUNNEL) {
- SharedHandle<FtpTunnelRequestConnectChain> chain
+ std::shared_ptr<FtpTunnelRequestConnectChain> chain
(new FtpTunnelRequestConnectChain());
c->setControlChain(chain);
} else {
@@ -141,9 +141,9 @@ Command* FtpInitiateConnectionCommand::createNextCommand
} else if(proxyMethod == V_GET) {
// Use GET for FTP via HTTP proxy.
getRequest()->setMethod(Request::METHOD_GET);
- SharedHandle<SocketRecvBuffer> socketRecvBuffer
+ std::shared_ptr<SocketRecvBuffer> socketRecvBuffer
(new SocketRecvBuffer(pooledSocket));
- SharedHandle<HttpConnection> hc
+ std::shared_ptr<HttpConnection> hc
(new HttpConnection(getCuid(), pooledSocket, socketRecvBuffer));
HttpRequestCommand* c = new HttpRequestCommand(getCuid(),
@@ -162,7 +162,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
}
} else {
std::string options;
- SharedHandle<SocketCore> pooledSocket =
+ std::shared_ptr<SocketCore> pooledSocket =
getDownloadEngine()->popPooledSocket
(options, resolvedAddresses,
getRequest()->getPort(),
@@ -181,7 +181,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
getRequestGroup(),
getDownloadEngine(),
getSocket());
- SharedHandle<FtpNegotiationConnectChain> chain
+ std::shared_ptr<FtpNegotiationConnectChain> chain
(new FtpNegotiationConnectChain());
c->setControlChain(chain);
setupBackupConnection(hostname, addr, port, c);
diff --git a/src/FtpInitiateConnectionCommand.h b/src/FtpInitiateConnectionCommand.h
index 38d07609..46cead0d 100644
--- a/src/FtpInitiateConnectionCommand.h
+++ b/src/FtpInitiateConnectionCommand.h
@@ -44,10 +44,10 @@ protected:
virtual Command* createNextCommand
(const std::string& hostname, const std::string& addr, uint16_t port,
const std::vector<std::string>& resolvedAddresses,
- const SharedHandle<Request>& proxyRequest);
+ const std::shared_ptr<Request>& proxyRequest);
public:
- FtpInitiateConnectionCommand(cuid_t cuid, const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ FtpInitiateConnectionCommand(cuid_t cuid, const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup, DownloadEngine* e);
virtual ~FtpInitiateConnectionCommand();
diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc
index 8ed30e5b..1845a116 100644
--- a/src/FtpNegotiationCommand.cc
+++ b/src/FtpNegotiationCommand.cc
@@ -82,11 +82,11 @@ namespace aria2 {
FtpNegotiationCommand::FtpNegotiationCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket,
+ const std::shared_ptr<SocketCore>& socket,
Seq seq,
const std::string& baseWorkingDir):
AbstractCommand(cuid, req, fileEntry, requestGroup, e, socket),
@@ -401,7 +401,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(int64_t totalLength)
getRequestGroup()->initPieceStorage();
if(getDownloadContext()->isChecksumVerificationNeeded()) {
A2_LOG_DEBUG("Zero length file exists. Verify checksum.");
- SharedHandle<ChecksumCheckIntegrityEntry> entry
+ std::shared_ptr<ChecksumCheckIntegrityEntry> entry
(new ChecksumCheckIntegrityEntry(getRequestGroup()));
entry->initValidator();
getPieceStorage()->getDiskAdaptor()->openExistingFile();
@@ -435,7 +435,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(int64_t totalLength)
// HttpResponseCommand::handleOtherEncoding()
if(getDownloadContext()->isChecksumVerificationNeeded()) {
A2_LOG_DEBUG("Verify checksum for zero-length file");
- SharedHandle<ChecksumCheckIntegrityEntry> entry
+ std::shared_ptr<ChecksumCheckIntegrityEntry> entry
(new ChecksumCheckIntegrityEntry(getRequestGroup()));
entry->initValidator();
getDownloadEngine()->getCheckIntegrityMan()->pushEntry(entry);
@@ -455,9 +455,9 @@ bool FtpNegotiationCommand::onFileSizeDetermined(int64_t totalLength)
getSegmentMan()->getSegmentWithIndex(getCuid(), 0);
return true;
} else {
- SharedHandle<BtProgressInfoFile> progressInfoFile
+ std::shared_ptr<BtProgressInfoFile> progressInfoFile
(new DefaultBtProgressInfoFile
- (getDownloadContext(), SharedHandle<PieceStorage>(), getOption().get()));
+ (getDownloadContext(), std::shared_ptr<PieceStorage>(), getOption().get()));
getRequestGroup()->adjustFilename(progressInfoFile);
getRequestGroup()->initPieceStorage();
@@ -466,7 +466,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(int64_t totalLength)
return false;
}
- SharedHandle<CheckIntegrityEntry> checkIntegrityEntry =
+ std::shared_ptr<CheckIntegrityEntry> checkIntegrityEntry =
getRequestGroup()->createCheckIntegrityEntry();
if(!checkIntegrityEntry) {
sequence_ = SEQ_DOWNLOAD_ALREADY_COMPLETED;
@@ -684,7 +684,7 @@ bool FtpNegotiationCommand::preparePasvConnect() {
bool FtpNegotiationCommand::resolveProxy()
{
- SharedHandle<Request> proxyReq = createProxyRequest();
+ std::shared_ptr<Request> proxyReq = createProxyRequest();
std::vector<std::string> addrs;
proxyAddr_ = resolveHostname
(addrs, proxyReq->getHost(), proxyReq->getPort());
@@ -698,7 +698,7 @@ bool FtpNegotiationCommand::resolveProxy()
dataSocket_->establishConnection(proxyAddr_, proxyReq->getPort());
disableReadCheckSocket();
setWriteCheckSocket(dataSocket_);
- SharedHandle<SocketRecvBuffer> socketRecvBuffer
+ std::shared_ptr<SocketRecvBuffer> socketRecvBuffer
(new SocketRecvBuffer(dataSocket_));
http_.reset(new HttpConnection(getCuid(), dataSocket_, socketRecvBuffer));
sequence_ = SEQ_SEND_TUNNEL_REQUEST;
@@ -711,7 +711,7 @@ bool FtpNegotiationCommand::sendTunnelRequest()
if(dataSocket_->isReadable(0)) {
std::string error = getSocket()->getSocketError();
if(!error.empty()) {
- SharedHandle<Request> proxyReq = createProxyRequest();
+ std::shared_ptr<Request> proxyReq = createProxyRequest();
getDownloadEngine()->markBadIPAddress(proxyReq->getHost(),
proxyAddr_,proxyReq->getPort());
std::string nextProxyAddr = getDownloadEngine()->findCachedIPAddress
@@ -735,9 +735,9 @@ bool FtpNegotiationCommand::sendTunnelRequest()
}
}
}
- SharedHandle<HttpRequest> httpRequest(new HttpRequest());
+ std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
httpRequest->setUserAgent(getOption()->get(PREF_USER_AGENT));
- SharedHandle<Request> req(new Request());
+ std::shared_ptr<Request> req(new Request());
// Construct fake URI in order to use HttpRequest
std::pair<std::string, uint16_t> dataAddr;
uri::UriStruct us;
@@ -767,7 +767,7 @@ bool FtpNegotiationCommand::sendTunnelRequest()
bool FtpNegotiationCommand::recvTunnelResponse()
{
- SharedHandle<HttpResponse> httpResponse = http_->receiveResponse();
+ std::shared_ptr<HttpResponse> httpResponse = http_->receiveResponse();
if(!httpResponse) {
return false;
}
@@ -778,7 +778,7 @@ bool FtpNegotiationCommand::recvTunnelResponse()
return true;
}
-bool FtpNegotiationCommand::sendRestPasv(const SharedHandle<Segment>& segment) {
+bool FtpNegotiationCommand::sendRestPasv(const std::shared_ptr<Segment>& segment) {
//dataSocket_->setBlockingMode();
// Check connection is made properly
if(dataSocket_->isReadable(0)) {
@@ -792,7 +792,7 @@ bool FtpNegotiationCommand::sendRestPasv(const SharedHandle<Segment>& segment) {
return sendRest(segment);
}
-bool FtpNegotiationCommand::sendRest(const SharedHandle<Segment>& segment) {
+bool FtpNegotiationCommand::sendRest(const std::shared_ptr<Segment>& segment) {
if(ftp_->sendRest(segment)) {
disableWriteCheckSocket();
sequence_ = SEQ_RECV_REST;
@@ -802,7 +802,7 @@ bool FtpNegotiationCommand::sendRest(const SharedHandle<Segment>& segment) {
return false;
}
-bool FtpNegotiationCommand::recvRest(const SharedHandle<Segment>& segment) {
+bool FtpNegotiationCommand::recvRest(const std::shared_ptr<Segment>& segment) {
int status = ftp_->receiveResponse();
if(status == 0) {
return false;
@@ -864,7 +864,7 @@ bool FtpNegotiationCommand::waitConnection()
}
bool FtpNegotiationCommand::processSequence
-(const SharedHandle<Segment>& segment) {
+(const std::shared_ptr<Segment>& segment) {
bool doNextSequence = true;
switch(sequence_) {
case SEQ_RECV_GREETING:
diff --git a/src/FtpNegotiationCommand.h b/src/FtpNegotiationCommand.h
index 07e4c228..9fa5ad1d 100644
--- a/src/FtpNegotiationCommand.h
+++ b/src/FtpNegotiationCommand.h
@@ -125,13 +125,13 @@ private:
bool resolveProxy();
bool sendTunnelRequest();
bool recvTunnelResponse();
- bool sendRest(const SharedHandle<Segment>& segment);
- bool sendRestPasv(const SharedHandle<Segment>& segment);
- bool recvRest(const SharedHandle<Segment>& segment);
+ bool sendRest(const std::shared_ptr<Segment>& segment);
+ bool sendRestPasv(const std::shared_ptr<Segment>& segment);
+ bool recvRest(const std::shared_ptr<Segment>& segment);
bool sendRetr();
bool recvRetr();
bool waitConnection();
- bool processSequence(const SharedHandle<Segment>& segment);
+ bool processSequence(const std::shared_ptr<Segment>& segment);
void afterFileAllocation();
@@ -141,12 +141,12 @@ private:
void onDryRunFileFound();
- SharedHandle<SocketCore> dataSocket_;
- SharedHandle<SocketCore> serverSocket_;
+ std::shared_ptr<SocketCore> dataSocket_;
+ std::shared_ptr<SocketCore> serverSocket_;
Seq sequence_;
- SharedHandle<FtpConnection> ftp_;
+ std::shared_ptr<FtpConnection> ftp_;
// For tunneling
- SharedHandle<HttpConnection> http_;
+ std::shared_ptr<HttpConnection> http_;
// Port number in PASV/EPSV response
uint16_t pasvPort_;
// Resolved address for proxy
@@ -157,11 +157,11 @@ protected:
virtual bool executeInternal();
public:
FtpNegotiationCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s,
+ const std::shared_ptr<SocketCore>& s,
Seq seq = SEQ_RECV_GREETING,
const std::string& baseWorkingDir = "/");
virtual ~FtpNegotiationCommand();
diff --git a/src/FtpTunnelRequestCommand.cc b/src/FtpTunnelRequestCommand.cc
index 2ca92895..72ea099b 100644
--- a/src/FtpTunnelRequestCommand.cc
+++ b/src/FtpTunnelRequestCommand.cc
@@ -43,12 +43,12 @@ namespace aria2 {
FtpTunnelRequestCommand::FtpTunnelRequestCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<SocketCore>& s)
:
AbstractProxyRequestCommand(cuid, req, fileEntry, requestGroup, e,
proxyRequest, s)
diff --git a/src/FtpTunnelRequestCommand.h b/src/FtpTunnelRequestCommand.h
index c22ff381..2e2bb6f5 100644
--- a/src/FtpTunnelRequestCommand.h
+++ b/src/FtpTunnelRequestCommand.h
@@ -44,12 +44,12 @@ class SocketCore;
class FtpTunnelRequestCommand : public AbstractProxyRequestCommand {
public:
FtpTunnelRequestCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<SocketCore>& s);
virtual ~FtpTunnelRequestCommand();
virtual Command* getNextCommand();
diff --git a/src/FtpTunnelResponseCommand.cc b/src/FtpTunnelResponseCommand.cc
index abafea18..bc218400 100644
--- a/src/FtpTunnelResponseCommand.cc
+++ b/src/FtpTunnelResponseCommand.cc
@@ -45,12 +45,12 @@ namespace aria2 {
FtpTunnelResponseCommand::FtpTunnelResponseCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<SocketCore>& s)
:AbstractProxyResponseCommand(cuid, req, fileEntry, requestGroup,
httpConnection,e, s)
{}
diff --git a/src/FtpTunnelResponseCommand.h b/src/FtpTunnelResponseCommand.h
index fae4b427..b80ef8ff 100644
--- a/src/FtpTunnelResponseCommand.h
+++ b/src/FtpTunnelResponseCommand.h
@@ -44,12 +44,12 @@ class SocketCore;
class FtpTunnelResponseCommand : public AbstractProxyResponseCommand {
public:
FtpTunnelResponseCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<SocketCore>& s);
virtual ~FtpTunnelResponseCommand();
virtual Command* getNextCommand();
diff --git a/src/GZipDecodingStreamFilter.cc b/src/GZipDecodingStreamFilter.cc
index 67559cbe..58fef107 100644
--- a/src/GZipDecodingStreamFilter.cc
+++ b/src/GZipDecodingStreamFilter.cc
@@ -44,7 +44,7 @@ namespace aria2 {
const std::string GZipDecodingStreamFilter::NAME("GZipDecodingStreamFilter");
GZipDecodingStreamFilter::GZipDecodingStreamFilter
-(const SharedHandle<StreamFilter>& delegate):
+(const std::shared_ptr<StreamFilter>& delegate):
StreamFilter(delegate), strm_(0), finished_(false), bytesProcessed_(0) {}
GZipDecodingStreamFilter::~GZipDecodingStreamFilter()
@@ -79,8 +79,8 @@ void GZipDecodingStreamFilter::release()
}
ssize_t GZipDecodingStreamFilter::transform
-(const SharedHandle<BinaryStream>& out,
- const SharedHandle<Segment>& segment,
+(const std::shared_ptr<BinaryStream>& out,
+ const std::shared_ptr<Segment>& segment,
const unsigned char* inbuf, size_t inlen)
{
bytesProcessed_ = 0;
diff --git a/src/GZipDecodingStreamFilter.h b/src/GZipDecodingStreamFilter.h
index 349bc8e5..1c812d75 100644
--- a/src/GZipDecodingStreamFilter.h
+++ b/src/GZipDecodingStreamFilter.h
@@ -52,14 +52,14 @@ private:
static const size_t OUTBUF_LENGTH = 16*1024;
public:
GZipDecodingStreamFilter
- (const SharedHandle<StreamFilter>& delegate = SharedHandle<StreamFilter>());
+ (const std::shared_ptr<StreamFilter>& delegate = std::shared_ptr<StreamFilter>());
virtual ~GZipDecodingStreamFilter();
virtual void init();
- virtual ssize_t transform(const SharedHandle<BinaryStream>& out,
- const SharedHandle<Segment>& segment,
+ virtual ssize_t transform(const std::shared_ptr<BinaryStream>& out,
+ const std::shared_ptr<Segment>& segment,
const unsigned char* inbuf, size_t inlen);
virtual bool finished();
diff --git a/src/GenericParser.h b/src/GenericParser.h
index b4930498..1870328a 100644
--- a/src/GenericParser.h
+++ b/src/GenericParser.h
@@ -36,7 +36,6 @@
#define D_GENERIC_PARSER_H
#include "common.h"
-#include "SharedHandle.h"
#include "a2io.h"
#include "util.h"
diff --git a/src/GroupId.cc b/src/GroupId.cc
index a5c9d4ea..8d1f1dfc 100644
--- a/src/GroupId.cc
+++ b/src/GroupId.cc
@@ -33,13 +33,16 @@
*/
/* copyright --> */
#include "GroupId.h"
+
+#include <cassert>
+
#include "util.h"
namespace aria2 {
std::set<a2_gid_t> GroupId::set_;
-SharedHandle<GroupId> GroupId::create()
+std::shared_ptr<GroupId> GroupId::create()
{
a2_gid_t n;
for(;;) {
@@ -48,13 +51,13 @@ SharedHandle<GroupId> GroupId::create()
break;
}
}
- SharedHandle<GroupId> res(new GroupId(n));
+ std::shared_ptr<GroupId> res(new GroupId(n));
return res;
}
-SharedHandle<GroupId> GroupId::import(a2_gid_t n)
+std::shared_ptr<GroupId> GroupId::import(a2_gid_t n)
{
- SharedHandle<GroupId> res;
+ std::shared_ptr<GroupId> res;
if(n == 0 || set_.count(n) != 0) {
return res;
}
diff --git a/src/GroupId.h b/src/GroupId.h
index 25e3c4f2..6d608edf 100644
--- a/src/GroupId.h
+++ b/src/GroupId.h
@@ -39,8 +39,7 @@
#include <set>
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -48,8 +47,8 @@ typedef uint64_t a2_gid_t;
class GroupId {
public:
- static SharedHandle<GroupId> create();
- static SharedHandle<GroupId> import(a2_gid_t n);
+ static std::shared_ptr<GroupId> create();
+ static std::shared_ptr<GroupId> import(a2_gid_t n);
static void clear();
enum {
ERR_NOT_UNIQUE = -1,
diff --git a/src/GrowSegment.cc b/src/GrowSegment.cc
index 70649fc2..c176cdde 100644
--- a/src/GrowSegment.cc
+++ b/src/GrowSegment.cc
@@ -38,7 +38,7 @@
namespace aria2 {
-GrowSegment::GrowSegment(const SharedHandle<Piece>& piece):
+GrowSegment::GrowSegment(const std::shared_ptr<Piece>& piece):
piece_(piece), writtenLength_(0) {}
GrowSegment::~GrowSegment() {}
@@ -66,7 +66,7 @@ void GrowSegment::clear(WrDiskCache* diskCache)
piece_->clearAllBlock(0);
}
-SharedHandle<Piece> GrowSegment::getPiece() const
+std::shared_ptr<Piece> GrowSegment::getPiece() const
{
return piece_;
}
diff --git a/src/GrowSegment.h b/src/GrowSegment.h
index b108ef40..b16c0f56 100644
--- a/src/GrowSegment.h
+++ b/src/GrowSegment.h
@@ -41,10 +41,10 @@ namespace aria2 {
class GrowSegment:public Segment {
private:
- SharedHandle<Piece> piece_;
+ std::shared_ptr<Piece> piece_;
int32_t writtenLength_;
public:
- GrowSegment(const SharedHandle<Piece>& piece);
+ GrowSegment(const std::shared_ptr<Piece>& piece);
virtual ~GrowSegment();
@@ -106,7 +106,7 @@ public:
virtual void clear(WrDiskCache* diskCache);
- virtual SharedHandle<Piece> getPiece() const;
+ virtual std::shared_ptr<Piece> getPiece() const;
};
} // namespace aria2
diff --git a/src/HandshakeExtensionMessage.cc b/src/HandshakeExtensionMessage.cc
index df2d23c5..1a39e782 100644
--- a/src/HandshakeExtensionMessage.cc
+++ b/src/HandshakeExtensionMessage.cc
@@ -67,7 +67,7 @@ std::string HandshakeExtensionMessage::getPayload()
if(tcpPort_ > 0) {
dict.put("p", Integer::g(tcpPort_));
}
- SharedHandle<Dict> extDict = Dict::g();
+ std::shared_ptr<Dict> extDict = Dict::g();
for(int i = 0; i < ExtensionMessageRegistry::MAX_EXTENSION; ++i) {
int id = extreg_.getExtensionMessageID(i);
if(id) {
@@ -109,7 +109,7 @@ void HandshakeExtensionMessage::doReceivedAction()
peer_->setExtension(i, id);
}
}
- SharedHandle<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx_);
+ std::shared_ptr<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx_);
if(attrs->metadata.empty()) {
if(!peer_->getExtensionMessageID(ExtensionMessageRegistry::UT_METADATA)) {
// TODO In metadataGetMode, if peer don't support metadata
@@ -128,7 +128,7 @@ void HandshakeExtensionMessage::doReceivedAction()
dctx_->markTotalLengthIsKnown();
dctx_->getOwnerRequestGroup()->initPieceStorage();
- SharedHandle<PieceStorage> pieceStorage =
+ std::shared_ptr<PieceStorage> pieceStorage =
dctx_->getOwnerRequestGroup()->getPieceStorage();
// We enter 'end game' mode from the start to get metadata
// quickly.
@@ -144,7 +144,7 @@ void HandshakeExtensionMessage::doReceivedAction()
}
}
-void HandshakeExtensionMessage::setPeer(const SharedHandle<Peer>& peer)
+void HandshakeExtensionMessage::setPeer(const std::shared_ptr<Peer>& peer)
{
peer_ = peer;
}
@@ -174,7 +174,7 @@ HandshakeExtensionMessage::create(const unsigned char* data, size_t length)
}
A2_LOG_DEBUG(fmt("Creating HandshakeExtensionMessage from %s",
util::percentEncode(data, length).c_str()));
- SharedHandle<ValueBase> decoded = bencode2::decode(data+1, length - 1);
+ std::shared_ptr<ValueBase> decoded = bencode2::decode(data+1, length - 1);
const Dict* dict = downcast<Dict>(decoded);
if(!dict) {
throw DL_ABORT_EX
diff --git a/src/HandshakeExtensionMessage.h b/src/HandshakeExtensionMessage.h
index 3c1c2e55..520b8a9c 100644
--- a/src/HandshakeExtensionMessage.h
+++ b/src/HandshakeExtensionMessage.h
@@ -37,9 +37,10 @@
#include "ExtensionMessage.h"
+#include <memory>
+
#include "BtConstants.h"
#include "ExtensionMessageRegistry.h"
-#include "SharedHandle.h"
namespace aria2 {
@@ -56,9 +57,9 @@ private:
ExtensionMessageRegistry extreg_;
- SharedHandle<DownloadContext> dctx_;
+ std::shared_ptr<DownloadContext> dctx_;
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
public:
HandshakeExtensionMessage();
@@ -112,7 +113,7 @@ public:
metadataSize_ = size;
}
- void setDownloadContext(const SharedHandle<DownloadContext>& dctx)
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& dctx)
{
dctx_ = dctx;
}
@@ -123,7 +124,7 @@ public:
uint8_t getExtensionMessageID(int key) const;
- void setPeer(const SharedHandle<Peer>& peer);
+ void setPeer(const std::shared_ptr<Peer>& peer);
static HandshakeExtensionMessage*
create(const unsigned char* data, size_t dataLength);
diff --git a/src/HaveEraseCommand.cc b/src/HaveEraseCommand.cc
index 69e7b817..e2727909 100644
--- a/src/HaveEraseCommand.cc
+++ b/src/HaveEraseCommand.cc
@@ -59,7 +59,7 @@ void HaveEraseCommand::process()
getDownloadEngine()->getRequestGroupMan()->getRequestGroups();
for(RequestGroupList::const_iterator i = groups.begin(),
eoi = groups.end(); i != eoi; ++i) {
- const SharedHandle<PieceStorage>& ps = (*i)->getPieceStorage();
+ const std::shared_ptr<PieceStorage>& ps = (*i)->getPieceStorage();
if(ps) {
ps->removeAdvertisedPiece(5);
}
diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc
index 84e3461f..78fe8164 100644
--- a/src/HttpConnection.cc
+++ b/src/HttpConnection.cc
@@ -62,7 +62,7 @@
namespace aria2 {
HttpRequestEntry::HttpRequestEntry
-(const SharedHandle<HttpRequest>& httpRequest)
+(const std::shared_ptr<HttpRequest>& httpRequest)
: httpRequest_(httpRequest),
proc_(new HttpHeaderProcessor(HttpHeaderProcessor::CLIENT_PARSER))
{}
@@ -71,8 +71,8 @@ HttpRequestEntry::~HttpRequestEntry() {}
HttpConnection::HttpConnection
(cuid_t cuid,
- const SharedHandle<SocketCore>& socket,
- const SharedHandle<SocketRecvBuffer>& socketRecvBuffer)
+ const std::shared_ptr<SocketCore>& socket,
+ const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer)
: cuid_(cuid),
socket_(socket),
socketRecvBuffer_(socketRecvBuffer),
@@ -99,7 +99,7 @@ std::string HttpConnection::eraseConfidentialInfo(const std::string& request)
return result;
}
-void HttpConnection::sendRequest(const SharedHandle<HttpRequest>& httpRequest)
+void HttpConnection::sendRequest(const std::shared_ptr<HttpRequest>& httpRequest)
{
std::string request = httpRequest->createRequest();
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
@@ -107,12 +107,12 @@ void HttpConnection::sendRequest(const SharedHandle<HttpRequest>& httpRequest)
eraseConfidentialInfo(request).c_str()));
socketBuffer_.pushStr(request);
socketBuffer_.send();
- SharedHandle<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
+ std::shared_ptr<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
outstandingHttpRequests_.push_back(entry);
}
void HttpConnection::sendProxyRequest
-(const SharedHandle<HttpRequest>& httpRequest)
+(const std::shared_ptr<HttpRequest>& httpRequest)
{
std::string request = httpRequest->createProxyRequest();
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
@@ -120,17 +120,17 @@ void HttpConnection::sendProxyRequest
eraseConfidentialInfo(request).c_str()));
socketBuffer_.pushStr(request);
socketBuffer_.send();
- SharedHandle<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
+ std::shared_ptr<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
outstandingHttpRequests_.push_back(entry);
}
-SharedHandle<HttpResponse> HttpConnection::receiveResponse()
+std::shared_ptr<HttpResponse> HttpConnection::receiveResponse()
{
if(outstandingHttpRequests_.empty()) {
throw DL_ABORT_EX(EX_NO_HTTP_REQUEST_ENTRY_FOUND);
}
- SharedHandle<HttpRequestEntry> entry = outstandingHttpRequests_.front();
- const SharedHandle<HttpHeaderProcessor>& proc =
+ std::shared_ptr<HttpRequestEntry> entry = outstandingHttpRequests_.front();
+ const std::shared_ptr<HttpHeaderProcessor>& proc =
entry->getHttpHeaderProcessor();
if(socketRecvBuffer_->bufferEmpty()) {
if(socketRecvBuffer_->recv() == 0 &&
@@ -138,10 +138,10 @@ SharedHandle<HttpResponse> HttpConnection::receiveResponse()
throw DL_RETRY_EX(EX_GOT_EOF);
}
}
- SharedHandle<HttpResponse> httpResponse;
+ std::shared_ptr<HttpResponse> httpResponse;
if(proc->parse(socketRecvBuffer_->getBuffer(),
socketRecvBuffer_->getBufferLength())) {
- const SharedHandle<HttpHeader>& httpHeader = proc->getResult();
+ const std::shared_ptr<HttpHeader>& httpHeader = proc->getResult();
A2_LOG_INFO(fmt(MSG_RECEIVE_RESPONSE,
cuid_,
proc->getHeaderString().c_str()));
@@ -155,11 +155,11 @@ SharedHandle<HttpResponse> HttpConnection::receiveResponse()
return httpResponse;
}
-bool HttpConnection::isIssued(const SharedHandle<Segment>& segment) const
+bool HttpConnection::isIssued(const std::shared_ptr<Segment>& segment) const
{
for(HttpRequestEntries::const_iterator itr = outstandingHttpRequests_.begin(),
eoi = outstandingHttpRequests_.end(); itr != eoi; ++itr) {
- SharedHandle<HttpRequest> httpRequest = (*itr)->getHttpRequest();
+ std::shared_ptr<HttpRequest> httpRequest = (*itr)->getHttpRequest();
if(*httpRequest->getSegment() == *segment) {
return true;
}
@@ -167,10 +167,10 @@ bool HttpConnection::isIssued(const SharedHandle<Segment>& segment) const
return false;
}
-SharedHandle<HttpRequest> HttpConnection::getFirstHttpRequest() const
+std::shared_ptr<HttpRequest> HttpConnection::getFirstHttpRequest() const
{
if(outstandingHttpRequests_.empty()) {
- return SharedHandle<HttpRequest>();
+ return std::shared_ptr<HttpRequest>();
} else {
return outstandingHttpRequests_.front()->getHttpRequest();
}
diff --git a/src/HttpConnection.h b/src/HttpConnection.h
index d7c2cc0c..b46f9461 100644
--- a/src/HttpConnection.h
+++ b/src/HttpConnection.h
@@ -39,8 +39,8 @@
#include <string>
#include <deque>
+#include <memory>
-#include "SharedHandle.h"
#include "SocketBuffer.h"
#include "Command.h"
@@ -56,31 +56,31 @@ class SocketRecvBuffer;
class HttpRequestEntry {
private:
- SharedHandle<HttpRequest> httpRequest_;
- SharedHandle<HttpHeaderProcessor> proc_;
+ std::shared_ptr<HttpRequest> httpRequest_;
+ std::shared_ptr<HttpHeaderProcessor> proc_;
public:
- HttpRequestEntry(const SharedHandle<HttpRequest>& httpRequest);
+ HttpRequestEntry(const std::shared_ptr<HttpRequest>& httpRequest);
~HttpRequestEntry();
- const SharedHandle<HttpRequest>& getHttpRequest() const
+ const std::shared_ptr<HttpRequest>& getHttpRequest() const
{
return httpRequest_;
}
- const SharedHandle<HttpHeaderProcessor>& getHttpHeaderProcessor() const
+ const std::shared_ptr<HttpHeaderProcessor>& getHttpHeaderProcessor() const
{
return proc_;
}
};
-typedef std::deque<SharedHandle<HttpRequestEntry> > HttpRequestEntries;
+typedef std::deque<std::shared_ptr<HttpRequestEntry> > HttpRequestEntries;
class HttpConnection {
private:
cuid_t cuid_;
- SharedHandle<SocketCore> socket_;
- SharedHandle<SocketRecvBuffer> socketRecvBuffer_;
+ std::shared_ptr<SocketCore> socket_;
+ std::shared_ptr<SocketRecvBuffer> socketRecvBuffer_;
SocketBuffer socketBuffer_;
HttpRequestEntries outstandingHttpRequests_;
@@ -89,8 +89,8 @@ private:
public:
HttpConnection
(cuid_t cuid,
- const SharedHandle<SocketCore>& socket,
- const SharedHandle<SocketRecvBuffer>& socketRecvBuffer);
+ const std::shared_ptr<SocketCore>& socket,
+ const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer);
~HttpConnection();
/**
@@ -100,12 +100,12 @@ public:
* HTTP proxy(GET method).
* @param segment indicates starting postion of the file for downloading
*/
- void sendRequest(const SharedHandle<HttpRequest>& httpRequest);
+ void sendRequest(const std::shared_ptr<HttpRequest>& httpRequest);
/**
* Sends Http proxy request using CONNECT method.
*/
- void sendProxyRequest(const SharedHandle<HttpRequest>& httpRequest);
+ void sendProxyRequest(const std::shared_ptr<HttpRequest>& httpRequest);
/**
* Receives HTTP response from the server and returns HttpResponseHandle
@@ -118,17 +118,17 @@ public:
*
* @return HttpResponse or 0 if whole response header is not received
*/
- SharedHandle<HttpResponse> receiveResponse();
+ std::shared_ptr<HttpResponse> receiveResponse();
- SharedHandle<HttpRequest> getFirstHttpRequest() const;
+ std::shared_ptr<HttpRequest> getFirstHttpRequest() const;
- bool isIssued(const SharedHandle<Segment>& segment) const;
+ bool isIssued(const std::shared_ptr<Segment>& segment) const;
bool sendBufferIsEmpty() const;
void sendPendingData();
- const SharedHandle<SocketRecvBuffer>& getSocketRecvBuffer() const
+ const std::shared_ptr<SocketRecvBuffer>& getSocketRecvBuffer() const
{
return socketRecvBuffer_;
}
diff --git a/src/HttpDownloadCommand.cc b/src/HttpDownloadCommand.cc
index 74153d4d..3436bb58 100644
--- a/src/HttpDownloadCommand.cc
+++ b/src/HttpDownloadCommand.cc
@@ -57,13 +57,13 @@ namespace aria2 {
HttpDownloadCommand::HttpDownloadCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpResponse>& httpResponse,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpResponse>& httpResponse,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket)
+ const std::shared_ptr<SocketCore>& socket)
: DownloadCommand(cuid, req, fileEntry, requestGroup, e, socket,
httpConnection->getSocketRecvBuffer()),
httpResponse_(httpResponse),
@@ -115,7 +115,7 @@ bool HttpDownloadCommand::prepareForNextSegment() {
if(!getRequest()->isPipeliningEnabled() &&
getRequest()->isPipeliningHint() &&
!downloadFinished) {
- const SharedHandle<Segment>& segment = getSegments().front();
+ const std::shared_ptr<Segment>& segment = getSegments().front();
int64_t lastOffset =getFileEntry()->gtoloff
(std::min(segment->getPosition()+segment->getLength(),
diff --git a/src/HttpDownloadCommand.h b/src/HttpDownloadCommand.h
index 491933aa..486da7b9 100644
--- a/src/HttpDownloadCommand.h
+++ b/src/HttpDownloadCommand.h
@@ -44,20 +44,20 @@ class HttpConnection;
class HttpDownloadCommand : public DownloadCommand {
private:
- SharedHandle<HttpResponse> httpResponse_;
- SharedHandle<HttpConnection> httpConnection_;
+ std::shared_ptr<HttpResponse> httpResponse_;
+ std::shared_ptr<HttpConnection> httpConnection_;
protected:
virtual bool prepareForNextSegment();
virtual int64_t getRequestEndOffset() const;
public:
HttpDownloadCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpResponse>& httpResponse,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpResponse>& httpResponse,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<SocketCore>& s);
virtual ~HttpDownloadCommand();
};
diff --git a/src/HttpHeader.h b/src/HttpHeader.h
index 5f9ef676..ff075e6d 100644
--- a/src/HttpHeader.h
+++ b/src/HttpHeader.h
@@ -41,8 +41,6 @@
#include <vector>
#include <string>
-#include "SharedHandle.h"
-
namespace aria2 {
struct Range;
diff --git a/src/HttpHeaderProcessor.cc b/src/HttpHeaderProcessor.cc
index 6b85524a..d7c4f59b 100644
--- a/src/HttpHeaderProcessor.cc
+++ b/src/HttpHeaderProcessor.cc
@@ -391,7 +391,7 @@ void HttpHeaderProcessor::clear()
headers_.clear();
}
-const SharedHandle<HttpHeader>& HttpHeaderProcessor::getResult() const
+const std::shared_ptr<HttpHeader>& HttpHeaderProcessor::getResult() const
{
return result_;
}
diff --git a/src/HttpHeaderProcessor.h b/src/HttpHeaderProcessor.h
index d8912f72..180eea05 100644
--- a/src/HttpHeaderProcessor.h
+++ b/src/HttpHeaderProcessor.h
@@ -39,8 +39,7 @@
#include <utility>
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -74,7 +73,7 @@ public:
* Processes the received header as a http response header and returns
* HttpHeader object.
*/
- const SharedHandle<HttpHeader>& getResult() const;
+ const std::shared_ptr<HttpHeader>& getResult() const;
std::string getHeaderString() const;
@@ -89,7 +88,7 @@ private:
std::string buf_;
std::string lastFieldName_;
int lastFieldHdKey_;
- SharedHandle<HttpHeader> result_;
+ std::shared_ptr<HttpHeader> result_;
std::string headers_;
};
diff --git a/src/HttpInitiateConnectionCommand.cc b/src/HttpInitiateConnectionCommand.cc
index e908dc65..cc8b2ef1 100644
--- a/src/HttpInitiateConnectionCommand.cc
+++ b/src/HttpInitiateConnectionCommand.cc
@@ -60,8 +60,8 @@ namespace aria2 {
HttpInitiateConnectionCommand::HttpInitiateConnectionCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e)
: InitiateConnectionCommand(cuid, req, fileEntry, requestGroup, e)
@@ -72,11 +72,11 @@ HttpInitiateConnectionCommand::~HttpInitiateConnectionCommand() {}
Command* HttpInitiateConnectionCommand::createNextCommand
(const std::string& hostname, const std::string& addr, uint16_t port,
const std::vector<std::string>& resolvedAddresses,
- const SharedHandle<Request>& proxyRequest)
+ const std::shared_ptr<Request>& proxyRequest)
{
Command* command;
if(proxyRequest) {
- SharedHandle<SocketCore> pooledSocket =
+ std::shared_ptr<SocketCore> pooledSocket =
getDownloadEngine()->popPooledSocket
(getRequest()->getHost(), getRequest()->getPort(),
proxyRequest->getHost(), proxyRequest->getPort());
@@ -96,11 +96,11 @@ Command* HttpInitiateConnectionCommand::createNextCommand
getDownloadEngine(),
getSocket());
if(proxyMethod == V_TUNNEL) {
- SharedHandle<HttpProxyRequestConnectChain> chain
+ std::shared_ptr<HttpProxyRequestConnectChain> chain
(new HttpProxyRequestConnectChain());
c->setControlChain(chain);
} else if(proxyMethod == V_GET) {
- SharedHandle<HttpRequestConnectChain> chain
+ std::shared_ptr<HttpRequestConnectChain> chain
(new HttpRequestConnectChain());
c->setControlChain(chain);
} else {
@@ -111,9 +111,9 @@ Command* HttpInitiateConnectionCommand::createNextCommand
command = c;
} else {
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
- SharedHandle<SocketRecvBuffer> socketRecvBuffer
+ std::shared_ptr<SocketRecvBuffer> socketRecvBuffer
(new SocketRecvBuffer(pooledSocket));
- SharedHandle<HttpConnection> httpConnection
+ std::shared_ptr<HttpConnection> httpConnection
(new HttpConnection(getCuid(), pooledSocket, socketRecvBuffer));
HttpRequestCommand* c = new HttpRequestCommand(getCuid(),
getRequest(),
@@ -128,7 +128,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand
command = c;
}
} else {
- SharedHandle<SocketCore> pooledSocket =
+ std::shared_ptr<SocketCore> pooledSocket =
getDownloadEngine()->popPooledSocket
(resolvedAddresses, getRequest()->getPort());
if(!pooledSocket) {
@@ -145,7 +145,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand
getRequestGroup(),
getDownloadEngine(),
getSocket());
- SharedHandle<HttpRequestConnectChain> chain
+ std::shared_ptr<HttpRequestConnectChain> chain
(new HttpRequestConnectChain());
c->setControlChain(chain);
setupBackupConnection(hostname, addr, port, c);
@@ -154,9 +154,9 @@ Command* HttpInitiateConnectionCommand::createNextCommand
setSocket(pooledSocket);
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
- SharedHandle<SocketRecvBuffer> socketRecvBuffer
+ std::shared_ptr<SocketRecvBuffer> socketRecvBuffer
(new SocketRecvBuffer(getSocket()));
- SharedHandle<HttpConnection> httpConnection
+ std::shared_ptr<HttpConnection> httpConnection
(new HttpConnection(getCuid(), getSocket(), socketRecvBuffer));
command = new HttpRequestCommand(getCuid(),
getRequest(),
diff --git a/src/HttpInitiateConnectionCommand.h b/src/HttpInitiateConnectionCommand.h
index db104185..a913dc78 100644
--- a/src/HttpInitiateConnectionCommand.h
+++ b/src/HttpInitiateConnectionCommand.h
@@ -71,10 +71,10 @@ protected:
virtual Command* createNextCommand
(const std::string& hostname, const std::string& addr, uint16_t port,
const std::vector<std::string>& resolvedAddresses,
- const SharedHandle<Request>& proxyRequest);
+ const std::shared_ptr<Request>& proxyRequest);
public:
- HttpInitiateConnectionCommand(cuid_t cuid, const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ HttpInitiateConnectionCommand(cuid_t cuid, const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e);
diff --git a/src/HttpListenCommand.cc b/src/HttpListenCommand.cc
index 5115ece0..728faa57 100644
--- a/src/HttpListenCommand.cc
+++ b/src/HttpListenCommand.cc
@@ -72,7 +72,7 @@ bool HttpListenCommand::execute()
}
try {
if(serverSocket_->isReadable(0)) {
- SharedHandle<SocketCore> socket(serverSocket_->acceptConnection());
+ std::shared_ptr<SocketCore> socket(serverSocket_->acceptConnection());
socket->setTcpNodelay(true);
std::pair<std::string, uint16_t> peerInfo;
socket->getPeerInfo(peerInfo);
diff --git a/src/HttpListenCommand.h b/src/HttpListenCommand.h
index c58700e5..b2d1ee60 100644
--- a/src/HttpListenCommand.h
+++ b/src/HttpListenCommand.h
@@ -36,7 +36,8 @@
#define D_HTTP_LISTEN_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -47,7 +48,7 @@ class HttpListenCommand : public Command {
private:
DownloadEngine* e_;
int family_;
- SharedHandle<SocketCore> serverSocket_;
+ std::shared_ptr<SocketCore> serverSocket_;
bool secure_;
public:
HttpListenCommand(cuid_t cuid, DownloadEngine* e, int family, bool secure);
diff --git a/src/HttpProxyRequestCommand.cc b/src/HttpProxyRequestCommand.cc
index 410345ce..2143f398 100644
--- a/src/HttpProxyRequestCommand.cc
+++ b/src/HttpProxyRequestCommand.cc
@@ -42,12 +42,12 @@ namespace aria2 {
HttpProxyRequestCommand::HttpProxyRequestCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<SocketCore>& s)
:
AbstractProxyRequestCommand(cuid, req, fileEntry, requestGroup, e,
proxyRequest, s)
diff --git a/src/HttpProxyRequestCommand.h b/src/HttpProxyRequestCommand.h
index 60fd6648..ef99ddb2 100644
--- a/src/HttpProxyRequestCommand.h
+++ b/src/HttpProxyRequestCommand.h
@@ -44,12 +44,12 @@ class SocketCore;
class HttpProxyRequestCommand : public AbstractProxyRequestCommand {
public:
HttpProxyRequestCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<Request>& proxyRequest,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<Request>& proxyRequest,
+ const std::shared_ptr<SocketCore>& s);
virtual ~HttpProxyRequestCommand();
virtual Command* getNextCommand();
diff --git a/src/HttpProxyResponseCommand.cc b/src/HttpProxyResponseCommand.cc
index 598bac25..cfadc609 100644
--- a/src/HttpProxyResponseCommand.cc
+++ b/src/HttpProxyResponseCommand.cc
@@ -45,12 +45,12 @@ namespace aria2 {
HttpProxyResponseCommand::HttpProxyResponseCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<SocketCore>& s)
:AbstractProxyResponseCommand(cuid, req, fileEntry, requestGroup,
httpConnection, e, s)
{}
diff --git a/src/HttpProxyResponseCommand.h b/src/HttpProxyResponseCommand.h
index 260e79dc..008f7a8b 100644
--- a/src/HttpProxyResponseCommand.h
+++ b/src/HttpProxyResponseCommand.h
@@ -44,12 +44,12 @@ class SocketCore;
class HttpProxyResponseCommand : public AbstractProxyResponseCommand {
public:
HttpProxyResponseCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<SocketCore>& s);
virtual ~HttpProxyResponseCommand();
virtual Command* getNextCommand();
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc
index 0a55b734..d7320d00 100644
--- a/src/HttpRequest.cc
+++ b/src/HttpRequest.cc
@@ -68,12 +68,12 @@ HttpRequest::HttpRequest():contentEncodingEnabled_(true),
HttpRequest::~HttpRequest() {}
-void HttpRequest::setSegment(const SharedHandle<Segment>& segment)
+void HttpRequest::setSegment(const std::shared_ptr<Segment>& segment)
{
segment_ = segment;
}
-void HttpRequest::setRequest(const SharedHandle<Request>& request)
+void HttpRequest::setRequest(const std::shared_ptr<Request>& request)
{
request_ = request;
}
@@ -328,34 +328,34 @@ void HttpRequest::clearHeader()
}
void HttpRequest::setCookieStorage
-(const SharedHandle<CookieStorage>& cookieStorage)
+(const std::shared_ptr<CookieStorage>& cookieStorage)
{
cookieStorage_ = cookieStorage;
}
void HttpRequest::setAuthConfigFactory
-(const SharedHandle<AuthConfigFactory>& factory, const Option* option)
+(const std::shared_ptr<AuthConfigFactory>& factory, const Option* option)
{
authConfigFactory_ = factory;
option_ = option;
}
-void HttpRequest::setProxyRequest(const SharedHandle<Request>& proxyRequest)
+void HttpRequest::setProxyRequest(const std::shared_ptr<Request>& proxyRequest)
{
proxyRequest_ = proxyRequest;
}
bool HttpRequest::isProxyRequestSet() const
{
- return proxyRequest_;
+ return proxyRequest_.get();
}
bool HttpRequest::authenticationUsed() const
{
- return authConfig_;
+ return authConfig_.get();
}
-const SharedHandle<AuthConfig>& HttpRequest::getAuthConfig() const
+const std::shared_ptr<AuthConfig>& HttpRequest::getAuthConfig() const
{
return authConfig_;
}
@@ -421,7 +421,7 @@ void HttpRequest::setUserAgent(const std::string& userAgent)
userAgent_ = userAgent;
}
-void HttpRequest::setFileEntry(const SharedHandle<FileEntry>& fileEntry)
+void HttpRequest::setFileEntry(const std::shared_ptr<FileEntry>& fileEntry)
{
fileEntry_ = fileEntry;
}
diff --git a/src/HttpRequest.h b/src/HttpRequest.h
index 91e30f6d..a9ac38c0 100644
--- a/src/HttpRequest.h
+++ b/src/HttpRequest.h
@@ -40,8 +40,8 @@
#include <cassert>
#include <string>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "FileEntry.h"
namespace aria2 {
@@ -59,11 +59,11 @@ private:
static const std::string USER_AGENT;
- SharedHandle<Request> request_;
+ std::shared_ptr<Request> request_;
- SharedHandle<FileEntry> fileEntry_;
+ std::shared_ptr<FileEntry> fileEntry_;
- SharedHandle<Segment> segment_;
+ std::shared_ptr<Segment> segment_;
bool contentEncodingEnabled_;
@@ -74,15 +74,15 @@ private:
// If true, metalink content types are sent in Accept header field.
bool acceptMetalink_;
- SharedHandle<CookieStorage> cookieStorage_;
+ std::shared_ptr<CookieStorage> cookieStorage_;
- SharedHandle<AuthConfigFactory> authConfigFactory_;
+ std::shared_ptr<AuthConfigFactory> authConfigFactory_;
const Option* option_;
- SharedHandle<AuthConfig> authConfig_;
+ std::shared_ptr<AuthConfig> authConfig_;
- SharedHandle<Request> proxyRequest_;
+ std::shared_ptr<Request> proxyRequest_;
bool noCache_;
@@ -104,14 +104,14 @@ public:
HttpRequest();
~HttpRequest();
- const SharedHandle<Segment>& getSegment() const
+ const std::shared_ptr<Segment>& getSegment() const
{
return segment_;
}
- void setSegment(const SharedHandle<Segment>& segment);
+ void setSegment(const std::shared_ptr<Segment>& segment);
- void setRequest(const SharedHandle<Request>& request);
+ void setRequest(const std::shared_ptr<Request>& request);
int64_t getEntityLength() const;
@@ -143,7 +143,7 @@ public:
*/
bool isRangeSatisfied(const Range& range) const;
- const SharedHandle<Request>& getRequest() const
+ const std::shared_ptr<Request>& getRequest() const
{
return request_;
}
@@ -185,21 +185,21 @@ public:
acceptMetalink_ = f;
}
- void setCookieStorage(const SharedHandle<CookieStorage>& cookieStorage);
+ void setCookieStorage(const std::shared_ptr<CookieStorage>& cookieStorage);
- const SharedHandle<CookieStorage>& getCookieStorage() const
+ const std::shared_ptr<CookieStorage>& getCookieStorage() const
{
return cookieStorage_;
}
void setAuthConfigFactory
- (const SharedHandle<AuthConfigFactory>& factory, const Option* option);
+ (const std::shared_ptr<AuthConfigFactory>& factory, const Option* option);
/*
* To use proxy, pass proxy string to Request::setUri() and set it this
* object.
*/
- void setProxyRequest(const SharedHandle<Request>& proxyRequest);
+ void setProxyRequest(const std::shared_ptr<Request>& proxyRequest);
/*
* Returns true if non-Null proxy request is set by setProxyRequest().
@@ -213,11 +213,11 @@ public:
// Returns AuthConfig used in the last invocation of
// createRequest().
- const SharedHandle<AuthConfig>& getAuthConfig() const;
+ const std::shared_ptr<AuthConfig>& getAuthConfig() const;
- void setFileEntry(const SharedHandle<FileEntry>& fileEntry);
+ void setFileEntry(const std::shared_ptr<FileEntry>& fileEntry);
- const SharedHandle<FileEntry>& getFileEntry() const
+ const std::shared_ptr<FileEntry>& getFileEntry() const
{
return fileEntry_;
}
diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc
index 971a861d..620dbf7d 100644
--- a/src/HttpRequestCommand.cc
+++ b/src/HttpRequestCommand.cc
@@ -64,12 +64,12 @@ namespace aria2 {
HttpRequestCommand::HttpRequestCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<SocketCore>& s)
: AbstractCommand(cuid, req, fileEntry, requestGroup, e, s,
httpConnection->getSocketRecvBuffer()),
httpConnection_(httpConnection)
@@ -82,19 +82,19 @@ HttpRequestCommand::HttpRequestCommand
HttpRequestCommand::~HttpRequestCommand() {}
namespace {
-SharedHandle<HttpRequest>
-createHttpRequest(const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
- const SharedHandle<Segment>& segment,
+std::shared_ptr<HttpRequest>
+createHttpRequest(const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
+ const std::shared_ptr<Segment>& segment,
int64_t totalLength,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<Option>& option,
const RequestGroup* rg,
- const SharedHandle<CookieStorage>& cookieStorage,
- const SharedHandle<AuthConfigFactory>& authConfigFactory,
- const SharedHandle<Request>& proxyRequest,
+ const std::shared_ptr<CookieStorage>& cookieStorage,
+ const std::shared_ptr<AuthConfigFactory>& authConfigFactory,
+ const std::shared_ptr<Request>& proxyRequest,
int64_t endOffset = 0)
{
- SharedHandle<HttpRequest> httpRequest(new HttpRequest());
+ std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
httpRequest->setUserAgent(option->get(PREF_USER_AGENT));
httpRequest->setRequest(req);
httpRequest->setFileEntry(fileEntry);
@@ -136,10 +136,10 @@ bool HttpRequestCommand::executeInternal() {
}
#endif // ENABLE_SSL
if(getSegments().empty()) {
- SharedHandle<HttpRequest> httpRequest
+ std::shared_ptr<HttpRequest> httpRequest
(createHttpRequest(getRequest(),
getFileEntry(),
- SharedHandle<Segment>(),
+ std::shared_ptr<Segment>(),
getRequestGroup()->getTotalLength(),
getOption(),
getRequestGroup(),
@@ -172,10 +172,10 @@ bool HttpRequestCommand::executeInternal() {
}
httpConnection_->sendRequest(httpRequest);
} else {
- for(std::vector<SharedHandle<Segment> >::const_iterator itr =
+ for(std::vector<std::shared_ptr<Segment> >::const_iterator itr =
getSegments().begin(), eoi = getSegments().end();
itr != eoi; ++itr) {
- const SharedHandle<Segment>& segment = *itr;
+ const std::shared_ptr<Segment>& segment = *itr;
if(!httpConnection_->isIssued(segment)) {
int64_t endOffset = 0;
// FTP via HTTP proxy does not support end byte marker
@@ -188,7 +188,7 @@ bool HttpRequestCommand::executeInternal() {
getFileEntry()->gtoloff
(static_cast<int64_t>(segment->getSegmentLength())*nextIndex));
}
- SharedHandle<HttpRequest> httpRequest
+ std::shared_ptr<HttpRequest> httpRequest
(createHttpRequest(getRequest(),
getFileEntry(),
segment,
@@ -225,7 +225,7 @@ bool HttpRequestCommand::executeInternal() {
}
void HttpRequestCommand::setProxyRequest
-(const SharedHandle<Request>& proxyRequest)
+(const std::shared_ptr<Request>& proxyRequest)
{
proxyRequest_ = proxyRequest;
}
diff --git a/src/HttpRequestCommand.h b/src/HttpRequestCommand.h
index 8f6d37f9..f278a3c3 100644
--- a/src/HttpRequestCommand.h
+++ b/src/HttpRequestCommand.h
@@ -50,22 +50,22 @@ class SocketCore;
// returns true.
class HttpRequestCommand:public AbstractCommand {
private:
- SharedHandle<Request> proxyRequest_;
+ std::shared_ptr<Request> proxyRequest_;
- SharedHandle<HttpConnection> httpConnection_;
+ std::shared_ptr<HttpConnection> httpConnection_;
protected:
virtual bool executeInternal();
public:
HttpRequestCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<SocketCore>& s);
virtual ~HttpRequestCommand();
- void setProxyRequest(const SharedHandle<Request>& proxyRequest);
+ void setProxyRequest(const std::shared_ptr<Request>& proxyRequest);
};
} // namespace aria2
diff --git a/src/HttpRequestConnectChain.h b/src/HttpRequestConnectChain.h
index d3a4f38f..ab6ef98e 100644
--- a/src/HttpRequestConnectChain.h
+++ b/src/HttpRequestConnectChain.h
@@ -49,9 +49,9 @@ struct HttpRequestConnectChain : public ControlChain<ConnectCommand*> {
virtual ~HttpRequestConnectChain() {}
virtual int run(ConnectCommand* t, DownloadEngine* e)
{
- SharedHandle<SocketRecvBuffer> socketRecvBuffer
+ std::shared_ptr<SocketRecvBuffer> socketRecvBuffer
(new SocketRecvBuffer(t->getSocket()));
- SharedHandle<HttpConnection> httpConnection
+ std::shared_ptr<HttpConnection> httpConnection
(new HttpConnection(t->getCuid(), t->getSocket(), socketRecvBuffer));
HttpRequestCommand* c = new HttpRequestCommand(t->getCuid(),
t->getRequest(),
diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc
index cd7e821f..0d8642dc 100644
--- a/src/HttpResponse.cc
+++ b/src/HttpResponse.cc
@@ -191,9 +191,9 @@ const std::string& HttpResponse::getTransferEncoding() const
return httpHeader_->find(HttpHeader::TRANSFER_ENCODING);
}
-SharedHandle<StreamFilter> HttpResponse::getTransferEncodingStreamFilter() const
+std::shared_ptr<StreamFilter> HttpResponse::getTransferEncodingStreamFilter() const
{
- SharedHandle<StreamFilter> filter;
+ std::shared_ptr<StreamFilter> filter;
// TODO Transfer-Encoding header field can contains multiple tokens. We should
// parse the field and retrieve each token.
if(isTransferEncodingSpecified()) {
@@ -214,9 +214,9 @@ const std::string& HttpResponse::getContentEncoding() const
return httpHeader_->find(HttpHeader::CONTENT_ENCODING);
}
-SharedHandle<StreamFilter> HttpResponse::getContentEncodingStreamFilter() const
+std::shared_ptr<StreamFilter> HttpResponse::getContentEncodingStreamFilter() const
{
- SharedHandle<StreamFilter> filter;
+ std::shared_ptr<StreamFilter> filter;
#ifdef HAVE_ZLIB
if(util::strieq(getContentEncoding(), "gzip") ||
util::strieq(getContentEncoding(), "deflate")) {
@@ -256,12 +256,12 @@ std::string HttpResponse::getContentType() const
}
}
-void HttpResponse::setHttpHeader(const SharedHandle<HttpHeader>& httpHeader)
+void HttpResponse::setHttpHeader(const std::shared_ptr<HttpHeader>& httpHeader)
{
httpHeader_ = httpHeader;
}
-void HttpResponse::setHttpRequest(const SharedHandle<HttpRequest>& httpRequest)
+void HttpResponse::setHttpRequest(const std::shared_ptr<HttpRequest>& httpRequest)
{
httpRequest_ = httpRequest;
}
@@ -344,7 +344,7 @@ bool parseMetalinkHttpLink(MetalinkHttpEntry& result, const std::string& s)
// Link header field is defined by http://tools.ietf.org/html/rfc5988.
void HttpResponse::getMetalinKHttpEntries
(std::vector<MetalinkHttpEntry>& result,
- const SharedHandle<Option>& option) const
+ const std::shared_ptr<Option>& option) const
{
std::pair<std::multimap<int, std::string>::const_iterator,
std::multimap<int, std::string>::const_iterator> p =
diff --git a/src/HttpResponse.h b/src/HttpResponse.h
index f23a92eb..22ec13c1 100644
--- a/src/HttpResponse.h
+++ b/src/HttpResponse.h
@@ -39,8 +39,8 @@
#include <stdint.h>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "TimeA2.h"
#include "Command.h"
@@ -56,8 +56,8 @@ class Checksum;
class HttpResponse {
private:
cuid_t cuid_;
- SharedHandle<HttpRequest> httpRequest_;
- SharedHandle<HttpHeader> httpHeader_;
+ std::shared_ptr<HttpRequest> httpRequest_;
+ std::shared_ptr<HttpHeader> httpHeader_;
public:
HttpResponse();
@@ -88,13 +88,13 @@ public:
const std::string& getTransferEncoding() const;
- SharedHandle<StreamFilter> getTransferEncodingStreamFilter() const;
+ std::shared_ptr<StreamFilter> getTransferEncodingStreamFilter() const;
bool isContentEncodingSpecified() const;
const std::string& getContentEncoding() const;
- SharedHandle<StreamFilter> getContentEncodingStreamFilter() const;
+ std::shared_ptr<StreamFilter> getContentEncodingStreamFilter() const;
int64_t getContentLength() const;
@@ -103,18 +103,18 @@ public:
// Returns type "/" subtype. The parameter is removed.
std::string getContentType() const;
- void setHttpHeader(const SharedHandle<HttpHeader>& httpHeader);
+ void setHttpHeader(const std::shared_ptr<HttpHeader>& httpHeader);
- const SharedHandle<HttpHeader>& getHttpHeader() const
+ const std::shared_ptr<HttpHeader>& getHttpHeader() const
{
return httpHeader_;
}
int getStatusCode() const;
- void setHttpRequest(const SharedHandle<HttpRequest>& httpRequest);
+ void setHttpRequest(const std::shared_ptr<HttpRequest>& httpRequest);
- const SharedHandle<HttpRequest>& getHttpRequest() const
+ const std::shared_ptr<HttpRequest>& getHttpRequest() const
{
return httpRequest_;
}
@@ -130,7 +130,7 @@ public:
void getMetalinKHttpEntries
(std::vector<MetalinkHttpEntry>& result,
- const SharedHandle<Option>& option) const;
+ const std::shared_ptr<Option>& option) const;
#ifdef ENABLE_MESSAGE_DIGEST
// Returns all digests specified in Digest header field. Sort
// strong algorithm first. Strength is defined in MessageDigest. If
diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc
index c04e5818..872f401a 100644
--- a/src/HttpResponseCommand.cc
+++ b/src/HttpResponseCommand.cc
@@ -84,11 +84,11 @@
namespace aria2 {
namespace {
-SharedHandle<StreamFilter> getTransferEncodingStreamFilter
-(const SharedHandle<HttpResponse>& httpResponse,
- const SharedHandle<StreamFilter>& delegate = SharedHandle<StreamFilter>())
+std::shared_ptr<StreamFilter> getTransferEncodingStreamFilter
+(const std::shared_ptr<HttpResponse>& httpResponse,
+ const std::shared_ptr<StreamFilter>& delegate = std::shared_ptr<StreamFilter>())
{
- SharedHandle<StreamFilter> filter;
+ std::shared_ptr<StreamFilter> filter;
if(httpResponse->isTransferEncodingSpecified()) {
filter = httpResponse->getTransferEncodingStreamFilter();
if(!filter) {
@@ -107,11 +107,11 @@ SharedHandle<StreamFilter> getTransferEncodingStreamFilter
} // namespace
namespace {
-SharedHandle<StreamFilter> getContentEncodingStreamFilter
-(const SharedHandle<HttpResponse>& httpResponse,
- const SharedHandle<StreamFilter>& delegate = SharedHandle<StreamFilter>())
+std::shared_ptr<StreamFilter> getContentEncodingStreamFilter
+(const std::shared_ptr<HttpResponse>& httpResponse,
+ const std::shared_ptr<StreamFilter>& delegate = std::shared_ptr<StreamFilter>())
{
- SharedHandle<StreamFilter> filter;
+ std::shared_ptr<StreamFilter> filter;
if(httpResponse->isContentEncodingSpecified()) {
filter = httpResponse->getContentEncodingStreamFilter();
if(!filter) {
@@ -134,12 +134,12 @@ SharedHandle<StreamFilter> getContentEncodingStreamFilter
HttpResponseCommand::HttpResponseCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<SocketCore>& s)
: AbstractCommand(cuid, req, fileEntry, requestGroup, e, s,
httpConnection->getSocketRecvBuffer()),
httpConnection_(httpConnection)
@@ -151,8 +151,8 @@ HttpResponseCommand::~HttpResponseCommand() {}
bool HttpResponseCommand::executeInternal()
{
- SharedHandle<HttpRequest> httpRequest =httpConnection_->getFirstHttpRequest();
- SharedHandle<HttpResponse> httpResponse = httpConnection_->receiveResponse();
+ std::shared_ptr<HttpRequest> httpRequest =httpConnection_->getFirstHttpRequest();
+ std::shared_ptr<HttpResponse> httpResponse = httpConnection_->receiveResponse();
if(!httpResponse) {
// The server has not responded to our request yet.
// For socket->wantRead() == true, setReadCheckSocket(socket) is already
@@ -165,7 +165,7 @@ bool HttpResponseCommand::executeInternal()
httpResponse->validateResponse();
httpResponse->retrieveCookie();
- SharedHandle<HttpHeader> httpHeader = httpResponse->getHttpHeader();
+ std::shared_ptr<HttpHeader> httpHeader = httpResponse->getHttpHeader();
// Disable persistent connection if:
// Connection: close is received or the remote server is not HTTP/1.1.
// We don't care whether non-HTTP/1.1 server returns Connection: keep-alive.
@@ -332,7 +332,7 @@ void HttpResponseCommand::updateLastModifiedTime(const Time& lastModified)
}
bool HttpResponseCommand::shouldInflateContentEncoding
-(const SharedHandle<HttpResponse>& httpResponse)
+(const std::shared_ptr<HttpResponse>& httpResponse)
{
// Basically, on the fly inflation cannot be made with segment
// download, because in each segment we don't know where the date
@@ -347,12 +347,12 @@ bool HttpResponseCommand::shouldInflateContentEncoding
}
bool HttpResponseCommand::handleDefaultEncoding
-(const SharedHandle<HttpResponse>& httpResponse)
+(const std::shared_ptr<HttpResponse>& httpResponse)
{
- SharedHandle<HttpRequest> httpRequest = httpResponse->getHttpRequest();
- SharedHandle<BtProgressInfoFile> progressInfoFile
+ std::shared_ptr<HttpRequest> httpRequest = httpResponse->getHttpRequest();
+ std::shared_ptr<BtProgressInfoFile> progressInfoFile
(new DefaultBtProgressInfoFile
- (getDownloadContext(), SharedHandle<PieceStorage>(), getOption().get()));
+ (getDownloadContext(), std::shared_ptr<PieceStorage>(), getOption().get()));
getRequestGroup()->adjustFilename(progressInfoFile);
getRequestGroup()->initPieceStorage();
@@ -361,7 +361,7 @@ bool HttpResponseCommand::handleDefaultEncoding
return true;
}
- SharedHandle<CheckIntegrityEntry> checkEntry =
+ std::shared_ptr<CheckIntegrityEntry> checkEntry =
getRequestGroup()->createCheckIntegrityEntry();
if(!checkEntry) {
return true;
@@ -370,7 +370,7 @@ bool HttpResponseCommand::handleDefaultEncoding
// We have to make sure that command that has Request object must
// have segment after PieceStorage is initialized. See
// AbstractCommand::execute()
- SharedHandle<Segment> segment =
+ std::shared_ptr<Segment> segment =
getSegmentMan()->getSegmentWithIndex(getCuid(), 0);
// pipelining requires implicit range specified. But the request for
// this response most likely dones't contains range header. This means
@@ -403,9 +403,9 @@ bool HttpResponseCommand::handleDefaultEncoding
}
bool HttpResponseCommand::handleOtherEncoding
-(const SharedHandle<HttpResponse>& httpResponse) {
+(const std::shared_ptr<HttpResponse>& httpResponse) {
// We assume that RequestGroup::getTotalLength() == 0 here
- SharedHandle<HttpRequest> httpRequest = httpResponse->getHttpRequest();
+ std::shared_ptr<HttpRequest> httpRequest = httpResponse->getHttpRequest();
if(getOption()->getAsBool(PREF_DRY_RUN)) {
getRequestGroup()->initPieceStorage();
@@ -422,7 +422,7 @@ bool HttpResponseCommand::handleOtherEncoding
// In this context, knowsTotalLength() is true only when the file is
// really zero-length.
- SharedHandle<StreamFilter> streamFilter =
+ std::shared_ptr<StreamFilter> streamFilter =
getTransferEncodingStreamFilter
(httpResponse,
getContentEncodingStreamFilter(httpResponse));
@@ -441,7 +441,7 @@ bool HttpResponseCommand::handleOtherEncoding
// See also FtpNegotiationCommand::onFileSizeDetermined()
if(getDownloadContext()->isChecksumVerificationNeeded()) {
A2_LOG_DEBUG("Zero length file exists. Verify checksum.");
- SharedHandle<ChecksumCheckIntegrityEntry> entry
+ std::shared_ptr<ChecksumCheckIntegrityEntry> entry
(new ChecksumCheckIntegrityEntry(getRequestGroup()));
entry->initValidator();
getPieceStorage()->getDiskAdaptor()->openExistingFile();
@@ -475,7 +475,7 @@ bool HttpResponseCommand::handleOtherEncoding
#ifdef ENABLE_MESSAGE_DIGEST
if(getDownloadContext()->isChecksumVerificationNeeded()) {
A2_LOG_DEBUG("Verify checksum for zero-length file");
- SharedHandle<ChecksumCheckIntegrityEntry> entry
+ std::shared_ptr<ChecksumCheckIntegrityEntry> entry
(new ChecksumCheckIntegrityEntry(getRequestGroup()));
entry->initValidator();
getDownloadEngine()->getCheckIntegrityMan()->pushEntry(entry);
@@ -498,9 +498,9 @@ bool HttpResponseCommand::handleOtherEncoding
}
bool HttpResponseCommand::skipResponseBody
-(const SharedHandle<HttpResponse>& httpResponse)
+(const std::shared_ptr<HttpResponse>& httpResponse)
{
- SharedHandle<StreamFilter> filter =
+ std::shared_ptr<StreamFilter> filter =
getTransferEncodingStreamFilter(httpResponse);
// We don't use Content-Encoding here because this response body is just
// thrown away.
@@ -528,10 +528,10 @@ bool HttpResponseCommand::skipResponseBody
namespace {
bool decideFileAllocation
-(const SharedHandle<StreamFilter>& filter)
+(const std::shared_ptr<StreamFilter>& filter)
{
#ifdef HAVE_ZLIB
- for(SharedHandle<StreamFilter> f = filter; f; f = f->getDelegate()){
+ for(std::shared_ptr<StreamFilter> f = filter; f; f = f->getDelegate()){
// Since the compressed file's length are returned in the response header
// and the decompressed file size is unknown at this point, disable file
// allocation here.
@@ -545,8 +545,8 @@ bool decideFileAllocation
} // namespace
HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand
-(const SharedHandle<HttpResponse>& httpResponse,
- const SharedHandle<StreamFilter>& filter)
+(const std::shared_ptr<HttpResponse>& httpResponse,
+ const std::shared_ptr<StreamFilter>& filter)
{
HttpDownloadCommand* command =
@@ -585,7 +585,7 @@ void HttpResponseCommand::onDryRunFileFound()
#ifdef ENABLE_MESSAGE_DIGEST
bool HttpResponseCommand::checkChecksum
-(const SharedHandle<DownloadContext>& dctx,
+(const std::shared_ptr<DownloadContext>& dctx,
const Checksum& checksum)
{
if(dctx->getHashType() == checksum.getHashType()) {
diff --git a/src/HttpResponseCommand.h b/src/HttpResponseCommand.h
index 6c691e0e..8a947d5d 100644
--- a/src/HttpResponseCommand.h
+++ b/src/HttpResponseCommand.h
@@ -61,16 +61,16 @@ class Checksum;
// HttpSkipResponseCommand.
class HttpResponseCommand : public AbstractCommand {
private:
- SharedHandle<HttpConnection> httpConnection_;
+ std::shared_ptr<HttpConnection> httpConnection_;
- bool handleDefaultEncoding(const SharedHandle<HttpResponse>& httpResponse);
- bool handleOtherEncoding(const SharedHandle<HttpResponse>& httpResponse);
- bool skipResponseBody(const SharedHandle<HttpResponse>& httpResponse);
+ bool handleDefaultEncoding(const std::shared_ptr<HttpResponse>& httpResponse);
+ bool handleOtherEncoding(const std::shared_ptr<HttpResponse>& httpResponse);
+ bool skipResponseBody(const std::shared_ptr<HttpResponse>& httpResponse);
HttpDownloadCommand*
createHttpDownloadCommand
- (const SharedHandle<HttpResponse>& httpResponse,
- const SharedHandle<StreamFilter>& streamFilter);
+ (const std::shared_ptr<HttpResponse>& httpResponse,
+ const std::shared_ptr<StreamFilter>& streamFilter);
void updateLastModifiedTime(const Time& lastModified);
@@ -82,23 +82,23 @@ private:
// value. If they have same hash type but different hash value,
// throws exception. Otherwise returns false.
bool checkChecksum
- (const SharedHandle<DownloadContext>& dctx,
+ (const std::shared_ptr<DownloadContext>& dctx,
const Checksum& checksum);
#endif // ENABLE_MESSAGE_DIGEST
protected:
bool executeInternal();
bool shouldInflateContentEncoding
- (const SharedHandle<HttpResponse>& httpResponse);
+ (const std::shared_ptr<HttpResponse>& httpResponse);
public:
HttpResponseCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<SocketCore>& s);
~HttpResponseCommand();
};
diff --git a/src/HttpServer.cc b/src/HttpServer.cc
index 194a8b89..f314ee1e 100644
--- a/src/HttpServer.cc
+++ b/src/HttpServer.cc
@@ -57,7 +57,7 @@
namespace aria2 {
-HttpServer::HttpServer(const SharedHandle<SocketCore>& socket)
+HttpServer::HttpServer(const std::shared_ptr<SocketCore>& socket)
: socket_(socket),
socketRecvBuffer_(new SocketRecvBuffer(socket_)),
socketBuffer_(socket),
@@ -126,7 +126,7 @@ const char* getStatusString(int status)
}
} // namespace
-SharedHandle<HttpHeader> HttpServer::receiveRequest()
+std::shared_ptr<HttpHeader> HttpServer::receiveRequest()
{
if(socketRecvBuffer_->bufferEmpty()) {
if(socketRecvBuffer_->recv() == 0 &&
@@ -134,7 +134,7 @@ SharedHandle<HttpHeader> HttpServer::receiveRequest()
throw DL_ABORT_EX(EX_EOF_FROM_PEER);
}
}
- SharedHandle<HttpHeader> header;
+ std::shared_ptr<HttpHeader> header;
if(headerProcessor_->parse(socketRecvBuffer_->getBuffer(),
socketRecvBuffer_->getBufferLength())) {
header = headerProcessor_->getResult();
diff --git a/src/HttpServer.h b/src/HttpServer.h
index b2ef76d4..8f07412a 100644
--- a/src/HttpServer.h
+++ b/src/HttpServer.h
@@ -40,8 +40,8 @@
#include <string>
#include <sstream>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "SocketBuffer.h"
namespace aria2 {
@@ -64,17 +64,17 @@ enum RequestType {
// intended to be a generic HTTP server.
class HttpServer {
private:
- SharedHandle<SocketCore> socket_;
- SharedHandle<SocketRecvBuffer> socketRecvBuffer_;
+ std::shared_ptr<SocketCore> socket_;
+ std::shared_ptr<SocketRecvBuffer> socketRecvBuffer_;
SocketBuffer socketBuffer_;
- SharedHandle<HttpHeaderProcessor> headerProcessor_;
- SharedHandle<HttpHeader> lastRequestHeader_;
+ std::shared_ptr<HttpHeaderProcessor> headerProcessor_;
+ std::shared_ptr<HttpHeader> lastRequestHeader_;
int64_t lastContentLength_;
// How many bytes are consumed. The total number of bytes is
// lastContentLength_.
int64_t bodyConsumed_;
RequestType reqType_;
- SharedHandle<DiskWriter> lastBody_;
+ std::shared_ptr<DiskWriter> lastBody_;
bool keepAlive_;
bool gzip_;
std::string username_;
@@ -83,11 +83,11 @@ private:
std::string allowOrigin_;
bool secure_;
public:
- HttpServer(const SharedHandle<SocketCore>& socket);
+ HttpServer(const std::shared_ptr<SocketCore>& socket);
~HttpServer();
- SharedHandle<HttpHeader> receiveRequest();
+ std::shared_ptr<HttpHeader> receiveRequest();
bool receiveBody();
@@ -101,7 +101,7 @@ public:
std::string createQuery() const;
- const SharedHandle<DiskWriter>& getBody() const
+ const std::shared_ptr<DiskWriter>& getBody() const
{
return lastBody_;
}
@@ -154,7 +154,7 @@ public:
int64_t getContentLength() const { return lastContentLength_; }
- const SharedHandle<SocketRecvBuffer>& getSocketRecvBuffer() const
+ const std::shared_ptr<SocketRecvBuffer>& getSocketRecvBuffer() const
{
return socketRecvBuffer_;
}
@@ -169,12 +169,12 @@ public:
allowOrigin_ = allowOrigin;
}
- const SharedHandle<SocketCore>& getSocket() const
+ const std::shared_ptr<SocketCore>& getSocket() const
{
return socket_;
}
- const SharedHandle<HttpHeader>& getRequestHeader() const
+ const std::shared_ptr<HttpHeader>& getRequestHeader() const
{
return lastRequestHeader_;
}
diff --git a/src/HttpServerBodyCommand.cc b/src/HttpServerBodyCommand.cc
index 23230d00..a860e90d 100644
--- a/src/HttpServerBodyCommand.cc
+++ b/src/HttpServerBodyCommand.cc
@@ -68,9 +68,9 @@ namespace aria2 {
HttpServerBodyCommand::HttpServerBodyCommand
(cuid_t cuid,
- const SharedHandle<HttpServer>& httpServer,
+ const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket)
+ const std::shared_ptr<SocketCore>& socket)
: Command(cuid),
e_(e),
socket_(socket),
@@ -184,7 +184,7 @@ bool HttpServerBodyCommand::execute()
if(httpServer_->getMethod() == "OPTIONS") {
// Response to Preflight Request.
// See http://www.w3.org/TR/cors/
- const SharedHandle<HttpHeader>& header =
+ const std::shared_ptr<HttpHeader>& header =
httpServer_->getRequestHeader();
std::string accessControlHeaders;
if(!header->find(HttpHeader::ORIGIN).empty() &&
@@ -211,8 +211,8 @@ bool HttpServerBodyCommand::execute()
switch(httpServer_->getRequestType()) {
case RPC_TYPE_XML: {
#ifdef ENABLE_XML_RPC
- SharedHandle<rpc::XmlRpcDiskWriter> dw =
- static_pointer_cast<rpc::XmlRpcDiskWriter>(httpServer_->getBody());
+ auto dw = std::static_pointer_cast<rpc::XmlRpcDiskWriter>
+ (httpServer_->getBody());
int error;
error = dw->finalize();
rpc::RpcRequest req;
@@ -228,7 +228,7 @@ bool HttpServerBodyCommand::execute()
addHttpServerResponseCommand();
return true;
}
- SharedHandle<rpc::RpcMethod> method =
+ std::shared_ptr<rpc::RpcMethod> method =
rpc::RpcMethodFactory::create(req.methodName);
A2_LOG_INFO(fmt("Executing RPC method %s", req.methodName.c_str()));
rpc::RpcResponse res = method->execute(req, e_);
@@ -245,7 +245,7 @@ bool HttpServerBodyCommand::execute()
case RPC_TYPE_JSON:
case RPC_TYPE_JSONP: {
std::string callback;
- SharedHandle<ValueBase> json;
+ std::shared_ptr<ValueBase> json;
ssize_t error = 0;
if(httpServer_->getRequestType() == RPC_TYPE_JSONP) {
json::JsonGetParam param = json::decodeGetParams(query);
@@ -256,8 +256,8 @@ bool HttpServerBodyCommand::execute()
param.request.size(),
error);
} else {
- SharedHandle<json::JsonDiskWriter> dw =
- static_pointer_cast<json::JsonDiskWriter>(httpServer_->getBody());
+ auto dw = std::static_pointer_cast<json::JsonDiskWriter>
+ (httpServer_->getBody());
error = dw->finalize();
if(error == 0) {
json = dw->getResult();
diff --git a/src/HttpServerBodyCommand.h b/src/HttpServerBodyCommand.h
index 46c86919..34a1119d 100644
--- a/src/HttpServerBodyCommand.h
+++ b/src/HttpServerBodyCommand.h
@@ -36,7 +36,9 @@
#define D_HTTP_SERVER_BODY_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "TimerA2.h"
#include "ValueBase.h"
#include "RpcResponse.h"
@@ -50,8 +52,8 @@ class HttpServer;
class HttpServerBodyCommand : public Command {
private:
DownloadEngine* e_;
- SharedHandle<SocketCore> socket_;
- SharedHandle<HttpServer> httpServer_;
+ std::shared_ptr<SocketCore> socket_;
+ std::shared_ptr<HttpServer> httpServer_;
Timer timeoutTimer_;
bool writeCheck_;
@@ -59,7 +61,7 @@ private:
(const std::string& httpStatus,
int code,
const std::string& message,
- const SharedHandle<ValueBase>& id,
+ const std::shared_ptr<ValueBase>& id,
const std::string& callback);
void sendJsonRpcResponse
(const rpc::RpcResponse& res,
@@ -71,9 +73,9 @@ private:
void updateWriteCheck();
public:
HttpServerBodyCommand(cuid_t cuid,
- const SharedHandle<HttpServer>& httpServer,
+ const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket);
+ const std::shared_ptr<SocketCore>& socket);
virtual ~HttpServerBodyCommand();
diff --git a/src/HttpServerCommand.cc b/src/HttpServerCommand.cc
index 848df1bf..257ab474 100644
--- a/src/HttpServerCommand.cc
+++ b/src/HttpServerCommand.cc
@@ -64,7 +64,7 @@ namespace aria2 {
HttpServerCommand::HttpServerCommand
(cuid_t cuid,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket,
+ const std::shared_ptr<SocketCore>& socket,
bool secure)
: Command(cuid),
e_(e),
@@ -90,9 +90,9 @@ HttpServerCommand::HttpServerCommand
HttpServerCommand::HttpServerCommand
(cuid_t cuid,
- const SharedHandle<HttpServer>& httpServer,
+ const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket)
+ const std::shared_ptr<SocketCore>& socket)
: Command(cuid),
e_(e),
socket_(socket),
@@ -137,7 +137,7 @@ std::string createWebSocketServerKey(const std::string& clientKey)
} // namespace
namespace {
-int websocketHandshake(const SharedHandle<HttpHeader>& header)
+int websocketHandshake(const std::shared_ptr<HttpHeader>& header)
{
if(header->getMethod() != "GET" ||
header->find(HttpHeader::SEC_WEBSOCKET_KEY).empty()) {
@@ -190,7 +190,7 @@ bool HttpServerCommand::execute()
}
#endif // ENABLE_SSL
- SharedHandle<HttpHeader> header;
+ std::shared_ptr<HttpHeader> header;
header = httpServer_->receiveRequest();
if(!header) {
updateWriteCheck();
diff --git a/src/HttpServerCommand.h b/src/HttpServerCommand.h
index e8bf4cd0..aa47f943 100644
--- a/src/HttpServerCommand.h
+++ b/src/HttpServerCommand.h
@@ -36,7 +36,9 @@
#define D_HTTP_SERVER_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "TimerA2.h"
namespace aria2 {
@@ -48,8 +50,8 @@ class HttpServer;
class HttpServerCommand : public Command {
private:
DownloadEngine* e_;
- SharedHandle<SocketCore> socket_;
- SharedHandle<HttpServer> httpServer_;
+ std::shared_ptr<SocketCore> socket_;
+ std::shared_ptr<HttpServer> httpServer_;
Timer timeoutTimer_;
bool writeCheck_;
@@ -57,13 +59,13 @@ private:
void updateWriteCheck();
public:
HttpServerCommand(cuid_t cuid, DownloadEngine* e,
- const SharedHandle<SocketCore>& socket,
+ const std::shared_ptr<SocketCore>& socket,
bool secure);
HttpServerCommand(cuid_t cuid,
- const SharedHandle<HttpServer>& httpServer,
+ const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket);
+ const std::shared_ptr<SocketCore>& socket);
virtual ~HttpServerCommand();
diff --git a/src/HttpServerResponseCommand.cc b/src/HttpServerResponseCommand.cc
index 473afd84..a2aa1555 100644
--- a/src/HttpServerResponseCommand.cc
+++ b/src/HttpServerResponseCommand.cc
@@ -46,9 +46,9 @@ namespace aria2 {
HttpServerResponseCommand::HttpServerResponseCommand
(cuid_t cuid,
- const SharedHandle<HttpServer>& httpServer,
+ const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket)
+ const std::shared_ptr<SocketCore>& socket)
: AbstractHttpServerResponseCommand(cuid, httpServer, e, socket)
{}
@@ -56,7 +56,7 @@ HttpServerResponseCommand::~HttpServerResponseCommand()
{}
void HttpServerResponseCommand::afterSend
-(const SharedHandle<HttpServer>& httpServer,
+(const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e)
{
if(httpServer->supportsPersistentConnection()) {
diff --git a/src/HttpServerResponseCommand.h b/src/HttpServerResponseCommand.h
index 2df208e0..271c26a5 100644
--- a/src/HttpServerResponseCommand.h
+++ b/src/HttpServerResponseCommand.h
@@ -41,13 +41,13 @@ namespace aria2 {
class HttpServerResponseCommand : public AbstractHttpServerResponseCommand {
protected:
- virtual void afterSend(const SharedHandle<HttpServer>& httpServer,
+ virtual void afterSend(const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e);
public:
HttpServerResponseCommand(cuid_t cuid,
- const SharedHandle<HttpServer>& httpServer,
+ const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket);
+ const std::shared_ptr<SocketCore>& socket);
virtual ~HttpServerResponseCommand();
};
diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc
index 75d65637..0308c0ab 100644
--- a/src/HttpSkipResponseCommand.cc
+++ b/src/HttpSkipResponseCommand.cc
@@ -65,13 +65,13 @@ namespace aria2 {
HttpSkipResponseCommand::HttpSkipResponseCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
- const SharedHandle<HttpResponse>& httpResponse,
+ const std::shared_ptr<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpResponse>& httpResponse,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<SocketCore>& s)
: AbstractCommand(cuid, req, fileEntry, requestGroup, e, s,
httpConnection->getSocketRecvBuffer()),
httpConnection_(httpConnection),
@@ -87,7 +87,7 @@ HttpSkipResponseCommand::HttpSkipResponseCommand
HttpSkipResponseCommand::~HttpSkipResponseCommand() {}
void HttpSkipResponseCommand::installStreamFilter
-(const SharedHandle<StreamFilter>& streamFilter)
+(const std::shared_ptr<StreamFilter>& streamFilter)
{
if(!streamFilter) {
return;
@@ -132,8 +132,8 @@ bool HttpSkipResponseCommand::executeInternal()
} else {
// receivedBytes_ is not updated if transferEncoding is set.
// The return value is safely ignored here.
- streamFilter_->transform(SharedHandle<BinaryStream>(),
- SharedHandle<Segment>(),
+ streamFilter_->transform(std::shared_ptr<BinaryStream>(),
+ std::shared_ptr<Segment>(),
getSocketRecvBuffer()->getBuffer(),
getSocketRecvBuffer()->getBufferLength());
bufSize = streamFilter_->getBytesProcessed();
diff --git a/src/HttpSkipResponseCommand.h b/src/HttpSkipResponseCommand.h
index efbdc2a8..d30e1889 100644
--- a/src/HttpSkipResponseCommand.h
+++ b/src/HttpSkipResponseCommand.h
@@ -45,11 +45,11 @@ class StreamFilter;
class HttpSkipResponseCommand : public AbstractCommand {
private:
- SharedHandle<HttpConnection> httpConnection_;
+ std::shared_ptr<HttpConnection> httpConnection_;
- SharedHandle<HttpResponse> httpResponse_;
+ std::shared_ptr<HttpResponse> httpResponse_;
- SharedHandle<StreamFilter> streamFilter_;
+ std::shared_ptr<StreamFilter> streamFilter_;
bool sinkFilterOnly_;
@@ -65,17 +65,17 @@ protected:
public:
HttpSkipResponseCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
- const SharedHandle<HttpConnection>& httpConnection,
- const SharedHandle<HttpResponse>& httpResponse,
+ const std::shared_ptr<HttpConnection>& httpConnection,
+ const std::shared_ptr<HttpResponse>& httpResponse,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<SocketCore>& s);
virtual ~HttpSkipResponseCommand();
- void installStreamFilter(const SharedHandle<StreamFilter>& streamFilter);
+ void installStreamFilter(const std::shared_ptr<StreamFilter>& streamFilter);
void disableSocketCheck();
};
diff --git a/src/InitiateConnectionCommand.cc b/src/InitiateConnectionCommand.cc
index 98cae3b4..069a5a8f 100644
--- a/src/InitiateConnectionCommand.cc
+++ b/src/InitiateConnectionCommand.cc
@@ -58,8 +58,8 @@ namespace aria2 {
InitiateConnectionCommand::InitiateConnectionCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e)
: AbstractCommand(cuid, req, fileEntry, requestGroup, e)
@@ -76,7 +76,7 @@ InitiateConnectionCommand::~InitiateConnectionCommand() {}
bool InitiateConnectionCommand::executeInternal() {
std::string hostname;
uint16_t port;
- SharedHandle<Request> proxyRequest = createProxyRequest();
+ std::shared_ptr<Request> proxyRequest = createProxyRequest();
if(!proxyRequest) {
hostname = getRequest()->getHost();
port = getRequest()->getPort();
@@ -120,23 +120,23 @@ bool InitiateConnectionCommand::executeInternal() {
}
void InitiateConnectionCommand::setConnectedAddrInfo
-(const SharedHandle<Request>& req,
+(const std::shared_ptr<Request>& req,
const std::string& hostname,
- const SharedHandle<SocketCore>& socket)
+ const std::shared_ptr<SocketCore>& socket)
{
std::pair<std::string, uint16_t> peerAddr;
socket->getPeerInfo(peerAddr);
req->setConnectedAddrInfo(hostname, peerAddr.first, peerAddr.second);
}
-SharedHandle<BackupConnectInfo>
+std::shared_ptr<BackupConnectInfo>
InitiateConnectionCommand::createBackupIPv4ConnectCommand
(const std::string& hostname, const std::string& ipaddr, uint16_t port,
Command* mainCommand)
{
// Prepare IPv4 backup connection attemp in "Happy Eyeballs"
// fashion.
- SharedHandle<BackupConnectInfo> info;
+ std::shared_ptr<BackupConnectInfo> info;
char buf[sizeof(in6_addr)];
if(inetPton(AF_INET6, ipaddr.c_str(), &buf) == -1) {
return info;
@@ -152,7 +152,7 @@ InitiateConnectionCommand::createBackupIPv4ConnectCommand
BackupIPv4ConnectCommand* command = new BackupIPv4ConnectCommand
(getDownloadEngine()->newCUID(), *i, port, info, mainCommand,
getRequestGroup(), getDownloadEngine());
- A2_LOG_INFO(fmt("Issue backup connection command CUID#%"PRId64
+ A2_LOG_INFO(fmt("Issue backup connection command CUID#%" PRId64
", addr=%s", command->getCuid(), (*i).c_str()));
getDownloadEngine()->addCommand(command);
return info;
@@ -165,7 +165,7 @@ void InitiateConnectionCommand::setupBackupConnection
(const std::string& hostname, const std::string& addr, uint16_t port,
ConnectCommand* c)
{
- SharedHandle<BackupConnectInfo> backupConnectInfo
+ std::shared_ptr<BackupConnectInfo> backupConnectInfo
= createBackupIPv4ConnectCommand(hostname, addr, port, c);
if(backupConnectInfo) {
c->setBackupConnectInfo(backupConnectInfo);
diff --git a/src/InitiateConnectionCommand.h b/src/InitiateConnectionCommand.h
index def24b0a..c5e476a3 100644
--- a/src/InitiateConnectionCommand.h
+++ b/src/InitiateConnectionCommand.h
@@ -61,14 +61,14 @@ protected:
virtual Command* createNextCommand
(const std::string& hostname, const std::string& addr, uint16_t port,
const std::vector<std::string>& resolvedAddresses,
- const SharedHandle<Request>& proxyRequest) = 0;
+ const std::shared_ptr<Request>& proxyRequest) = 0;
void setConnectedAddrInfo
- (const SharedHandle<Request>& req,
+ (const std::shared_ptr<Request>& req,
const std::string& hostname,
- const SharedHandle<SocketCore>& socket);
+ const std::shared_ptr<SocketCore>& socket);
- SharedHandle<BackupConnectInfo> createBackupIPv4ConnectCommand
+ std::shared_ptr<BackupConnectInfo> createBackupIPv4ConnectCommand
(const std::string& hostname, const std::string& ipaddr, uint16_t port,
Command* mainCommand);
@@ -76,8 +76,8 @@ protected:
(const std::string& hostname, const std::string& addr, uint16_t port,
ConnectCommand* c);
public:
- InitiateConnectionCommand(cuid_t cuid, const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ InitiateConnectionCommand(cuid_t cuid, const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e);
diff --git a/src/InitiateConnectionCommandFactory.cc b/src/InitiateConnectionCommandFactory.cc
index 9b0b9096..2d4e6141 100644
--- a/src/InitiateConnectionCommandFactory.cc
+++ b/src/InitiateConnectionCommandFactory.cc
@@ -50,8 +50,8 @@ namespace aria2 {
Command*
InitiateConnectionCommandFactory::createInitiateConnectionCommand
(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e)
{
diff --git a/src/InitiateConnectionCommandFactory.h b/src/InitiateConnectionCommandFactory.h
index af4bb0ec..1cedf465 100644
--- a/src/InitiateConnectionCommandFactory.h
+++ b/src/InitiateConnectionCommandFactory.h
@@ -36,7 +36,9 @@
#define D_INITIATE_CONNECTION_COMMAND_FACTORY_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "Command.h"
namespace aria2 {
@@ -50,8 +52,8 @@ class InitiateConnectionCommandFactory {
public:
static Command*
createInitiateConnectionCommand(cuid_t cuid,
- const SharedHandle<Request>& req,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<Request>& req,
+ const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e);
};
diff --git a/src/InitiatorMSEHandshakeCommand.cc b/src/InitiatorMSEHandshakeCommand.cc
index 65b6c437..e5022921 100644
--- a/src/InitiatorMSEHandshakeCommand.cc
+++ b/src/InitiatorMSEHandshakeCommand.cc
@@ -62,10 +62,10 @@ namespace aria2 {
InitiatorMSEHandshakeCommand::InitiatorMSEHandshakeCommand
(cuid_t cuid,
RequestGroup* requestGroup,
- const SharedHandle<Peer>& p,
+ const std::shared_ptr<Peer>& p,
DownloadEngine* e,
- const SharedHandle<BtRuntime>& btRuntime,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<BtRuntime>& btRuntime,
+ const std::shared_ptr<SocketCore>& s)
: PeerAbstractCommand(cuid, p, e, s),
requestGroup_(requestGroup),
btRuntime_(btRuntime),
@@ -149,7 +149,7 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
}
case INITIATOR_RECEIVE_PAD_D: {
if(mseHandshake_->receivePad()) {
- SharedHandle<PeerConnection> peerConnection
+ std::shared_ptr<PeerConnection> peerConnection
(new PeerConnection(getCuid(), getPeer(), getSocket()));
if(mseHandshake_->getNegotiatedCryptoType() ==
MSEHandshake::CRYPTO_ARC4){
@@ -199,7 +199,7 @@ void InitiatorMSEHandshakeCommand::tryNewPeer()
{
if(peerStorage_->isPeerAvailable() && btRuntime_->lessThanEqMinPeers()) {
cuid_t ncuid = getDownloadEngine()->newCUID();
- SharedHandle<Peer> peer = peerStorage_->checkoutPeer(ncuid);
+ std::shared_ptr<Peer> peer = peerStorage_->checkoutPeer(ncuid);
// sanity check
if(peer) {
PeerInitiateConnectionCommand* command;
@@ -254,18 +254,18 @@ bool InitiatorMSEHandshakeCommand::exitBeforeExecute()
}
void InitiatorMSEHandshakeCommand::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
void InitiatorMSEHandshakeCommand::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
-const SharedHandle<Option>& InitiatorMSEHandshakeCommand::getOption() const
+const std::shared_ptr<Option>& InitiatorMSEHandshakeCommand::getOption() const
{
return requestGroup_->getOption();
}
diff --git a/src/InitiatorMSEHandshakeCommand.h b/src/InitiatorMSEHandshakeCommand.h
index 5b44abcb..5e80ca76 100644
--- a/src/InitiatorMSEHandshakeCommand.h
+++ b/src/InitiatorMSEHandshakeCommand.h
@@ -60,16 +60,16 @@ public:
private:
RequestGroup* requestGroup_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
- SharedHandle<BtRuntime> btRuntime_;
+ std::shared_ptr<BtRuntime> btRuntime_;
Seq sequence_;
MSEHandshake* mseHandshake_;
- const SharedHandle<Option>& getOption() const;
+ const std::shared_ptr<Option>& getOption() const;
void tryNewPeer();
protected:
@@ -81,16 +81,16 @@ public:
InitiatorMSEHandshakeCommand
(cuid_t cuid,
RequestGroup* requestGroup,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
DownloadEngine* e,
- const SharedHandle<BtRuntime>& btRuntime,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<BtRuntime>& btRuntime,
+ const std::shared_ptr<SocketCore>& s);
virtual ~InitiatorMSEHandshakeCommand();
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
};
} // namespace aria2
diff --git a/src/IteratableChecksumValidator.cc b/src/IteratableChecksumValidator.cc
index 405ba2bf..c07daafb 100644
--- a/src/IteratableChecksumValidator.cc
+++ b/src/IteratableChecksumValidator.cc
@@ -50,8 +50,8 @@
namespace aria2 {
IteratableChecksumValidator::IteratableChecksumValidator
-(const SharedHandle<DownloadContext>& dctx,
- const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<DownloadContext>& dctx,
+ const std::shared_ptr<PieceStorage>& pieceStorage)
: dctx_(dctx),
pieceStorage_(pieceStorage),
currentOffset_(0)
diff --git a/src/IteratableChecksumValidator.h b/src/IteratableChecksumValidator.h
index 18d51efd..e747c57d 100644
--- a/src/IteratableChecksumValidator.h
+++ b/src/IteratableChecksumValidator.h
@@ -36,7 +36,8 @@
#define D_ITERATABLE_CHECKSUM_VALIDATOR_H
#include "IteratableValidator.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -47,16 +48,16 @@ class MessageDigest;
class IteratableChecksumValidator:public IteratableValidator
{
private:
- SharedHandle<DownloadContext> dctx_;
+ std::shared_ptr<DownloadContext> dctx_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
int64_t currentOffset_;
- SharedHandle<MessageDigest> ctx_;
+ std::shared_ptr<MessageDigest> ctx_;
public:
- IteratableChecksumValidator(const SharedHandle<DownloadContext>& dctx,
- const SharedHandle<PieceStorage>& pieceStorage);
+ IteratableChecksumValidator(const std::shared_ptr<DownloadContext>& dctx,
+ const std::shared_ptr<PieceStorage>& pieceStorage);
virtual ~IteratableChecksumValidator();
diff --git a/src/IteratableChunkChecksumValidator.cc b/src/IteratableChunkChecksumValidator.cc
index 17c2558c..a2fbce41 100644
--- a/src/IteratableChunkChecksumValidator.cc
+++ b/src/IteratableChunkChecksumValidator.cc
@@ -54,8 +54,8 @@
namespace aria2 {
IteratableChunkChecksumValidator::IteratableChunkChecksumValidator
-(const SharedHandle<DownloadContext>& dctx,
- const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<DownloadContext>& dctx,
+ const std::shared_ptr<PieceStorage>& pieceStorage)
: dctx_(dctx),
pieceStorage_(pieceStorage),
bitfield_(new BitfieldMan(dctx_->getPieceLength(),
diff --git a/src/IteratableChunkChecksumValidator.h b/src/IteratableChunkChecksumValidator.h
index ed72ebb4..ef42d9e9 100644
--- a/src/IteratableChunkChecksumValidator.h
+++ b/src/IteratableChunkChecksumValidator.h
@@ -38,8 +38,7 @@
#include "IteratableValidator.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -51,19 +50,19 @@ class MessageDigest;
class IteratableChunkChecksumValidator:public IteratableValidator
{
private:
- SharedHandle<DownloadContext> dctx_;
- SharedHandle<PieceStorage> pieceStorage_;
- SharedHandle<BitfieldMan> bitfield_;
+ std::shared_ptr<DownloadContext> dctx_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
+ std::shared_ptr<BitfieldMan> bitfield_;
size_t currentIndex_;
- SharedHandle<MessageDigest> ctx_;
+ std::shared_ptr<MessageDigest> ctx_;
std::string calculateActualChecksum();
std::string digest(int64_t offset, size_t length);
public:
- IteratableChunkChecksumValidator(const SharedHandle<DownloadContext>& dctx,
- const SharedHandle<PieceStorage>& pieceStorage);
+ IteratableChunkChecksumValidator(const std::shared_ptr<DownloadContext>& dctx,
+ const std::shared_ptr<PieceStorage>& pieceStorage);
virtual ~IteratableChunkChecksumValidator();
diff --git a/src/JsonParser.cc b/src/JsonParser.cc
index bae75286..d5501f18 100644
--- a/src/JsonParser.cc
+++ b/src/JsonParser.cc
@@ -33,8 +33,10 @@
*/
/* copyright --> */
#include "JsonParser.h"
-#include "StructParserStateMachine.h"
+#include <cassert>
+
+#include "StructParserStateMachine.h"
#include "util.h"
namespace aria2 {
diff --git a/src/KqueueEventPoll.cc b/src/KqueueEventPoll.cc
index 6cf6c66d..d1610318 100644
--- a/src/KqueueEventPoll.cc
+++ b/src/KqueueEventPoll.cc
@@ -170,7 +170,7 @@ int translateEvents(EventPoll::EventType events)
bool KqueueEventPoll::addEvents
(sock_t socket, const KqueueEventPoll::KEvent& event)
{
- SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
+ std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
KSocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
int r = 0;
struct timespec zeroTimeout = { 0, 0 };
@@ -210,7 +210,7 @@ bool KqueueEventPoll::addEvents(sock_t socket, Command* command,
#ifdef ENABLE_ASYNC_DNS
bool KqueueEventPoll::addEvents(sock_t socket, Command* command, int events,
- const SharedHandle<AsyncNameResolver>& rs)
+ const std::shared_ptr<AsyncNameResolver>& rs)
{
return addEvents(socket, KADNSEvent(rs, command, socket, events));
}
@@ -219,7 +219,7 @@ bool KqueueEventPoll::addEvents(sock_t socket, Command* command, int events,
bool KqueueEventPoll::deleteEvents(sock_t socket,
const KqueueEventPoll::KEvent& event)
{
- SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
+ std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
KSocketEntrySet::iterator i = socketEntries_.find(socketEntry);
if(i == socketEntries_.end()) {
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
@@ -247,7 +247,7 @@ bool KqueueEventPoll::deleteEvents(sock_t socket,
#ifdef ENABLE_ASYNC_DNS
bool KqueueEventPoll::deleteEvents(sock_t socket, Command* command,
- const SharedHandle<AsyncNameResolver>& rs)
+ const std::shared_ptr<AsyncNameResolver>& rs)
{
return deleteEvents(socket, KADNSEvent(rs, command, socket, 0));
}
@@ -262,9 +262,9 @@ bool KqueueEventPoll::deleteEvents(sock_t socket, Command* command,
#ifdef ENABLE_ASYNC_DNS
bool KqueueEventPoll::addNameResolver
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
- SharedHandle<KAsyncNameResolverEntry> entry
+ std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
if(itr == nameResolverEntries_.end()) {
@@ -277,9 +277,9 @@ bool KqueueEventPoll::addNameResolver
}
bool KqueueEventPoll::deleteNameResolver
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
- SharedHandle<KAsyncNameResolverEntry> entry
+ std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
if(itr == nameResolverEntries_.end()) {
diff --git a/src/KqueueEventPoll.h b/src/KqueueEventPoll.h
index 2ab6aff7..c84d2078 100644
--- a/src/KqueueEventPoll.h
+++ b/src/KqueueEventPoll.h
@@ -75,12 +75,12 @@ private:
friend int accumulateEvent(int events, const KEvent& event);
private:
- typedef std::set<SharedHandle<KSocketEntry>,
- DerefLess<SharedHandle<KSocketEntry> > > KSocketEntrySet;
+ typedef std::set<std::shared_ptr<KSocketEntry>,
+ DerefLess<std::shared_ptr<KSocketEntry> > > KSocketEntrySet;
KSocketEntrySet socketEntries_;
#ifdef ENABLE_ASYNC_DNS
- typedef std::set<SharedHandle<KAsyncNameResolverEntry>,
- DerefLess<SharedHandle<KAsyncNameResolverEntry> > >
+ typedef std::set<std::shared_ptr<KAsyncNameResolverEntry>,
+ DerefLess<std::shared_ptr<KAsyncNameResolverEntry> > >
KAsyncNameResolverEntrySet;
KAsyncNameResolverEntrySet nameResolverEntries_;
#endif // ENABLE_ASYNC_DNS
@@ -98,10 +98,10 @@ private:
bool deleteEvents(sock_t socket, const KEvent& event);
bool addEvents(sock_t socket, Command* command, int events,
- const SharedHandle<AsyncNameResolver>& rs);
+ const std::shared_ptr<AsyncNameResolver>& rs);
bool deleteEvents(sock_t socket, Command* command,
- const SharedHandle<AsyncNameResolver>& rs);
+ const std::shared_ptr<AsyncNameResolver>& rs);
public:
KqueueEventPoll();
@@ -119,10 +119,10 @@ public:
Command* command, EventPoll::EventType events);
#ifdef ENABLE_ASYNC_DNS
- virtual bool addNameResolver(const SharedHandle<AsyncNameResolver>& resolver,
+ virtual bool addNameResolver(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command);
virtual bool deleteNameResolver
- (const SharedHandle<AsyncNameResolver>& resolver, Command* command);
+ (const std::shared_ptr<AsyncNameResolver>& resolver, Command* command);
#endif // ENABLE_ASYNC_DNS
static const int IEV_READ = POLLIN;
diff --git a/src/LibgcryptMessageDigestImpl.cc b/src/LibgcryptMessageDigestImpl.cc
index 84c3f8bc..23ae1389 100644
--- a/src/LibgcryptMessageDigestImpl.cc
+++ b/src/LibgcryptMessageDigestImpl.cc
@@ -51,9 +51,9 @@ MessageDigestImpl::~MessageDigestImpl()
gcry_md_close(ctx_);
}
-SharedHandle<MessageDigestImpl> MessageDigestImpl::sha1()
+std::shared_ptr<MessageDigestImpl> MessageDigestImpl::sha1()
{
- return SharedHandle<MessageDigestImpl>(new MessageDigestImpl(GCRY_MD_SHA1));
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestImpl(GCRY_MD_SHA1));
}
typedef HashFuncEntry<int> CHashFuncEntry;
@@ -70,11 +70,11 @@ CHashFuncEntry hashFuncs[] = {
};
} // namespace
-SharedHandle<MessageDigestImpl> MessageDigestImpl::create
+std::shared_ptr<MessageDigestImpl> MessageDigestImpl::create
(const std::string& hashType)
{
int hashFunc = getHashFunc(vbegin(hashFuncs), vend(hashFuncs), hashType);
- return SharedHandle<MessageDigestImpl>(new MessageDigestImpl(hashFunc));
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestImpl(hashFunc));
}
bool MessageDigestImpl::supports(const std::string& hashType)
diff --git a/src/LibgcryptMessageDigestImpl.h b/src/LibgcryptMessageDigestImpl.h
index 1bec9154..212e09a7 100644
--- a/src/LibgcryptMessageDigestImpl.h
+++ b/src/LibgcryptMessageDigestImpl.h
@@ -38,11 +38,10 @@
#include "common.h"
#include <string>
+#include <memory>
#include <gcrypt.h>
-#include "SharedHandle.h"
-
namespace aria2 {
class MessageDigestImpl {
@@ -58,8 +57,8 @@ private:
public:
~MessageDigestImpl();
- static SharedHandle<MessageDigestImpl> sha1();
- static SharedHandle<MessageDigestImpl> create(const std::string& hashType);
+ static std::shared_ptr<MessageDigestImpl> sha1();
+ static std::shared_ptr<MessageDigestImpl> create(const std::string& hashType);
static bool supports(const std::string& hashType);
static size_t getDigestLength(const std::string& hashType);
diff --git a/src/LibnettleMessageDigestImpl.cc b/src/LibnettleMessageDigestImpl.cc
index d8eac9b7..5f49648d 100644
--- a/src/LibnettleMessageDigestImpl.cc
+++ b/src/LibnettleMessageDigestImpl.cc
@@ -53,9 +53,9 @@ MessageDigestImpl::~MessageDigestImpl()
delete [] ctx_;
}
-SharedHandle<MessageDigestImpl> MessageDigestImpl::sha1()
+std::shared_ptr<MessageDigestImpl> MessageDigestImpl::sha1()
{
- return SharedHandle<MessageDigestImpl>(new MessageDigestImpl(&nettle_sha1));
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestImpl(&nettle_sha1));
}
typedef HashFuncEntry<const nettle_hash*> CHashFuncEntry;
@@ -72,12 +72,12 @@ CHashFuncEntry hashFuncs[] = {
};
} // namespace
-SharedHandle<MessageDigestImpl> MessageDigestImpl::create
+std::shared_ptr<MessageDigestImpl> MessageDigestImpl::create
(const std::string& hashType)
{
const nettle_hash* hashInfo =
getHashFunc(vbegin(hashFuncs), vend(hashFuncs), hashType);
- return SharedHandle<MessageDigestImpl>(new MessageDigestImpl(hashInfo));
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestImpl(hashInfo));
}
bool MessageDigestImpl::supports(const std::string& hashType)
diff --git a/src/LibnettleMessageDigestImpl.h b/src/LibnettleMessageDigestImpl.h
index 3c6a86d6..2028885f 100644
--- a/src/LibnettleMessageDigestImpl.h
+++ b/src/LibnettleMessageDigestImpl.h
@@ -38,11 +38,10 @@
#include "common.h"
#include <string>
+#include <memory>
#include <nettle/nettle-meta.h>
-#include "SharedHandle.h"
-
namespace aria2 {
class MessageDigestImpl {
@@ -58,8 +57,8 @@ private:
public:
~MessageDigestImpl();
- static SharedHandle<MessageDigestImpl> sha1();
- static SharedHandle<MessageDigestImpl> create(const std::string& hashType);
+ static std::shared_ptr<MessageDigestImpl> sha1();
+ static std::shared_ptr<MessageDigestImpl> create(const std::string& hashType);
static bool supports(const std::string& hashType);
static size_t getDigestLength(const std::string& hashType);
diff --git a/src/LibsslMessageDigestImpl.cc b/src/LibsslMessageDigestImpl.cc
index 2ef9bfb7..8a024041 100644
--- a/src/LibsslMessageDigestImpl.cc
+++ b/src/LibsslMessageDigestImpl.cc
@@ -52,9 +52,9 @@ MessageDigestImpl::~MessageDigestImpl()
EVP_MD_CTX_cleanup(&ctx_);
}
-SharedHandle<MessageDigestImpl> MessageDigestImpl::sha1()
+std::shared_ptr<MessageDigestImpl> MessageDigestImpl::sha1()
{
- return SharedHandle<MessageDigestImpl>(new MessageDigestImpl(EVP_sha1()));
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestImpl(EVP_sha1()));
}
typedef HashFuncEntry<const EVP_MD*> CHashFuncEntry;
@@ -79,12 +79,12 @@ CHashFuncEntry hashFuncs[] = {
};
} // namespace
-SharedHandle<MessageDigestImpl> MessageDigestImpl::create
+std::shared_ptr<MessageDigestImpl> MessageDigestImpl::create
(const std::string& hashType)
{
const EVP_MD* hashFunc = getHashFunc(vbegin(hashFuncs), vend(hashFuncs),
hashType);
- return SharedHandle<MessageDigestImpl>(new MessageDigestImpl(hashFunc));
+ return std::shared_ptr<MessageDigestImpl>(new MessageDigestImpl(hashFunc));
}
bool MessageDigestImpl::supports(const std::string& hashType)
diff --git a/src/LibsslMessageDigestImpl.h b/src/LibsslMessageDigestImpl.h
index 1557c4c2..6d3a89f8 100644
--- a/src/LibsslMessageDigestImpl.h
+++ b/src/LibsslMessageDigestImpl.h
@@ -38,11 +38,10 @@
#include "common.h"
#include <string>
+#include <memory>
#include <openssl/evp.h>
-#include "SharedHandle.h"
-
namespace aria2 {
class MessageDigestImpl {
@@ -58,8 +57,8 @@ private:
public:
~MessageDigestImpl();
- static SharedHandle<MessageDigestImpl> sha1();
- static SharedHandle<MessageDigestImpl> create(const std::string& hashType);
+ static std::shared_ptr<MessageDigestImpl> sha1();
+ static std::shared_ptr<MessageDigestImpl> create(const std::string& hashType);
static bool supports(const std::string& hashType);
static size_t getDigestLength(const std::string& hashType);
diff --git a/src/LibuvEventPoll.cc b/src/LibuvEventPoll.cc
index 2509357f..1c415d2d 100644
--- a/src/LibuvEventPoll.cc
+++ b/src/LibuvEventPoll.cc
@@ -214,7 +214,7 @@ void LibuvEventPoll::pollCallback(KPoll* poll, int status, int events)
bool LibuvEventPoll::addEvents(sock_t socket,
const LibuvEventPoll::KEvent& event)
{
- SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
+ std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
KSocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
if (i != socketEntries_.end() && **i == *socketEntry) {
@@ -243,7 +243,7 @@ bool LibuvEventPoll::addEvents(sock_t socket, Command* command, EventPoll::Event
#ifdef ENABLE_ASYNC_DNS
bool LibuvEventPoll::addEvents(sock_t socket, Command* command, int events,
- const SharedHandle<AsyncNameResolver>& rs)
+ const std::shared_ptr<AsyncNameResolver>& rs)
{
return addEvents(socket, KADNSEvent(rs, command, socket, events));
}
@@ -252,7 +252,7 @@ bool LibuvEventPoll::addEvents(sock_t socket, Command* command, int events,
bool LibuvEventPoll::deleteEvents(sock_t socket,
const LibuvEventPoll::KEvent& event)
{
- SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
+ std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
KSocketEntrySet::iterator i = socketEntries_.find(socketEntry);
if (i == socketEntries_.end()) {
@@ -280,7 +280,7 @@ bool LibuvEventPoll::deleteEvents(sock_t socket,
#ifdef ENABLE_ASYNC_DNS
bool LibuvEventPoll::deleteEvents(sock_t socket, Command* command,
- const SharedHandle<AsyncNameResolver>& rs)
+ const std::shared_ptr<AsyncNameResolver>& rs)
{
return deleteEvents(socket, KADNSEvent(rs, command, socket, 0));
}
@@ -294,10 +294,10 @@ bool LibuvEventPoll::deleteEvents(sock_t socket, Command* command,
}
#ifdef ENABLE_ASYNC_DNS
-bool LibuvEventPoll::addNameResolver(const SharedHandle<AsyncNameResolver>& resolver,
+bool LibuvEventPoll::addNameResolver(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command)
{
- SharedHandle<KAsyncNameResolverEntry> entry(
+ std::shared_ptr<KAsyncNameResolverEntry> entry(
new KAsyncNameResolverEntry(resolver, command));
KAsyncNameResolverEntrySet::iterator itr =
nameResolverEntries_.lower_bound(entry);
@@ -309,10 +309,10 @@ bool LibuvEventPoll::addNameResolver(const SharedHandle<AsyncNameResolver>& reso
return true;
}
-bool LibuvEventPoll::deleteNameResolver(const SharedHandle<AsyncNameResolver>& resolver,
+bool LibuvEventPoll::deleteNameResolver(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command)
{
- SharedHandle<KAsyncNameResolverEntry> entry(
+ std::shared_ptr<KAsyncNameResolverEntry> entry(
new KAsyncNameResolverEntry(resolver, command));
KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
if (itr == nameResolverEntries_.end()) {
diff --git a/src/LibuvEventPoll.h b/src/LibuvEventPoll.h
index 5c058737..b7069176 100644
--- a/src/LibuvEventPoll.h
+++ b/src/LibuvEventPoll.h
@@ -105,14 +105,14 @@ private:
}
};
- typedef std::set<SharedHandle<KSocketEntry>,
- DerefLess<SharedHandle<KSocketEntry> > > KSocketEntrySet;
+ typedef std::set<std::shared_ptr<KSocketEntry>,
+ DerefLess<std::shared_ptr<KSocketEntry> > > KSocketEntrySet;
typedef std::map<sock_t, KPoll*> KPolls;
#ifdef ENABLE_ASYNC_DNS
- typedef std::set<SharedHandle<KAsyncNameResolverEntry>,
- DerefLess<SharedHandle<KAsyncNameResolverEntry> > >
+ typedef std::set<std::shared_ptr<KAsyncNameResolverEntry>,
+ DerefLess<std::shared_ptr<KAsyncNameResolverEntry> > >
KAsyncNameResolverEntrySet;
#endif // ENABLE_ASYNC_DNS
@@ -130,9 +130,9 @@ private:
#ifdef ENABLE_ASYNC_DNS
bool addEvents(sock_t socket, Command* command, int events,
- const SharedHandle<AsyncNameResolver>& rs);
+ const std::shared_ptr<AsyncNameResolver>& rs);
bool deleteEvents(sock_t socket, Command* command,
- const SharedHandle<AsyncNameResolver>& rs);
+ const std::shared_ptr<AsyncNameResolver>& rs);
#endif
static int translateEvents(EventPoll::EventType events);
@@ -151,10 +151,10 @@ public:
Command* command, EventPoll::EventType events);
#ifdef ENABLE_ASYNC_DNS
- virtual bool addNameResolver(const SharedHandle<AsyncNameResolver>& resolver,
+ virtual bool addNameResolver(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command);
virtual bool deleteNameResolver(
- const SharedHandle<AsyncNameResolver>& resolver, Command* command);
+ const std::shared_ptr<AsyncNameResolver>& resolver, Command* command);
#endif // ENABLE_ASYNC_DNS
static const int IEV_READ = UV_READABLE;
diff --git a/src/LogFactory.cc b/src/LogFactory.cc
index 126397ae..66b0fa77 100644
--- a/src/LogFactory.cc
+++ b/src/LogFactory.cc
@@ -40,12 +40,12 @@
namespace aria2 {
std::string LogFactory::filename_ = DEV_NULL;
-SharedHandle<Logger> LogFactory::logger_;
+std::shared_ptr<Logger> LogFactory::logger_;
bool LogFactory::consoleOutput_ = true;
Logger::LEVEL LogFactory::logLevel_ = Logger::A2_DEBUG;
Logger::LEVEL LogFactory::consoleLogLevel_ = Logger::A2_NOTICE;
-void LogFactory::openLogger(const SharedHandle<Logger>& logger)
+void LogFactory::openLogger(const std::shared_ptr<Logger>& logger)
{
if(filename_ != DEV_NULL) {
// don't open file DEV_NULL for performance sake.
@@ -70,10 +70,10 @@ void LogFactory::reconfigure()
}
}
-const SharedHandle<Logger>& LogFactory::getInstance()
+const std::shared_ptr<Logger>& LogFactory::getInstance()
{
if(!logger_) {
- SharedHandle<Logger> slogger(new Logger());
+ std::shared_ptr<Logger> slogger(new Logger());
openLogger(slogger);
logger_.swap(slogger);
}
diff --git a/src/LogFactory.h b/src/LogFactory.h
index b80aadd8..d28b115f 100644
--- a/src/LogFactory.h
+++ b/src/LogFactory.h
@@ -38,21 +38,21 @@
#include "common.h"
#include <string>
+#include <memory>
#include "Logger.h"
-#include "SharedHandle.h"
namespace aria2 {
class LogFactory {
private:
static std::string filename_;
- static SharedHandle<Logger> logger_;
+ static std::shared_ptr<Logger> logger_;
static bool consoleOutput_;
static Logger::LEVEL logLevel_;
static Logger::LEVEL consoleLogLevel_;
- static void openLogger(const SharedHandle<Logger>& logger);
+ static void openLogger(const std::shared_ptr<Logger>& logger);
LogFactory();
public:
@@ -60,7 +60,7 @@ public:
* Get logger instance. Returned logger is singleton.
* This function is not thread-safe.
*/
- static const SharedHandle<Logger>& getInstance();
+ static const std::shared_ptr<Logger>& getInstance();
/**
* Set a filename to write log. If name is "-", log is written to
@@ -112,14 +112,14 @@ public:
#define A2_LOG(level, msg) \
{ \
- const aria2::SharedHandle<aria2::Logger>& logger = \
+ const std::shared_ptr<aria2::Logger>& logger = \
aria2::LogFactory::getInstance(); \
if(logger->levelEnabled(level)) \
logger->log(level, __FILE__, __LINE__, msg); \
}
#define A2_LOG_EX(level, msg, ex) \
{ \
- const aria2::SharedHandle<aria2::Logger>& logger = \
+ const std::shared_ptr<aria2::Logger>& logger = \
aria2::LogFactory::getInstance(); \
if(logger->levelEnabled(level)) \
logger->log(level, __FILE__, __LINE__, msg, ex); \
diff --git a/src/Logger.cc b/src/Logger.cc
index 0df67660..6115db4e 100644
--- a/src/Logger.cc
+++ b/src/Logger.cc
@@ -37,6 +37,7 @@
#include <unistd.h>
#include <cstring>
#include <cstdio>
+#include <cassert>
#include "DlAbortEx.h"
#include "fmt.h"
diff --git a/src/Logger.h b/src/Logger.h
index c3a91e1a..a68ab72f 100644
--- a/src/Logger.h
+++ b/src/Logger.h
@@ -38,8 +38,7 @@
#include "common.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -58,7 +57,7 @@ public:
private:
// Minimum log level for file log output.
LEVEL logLevel_;
- SharedHandle<OutputFile> fpp_;
+ std::shared_ptr<OutputFile> fpp_;
// Minimum log level for console log output.
LEVEL consoleLogLevel_;
// true if console log output is enabled.
diff --git a/src/LpdDispatchMessageCommand.cc b/src/LpdDispatchMessageCommand.cc
index 00c74808..d2a54fbf 100644
--- a/src/LpdDispatchMessageCommand.cc
+++ b/src/LpdDispatchMessageCommand.cc
@@ -47,7 +47,7 @@ namespace aria2 {
LpdDispatchMessageCommand::LpdDispatchMessageCommand
(cuid_t cuid,
- const SharedHandle<LpdMessageDispatcher>& dispatcher,
+ const std::shared_ptr<LpdMessageDispatcher>& dispatcher,
DownloadEngine* e)
: Command(cuid),
dispatcher_(dispatcher),
diff --git a/src/LpdDispatchMessageCommand.h b/src/LpdDispatchMessageCommand.h
index cd53cfa0..1fa8b018 100644
--- a/src/LpdDispatchMessageCommand.h
+++ b/src/LpdDispatchMessageCommand.h
@@ -36,7 +36,8 @@
#define D_LPD_DISPATCH_MESSAGE_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -46,21 +47,21 @@ class BtRuntime;
class LpdDispatchMessageCommand:public Command {
private:
- SharedHandle<LpdMessageDispatcher> dispatcher_;
+ std::shared_ptr<LpdMessageDispatcher> dispatcher_;
DownloadEngine* e_;
int tryCount_;
- SharedHandle<BtRuntime> btRuntime_;
+ std::shared_ptr<BtRuntime> btRuntime_;
public:
LpdDispatchMessageCommand
(cuid_t cuid,
- const SharedHandle<LpdMessageDispatcher>& dispatcher,
+ const std::shared_ptr<LpdMessageDispatcher>& dispatcher,
DownloadEngine* e);
~LpdDispatchMessageCommand();
virtual bool execute();
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime)
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
diff --git a/src/LpdMessage.cc b/src/LpdMessage.cc
index adc14cc0..f7a4311c 100644
--- a/src/LpdMessage.cc
+++ b/src/LpdMessage.cc
@@ -38,7 +38,7 @@ namespace aria2 {
LpdMessage::LpdMessage() {}
LpdMessage::LpdMessage
-(const SharedHandle<Peer>& peer, const std::string& infoHash)
+(const std::shared_ptr<Peer>& peer, const std::string& infoHash)
: peer(peer), infoHash(infoHash)
{}
diff --git a/src/LpdMessage.h b/src/LpdMessage.h
index 42d55678..893d67b9 100644
--- a/src/LpdMessage.h
+++ b/src/LpdMessage.h
@@ -36,18 +36,17 @@
#include "common.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
class Peer;
struct LpdMessage {
- SharedHandle<Peer> peer;
+ std::shared_ptr<Peer> peer;
std::string infoHash;
LpdMessage();
- LpdMessage(const SharedHandle<Peer>& peer, const std::string& infoHash);
+ LpdMessage(const std::shared_ptr<Peer>& peer, const std::string& infoHash);
~LpdMessage();
};
diff --git a/src/LpdMessageDispatcher.h b/src/LpdMessageDispatcher.h
index e4685416..6fa02549 100644
--- a/src/LpdMessageDispatcher.h
+++ b/src/LpdMessageDispatcher.h
@@ -36,8 +36,8 @@
#include "common.h"
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
namespace aria2 {
@@ -46,7 +46,7 @@ class SocketCore;
class LpdMessageDispatcher {
private:
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<SocketCore> socket_;
std::string infoHash_;
uint16_t port_;
std::string multicastAddress_;
diff --git a/src/LpdMessageReceiver.cc b/src/LpdMessageReceiver.cc
index 49da2d64..20d9f02a 100644
--- a/src/LpdMessageReceiver.cc
+++ b/src/LpdMessageReceiver.cc
@@ -77,9 +77,9 @@ bool LpdMessageReceiver::init(const std::string& localAddr)
return false;
}
-SharedHandle<LpdMessage> LpdMessageReceiver::receiveMessage()
+std::shared_ptr<LpdMessage> LpdMessageReceiver::receiveMessage()
{
- SharedHandle<LpdMessage> msg;
+ std::shared_ptr<LpdMessage> msg;
while(1) {
unsigned char buf[200];
std::pair<std::string, uint16_t> peerAddr;
@@ -103,7 +103,7 @@ SharedHandle<LpdMessage> LpdMessageReceiver::receiveMessage()
A2_LOG_INFO_EX("Failed to parse LPD message.", e);
continue;
}
- const SharedHandle<HttpHeader>& header = proc.getResult();
+ const std::shared_ptr<HttpHeader>& header = proc.getResult();
const std::string& infoHashString = header->find(HttpHeader::INFOHASH);
uint32_t port = 0;
if(!util::parseUIntNoThrow(port, header->find(HttpHeader::PORT)) ||
@@ -123,7 +123,7 @@ SharedHandle<LpdMessage> LpdMessageReceiver::receiveMessage()
infoHashString.c_str()));
continue;
}
- SharedHandle<Peer> peer(new Peer(peerAddr.first, port, false));
+ std::shared_ptr<Peer> peer(new Peer(peerAddr.first, port, false));
if(util::inPrivateAddress(peerAddr.first)) {
peer->setLocalPeer(true);
}
diff --git a/src/LpdMessageReceiver.h b/src/LpdMessageReceiver.h
index c3061fd8..40369508 100644
--- a/src/LpdMessageReceiver.h
+++ b/src/LpdMessageReceiver.h
@@ -36,8 +36,7 @@
#include "common.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -46,7 +45,7 @@ struct LpdMessage;
class LpdMessageReceiver {
private:
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<SocketCore> socket_;
std::string multicastAddress_;
uint16_t multicastPort_;
std::string localAddress_;
@@ -62,11 +61,11 @@ public:
// Receives LPD message and returns LpdMessage which contains
// sender(peer) and infohash. If no data is available on socket,
- // returns SharedHandle<LpdMessage>(). If received data is bad,
- // then returns SharedHandle<LpdMessage>(new LpdMessage())
- SharedHandle<LpdMessage> receiveMessage();
+ // returns std::shared_ptr<LpdMessage>(). If received data is bad,
+ // then returns std::shared_ptr<LpdMessage>(new LpdMessage())
+ std::shared_ptr<LpdMessage> receiveMessage();
- const SharedHandle<SocketCore>& getSocket() const
+ const std::shared_ptr<SocketCore>& getSocket() const
{
return socket_;
}
diff --git a/src/LpdReceiveMessageCommand.cc b/src/LpdReceiveMessageCommand.cc
index 81ad11cc..65641715 100644
--- a/src/LpdReceiveMessageCommand.cc
+++ b/src/LpdReceiveMessageCommand.cc
@@ -53,7 +53,7 @@ namespace aria2 {
LpdReceiveMessageCommand::LpdReceiveMessageCommand
(cuid_t cuid,
- const SharedHandle<LpdMessageReceiver>& receiver,
+ const std::shared_ptr<LpdMessageReceiver>& receiver,
DownloadEngine* e)
: Command(cuid),
receiver_(receiver),
@@ -73,12 +73,12 @@ bool LpdReceiveMessageCommand::execute()
return true;
}
for(size_t i = 0; i < 20; ++i) {
- SharedHandle<LpdMessage> m = receiver_->receiveMessage();
+ std::shared_ptr<LpdMessage> m = receiver_->receiveMessage();
if(!m) {
break;
}
- SharedHandle<BtRegistry> reg = e_->getBtRegistry();
- SharedHandle<DownloadContext> dctx = reg->getDownloadContext(m->infoHash);
+ std::shared_ptr<BtRegistry> reg = e_->getBtRegistry();
+ std::shared_ptr<DownloadContext> dctx = reg->getDownloadContext(m->infoHash);
if(!dctx) {
A2_LOG_DEBUG(fmt("Download Context is null for infohash=%s.",
util::toHex(m->infoHash).c_str()));
@@ -90,11 +90,11 @@ bool LpdReceiveMessageCommand::execute()
}
RequestGroup* group = dctx->getOwnerRequestGroup();
assert(group);
- const SharedHandle<BtObject>& btobj = reg->get(group->getGID());
+ const std::shared_ptr<BtObject>& btobj = reg->get(group->getGID());
assert(btobj);
- const SharedHandle<PeerStorage>& peerStorage = btobj->peerStorage;
+ const std::shared_ptr<PeerStorage>& peerStorage = btobj->peerStorage;
assert(peerStorage);
- SharedHandle<Peer> peer = m->peer;
+ std::shared_ptr<Peer> peer = m->peer;
if(peerStorage->addPeer(peer)) {
A2_LOG_DEBUG(fmt("LPD peer %s:%u local=%d added.",
peer->getIPAddress().c_str(), peer->getPort(),
diff --git a/src/LpdReceiveMessageCommand.h b/src/LpdReceiveMessageCommand.h
index dea604a2..09f3fe60 100644
--- a/src/LpdReceiveMessageCommand.h
+++ b/src/LpdReceiveMessageCommand.h
@@ -36,7 +36,8 @@
#define D_LPD_RECEIVE_MESSAGE_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -46,17 +47,17 @@ class SocketCore;
class LpdReceiveMessageCommand:public Command {
private:
- SharedHandle<LpdMessageReceiver> receiver_;
+ std::shared_ptr<LpdMessageReceiver> receiver_;
DownloadEngine* e_;
public:
LpdReceiveMessageCommand
- (cuid_t cuid, const SharedHandle<LpdMessageReceiver>& receiver,
+ (cuid_t cuid, const std::shared_ptr<LpdMessageReceiver>& receiver,
DownloadEngine* e);
virtual ~LpdReceiveMessageCommand();
virtual bool execute();
- const SharedHandle<LpdMessageReceiver>& getLpdMessageReceiver() const
+ const std::shared_ptr<LpdMessageReceiver>& getLpdMessageReceiver() const
{
return receiver_;
}
diff --git a/src/MSEHandshake.cc b/src/MSEHandshake.cc
index 6e34ae30..b78a8b2e 100644
--- a/src/MSEHandshake.cc
+++ b/src/MSEHandshake.cc
@@ -72,7 +72,7 @@ const unsigned char* GENERATOR = reinterpret_cast<const unsigned char*>("2");
MSEHandshake::MSEHandshake
(cuid_t cuid,
- const SharedHandle<SocketCore>& socket,
+ const std::shared_ptr<SocketCore>& socket,
const Option* op)
: cuid_(cuid),
socket_(socket),
@@ -422,7 +422,7 @@ bool MSEHandshake::findReceiverHashMarker()
}
bool MSEHandshake::receiveReceiverHashAndPadCLength
-(const std::vector<SharedHandle<DownloadContext> >& downloadContexts)
+(const std::vector<std::shared_ptr<DownloadContext> >& downloadContexts)
{
if(20+VC_LENGTH+CRYPTO_BITFIELD_LENGTH+2/*PadC length*/ > rbufLength_) {
wantRead_ = true;
@@ -431,8 +431,8 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
// resolve info hash
// pointing to the position of HASH('req2', SKEY) xor HASH('req3', S)
unsigned char* rbufptr = rbuf_;
- SharedHandle<DownloadContext> downloadContext;
- for(std::vector<SharedHandle<DownloadContext> >::const_iterator i =
+ std::shared_ptr<DownloadContext> downloadContext;
+ for(std::vector<std::shared_ptr<DownloadContext> >::const_iterator i =
downloadContexts.begin(), eoi = downloadContexts.end();
i != eoi; ++i) {
unsigned char md[20];
diff --git a/src/MSEHandshake.h b/src/MSEHandshake.h
index be29e29f..68b00ef1 100644
--- a/src/MSEHandshake.h
+++ b/src/MSEHandshake.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "BtConstants.h"
#include "SocketBuffer.h"
#include "Command.h"
@@ -77,7 +77,7 @@ private:
static const size_t MAX_BUFFER_LENGTH = 636U;
cuid_t cuid_;
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<SocketCore> socket_;
bool wantRead_;
const Option* option_;
@@ -88,8 +88,8 @@ private:
CRYPTO_TYPE negotiatedCryptoType_;
DHKeyExchange* dh_;
- SharedHandle<ARC4Encryptor> encryptor_;
- SharedHandle<ARC4Encryptor> decryptor_;
+ std::shared_ptr<ARC4Encryptor> encryptor_;
+ std::shared_ptr<ARC4Encryptor> decryptor_;
unsigned char infoHash_[INFO_HASH_LENGTH];
unsigned char secret_[KEY_LENGTH];
bool initiator_;
@@ -98,7 +98,7 @@ private:
uint16_t padLength_;
uint16_t iaLength_;
unsigned char* ia_;
- SharedHandle<MessageDigest> sha1_;
+ std::shared_ptr<MessageDigest> sha1_;
void encryptAndSendData(unsigned char* data, size_t length);
@@ -122,7 +122,7 @@ private:
void shiftBuffer(size_t offset);
public:
- MSEHandshake(cuid_t cuid, const SharedHandle<SocketCore>& socket,
+ MSEHandshake(cuid_t cuid, const std::shared_ptr<SocketCore>& socket,
const Option* op);
~MSEHandshake();
@@ -168,7 +168,7 @@ public:
bool findReceiverHashMarker();
bool receiveReceiverHashAndPadCLength
- (const std::vector<SharedHandle<DownloadContext> >& downloadContexts);
+ (const std::vector<std::shared_ptr<DownloadContext> >& downloadContexts);
bool receiveReceiverIALength();
@@ -197,12 +197,12 @@ public:
return negotiatedCryptoType_;
}
- const SharedHandle<ARC4Encryptor>& getEncryptor() const
+ const std::shared_ptr<ARC4Encryptor>& getEncryptor() const
{
return encryptor_;
}
- const SharedHandle<ARC4Encryptor>& getDecryptor() const
+ const std::shared_ptr<ARC4Encryptor>& getDecryptor() const
{
return decryptor_;
}
diff --git a/src/Makefile.am b/src/Makefile.am
index c97b5b8e..c89aa097 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -54,7 +54,6 @@ SRCS = option_processing.cc\
LogFactory.cc LogFactory.h\
TimerA2.cc TimerA2.h\
TimeA2.cc TimeA2.h\
- SharedHandle.cc SharedHandle.h\
FeatureConfig.cc FeatureConfig.h\
DownloadEngineFactory.cc DownloadEngineFactory.h\
SpeedCalc.cc SpeedCalc.h\
diff --git a/src/MemoryPreDownloadHandler.h b/src/MemoryPreDownloadHandler.h
index c3fc8ca3..3c348982 100644
--- a/src/MemoryPreDownloadHandler.h
+++ b/src/MemoryPreDownloadHandler.h
@@ -50,7 +50,7 @@ public:
virtual void execute(RequestGroup* requestGroup)
{
- SharedHandle<DiskWriterFactory> dwf(new DiskWriterFactoryType());
+ std::shared_ptr<DiskWriterFactory> dwf(new DiskWriterFactoryType());
requestGroup->setDiskWriterFactory(dwf);
requestGroup->setFileAllocationEnabled(false);
requestGroup->setPreLocalFileCheckEnabled(false);
diff --git a/src/MessageDigest.cc b/src/MessageDigest.cc
index e0dc1644..1acb0b8b 100644
--- a/src/MessageDigest.cc
+++ b/src/MessageDigest.cc
@@ -69,16 +69,16 @@ MessageDigest::MessageDigest()
MessageDigest::~MessageDigest()
{}
-SharedHandle<MessageDigest> MessageDigest::sha1()
+std::shared_ptr<MessageDigest> MessageDigest::sha1()
{
- SharedHandle<MessageDigest> md(new MessageDigest());
+ std::shared_ptr<MessageDigest> md(new MessageDigest());
md->pImpl_ = MessageDigestImpl::sha1();
return md;
}
-SharedHandle<MessageDigest> MessageDigest::create(const std::string& hashType)
+std::shared_ptr<MessageDigest> MessageDigest::create(const std::string& hashType)
{
- SharedHandle<MessageDigest> md(new MessageDigest());
+ std::shared_ptr<MessageDigest> md(new MessageDigest());
md->pImpl_ = MessageDigestImpl::create(hashType);
return md;
}
diff --git a/src/MessageDigest.h b/src/MessageDigest.h
index f5e6ca55..d9c619b8 100644
--- a/src/MessageDigest.h
+++ b/src/MessageDigest.h
@@ -39,8 +39,7 @@
#include <string>
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -48,7 +47,7 @@ class MessageDigestImpl;
class MessageDigest {
private:
- SharedHandle<MessageDigestImpl> pImpl_;
+ std::shared_ptr<MessageDigestImpl> pImpl_;
MessageDigest();
@@ -60,11 +59,11 @@ public:
~MessageDigest();
// Factory functions
- static SharedHandle<MessageDigest> sha1();
+ static std::shared_ptr<MessageDigest> sha1();
// Factory function which takes hashType as string. Throws
// exception if hashType is not supported.
- static SharedHandle<MessageDigest> create(const std::string& hashType);
+ static std::shared_ptr<MessageDigest> create(const std::string& hashType);
// Returns true if hashType is supported. Otherwise returns false.
static bool supports(const std::string& hashType);
diff --git a/src/MetadataInfo.cc b/src/MetadataInfo.cc
index df3077a1..fd279961 100644
--- a/src/MetadataInfo.cc
+++ b/src/MetadataInfo.cc
@@ -34,9 +34,11 @@
/* copyright --> */
#include "MetadataInfo.h"
+#include <cassert>
+
namespace aria2 {
-MetadataInfo::MetadataInfo(const SharedHandle<GroupId>& gid,
+MetadataInfo::MetadataInfo(const std::shared_ptr<GroupId>& gid,
const std::string& uri)
: gid_(gid), uri_(uri)
{}
@@ -45,4 +47,10 @@ MetadataInfo::MetadataInfo() {}
MetadataInfo::~MetadataInfo() {}
+a2_gid_t MetadataInfo::getGID() const
+{
+ assert(gid_);
+ return gid_->getNumericId();
+}
+
} // namespace aria2
diff --git a/src/MetadataInfo.h b/src/MetadataInfo.h
index 7a5ac7f9..7e9b1cd9 100644
--- a/src/MetadataInfo.h
+++ b/src/MetadataInfo.h
@@ -38,18 +38,18 @@
#include "common.h"
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "GroupId.h"
namespace aria2 {
class MetadataInfo {
private:
- SharedHandle<GroupId> gid_;
+ std::shared_ptr<GroupId> gid_;
std::string uri_;
public:
- MetadataInfo(const SharedHandle<GroupId>& gid, const std::string& uri);
+ MetadataInfo(const std::shared_ptr<GroupId>& gid, const std::string& uri);
MetadataInfo();
@@ -65,11 +65,7 @@ public:
return uri_;
}
- a2_gid_t getGID() const
- {
- assert(gid_);
- return gid_->getNumericId();
- }
+ a2_gid_t getGID() const;
};
} // namespace aria2
diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc
index d849e52c..696f7c85 100644
--- a/src/Metalink2RequestGroup.cc
+++ b/src/Metalink2RequestGroup.cc
@@ -79,7 +79,7 @@ public:
AccumulateNonP2PUri(std::vector<std::string>& urisPtr)
:urisPtr(urisPtr) {}
- void operator()(const SharedHandle<MetalinkResource>& resource) {
+ void operator()(const std::shared_ptr<MetalinkResource>& resource) {
switch(resource->type) {
case MetalinkResource::TYPE_HTTP:
case MetalinkResource::TYPE_HTTPS:
@@ -98,7 +98,7 @@ class FindBitTorrentUri {
public:
FindBitTorrentUri() {}
- bool operator()(const SharedHandle<MetalinkResource>& resource) {
+ bool operator()(const std::shared_ptr<MetalinkResource>& resource) {
if(resource->type == MetalinkResource::TYPE_BITTORRENT) {
return true;
} else {
@@ -110,16 +110,16 @@ public:
void
Metalink2RequestGroup::generate
-(std::vector<SharedHandle<RequestGroup> >& groups,
+(std::vector<std::shared_ptr<RequestGroup> >& groups,
const std::string& metalinkFile,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<Option>& option,
const std::string& baseUri)
{
- std::vector<SharedHandle<MetalinkEntry> > entries;
+ std::vector<std::shared_ptr<MetalinkEntry> > entries;
metalink::parseAndQuery(entries, metalinkFile, option.get(), baseUri);
- std::vector<SharedHandle<RequestGroup> > tempgroups;
+ std::vector<std::shared_ptr<RequestGroup> > tempgroups;
createRequestGroup(tempgroups, entries, option);
- SharedHandle<MetadataInfo> mi;
+ std::shared_ptr<MetadataInfo> mi;
if(metalinkFile == DEV_STDIN) {
mi.reset(new MetadataInfo());
} else {
@@ -133,25 +133,25 @@ Metalink2RequestGroup::generate
void
Metalink2RequestGroup::generate
-(std::vector<SharedHandle<RequestGroup> >& groups,
- const SharedHandle<BinaryStream>& binaryStream,
- const SharedHandle<Option>& option,
+(std::vector<std::shared_ptr<RequestGroup> >& groups,
+ const std::shared_ptr<BinaryStream>& binaryStream,
+ const std::shared_ptr<Option>& option,
const std::string& baseUri)
{
- std::vector<SharedHandle<MetalinkEntry> > entries;
+ std::vector<std::shared_ptr<MetalinkEntry> > entries;
metalink::parseAndQuery(entries, binaryStream.get(), option.get(), baseUri);
- std::vector<SharedHandle<RequestGroup> > tempgroups;
+ std::vector<std::shared_ptr<RequestGroup> > tempgroups;
createRequestGroup(tempgroups, entries, option);
- SharedHandle<MetadataInfo> mi(new MetadataInfo());
+ std::shared_ptr<MetadataInfo> mi(new MetadataInfo());
setMetadataInfo(tempgroups.begin(), tempgroups.end(), mi);
groups.insert(groups.end(), tempgroups.begin(), tempgroups.end());
}
void
Metalink2RequestGroup::createRequestGroup
-(std::vector<SharedHandle<RequestGroup> >& groups,
- const std::vector<SharedHandle<MetalinkEntry> >& entries,
- const SharedHandle<Option>& optionTemplate)
+(std::vector<std::shared_ptr<RequestGroup> >& groups,
+ const std::vector<std::shared_ptr<MetalinkEntry> >& entries,
+ const std::shared_ptr<Option>& optionTemplate)
{
if(entries.empty()) {
A2_LOG_NOTICE(EX_NO_RESULT_WITH_YOUR_PREFS);
@@ -171,7 +171,7 @@ Metalink2RequestGroup::createRequestGroup
if(optionTemplate->get(PREF_METALINK_PREFERRED_PROTOCOL) != V_NONE) {
preferredProtocol = optionTemplate->get(PREF_METALINK_PREFERRED_PROTOCOL);
}
- for(std::vector<SharedHandle<MetalinkEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<MetalinkEntry> >::const_iterator i =
entries.begin(), eoi = entries.end(); i != eoi; ++i) {
(*i)->dropUnsupportedResource();
if((*i)->resources.empty() && (*i)->metaurls.empty()) {
@@ -184,7 +184,7 @@ Metalink2RequestGroup::createRequestGroup
(preferredProtocol, -MetalinkResource::getLowestPriority());
}
}
- std::vector<SharedHandle<MetalinkEntry> > selectedEntries;
+ std::vector<std::shared_ptr<MetalinkEntry> > selectedEntries;
SegList<int> sgl;
util::parseIntSegments(sgl, optionTemplate->get(PREF_SELECT_FILE));
sgl.normalize();
@@ -203,21 +203,21 @@ Metalink2RequestGroup::createRequestGroup
std::for_each(selectedEntries.begin(), selectedEntries.end(),
mem_fun_sh(&MetalinkEntry::reorderMetaurlsByPriority));
std::vector<std::pair<std::string,
- std::vector<SharedHandle<MetalinkEntry> > > > entryGroups;
+ std::vector<std::shared_ptr<MetalinkEntry> > > > entryGroups;
metalink::groupEntryByMetaurlName(entryGroups, selectedEntries);
for(std::vector<std::pair<std::string,
- std::vector<SharedHandle<MetalinkEntry> > > >::const_iterator itr =
+ std::vector<std::shared_ptr<MetalinkEntry> > > >::const_iterator itr =
entryGroups.begin(), eoi = entryGroups.end(); itr != eoi; ++itr) {
const std::string& metaurl = (*itr).first;
- const std::vector<SharedHandle<MetalinkEntry> >& mes = (*itr).second;
+ const std::vector<std::shared_ptr<MetalinkEntry> >& mes = (*itr).second;
A2_LOG_INFO(fmt("Processing metaurl group metaurl=%s", metaurl.c_str()));
#ifdef ENABLE_BITTORRENT
- SharedHandle<RequestGroup> torrentRg;
+ std::shared_ptr<RequestGroup> torrentRg;
if(!metaurl.empty()) {
std::vector<std::string> uris;
uris.push_back(metaurl);
{
- std::vector<SharedHandle<RequestGroup> > result;
+ std::vector<std::shared_ptr<RequestGroup> > result;
createRequestGroupForUri(result, optionTemplate, uris,
/* ignoreForceSequential = */true,
/* ignoreLocalPath = */true);
@@ -233,22 +233,22 @@ Metalink2RequestGroup::createRequestGroup
// tranparent metalink
torrentRg->getDownloadContext()->setAcceptMetalink(false);
// make it in-memory download
- SharedHandle<PreDownloadHandler> preh
+ std::shared_ptr<PreDownloadHandler> preh
(new MemoryBufferPreDownloadHandler());
- SharedHandle<RequestGroupCriteria> cri(new TrueRequestGroupCriteria());
+ std::shared_ptr<RequestGroupCriteria> cri(new TrueRequestGroupCriteria());
preh->setCriteria(cri);
torrentRg->addPreDownloadHandler(preh);
groups.push_back(torrentRg);
}
}
#endif // ENABLE_BITTORRENT
- SharedHandle<Option> option = util::copy(optionTemplate);
- SharedHandle<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
- SharedHandle<DownloadContext> dctx;
+ std::shared_ptr<Option> option = util::copy(optionTemplate);
+ std::shared_ptr<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
+ std::shared_ptr<DownloadContext> dctx;
int numSplit = option->getAsInt(PREF_SPLIT);
int maxConn = option->getAsInt(PREF_MAX_CONNECTION_PER_SERVER);
if(mes.size() == 1) {
- SharedHandle<MetalinkEntry> entry = mes[0];
+ std::shared_ptr<MetalinkEntry> entry = mes[0];
A2_LOG_INFO(fmt(MSG_METALINK_QUEUEING, entry->getPath().c_str()));
entry->reorderResourcesByPriority();
std::vector<std::string> uris;
@@ -295,9 +295,9 @@ Metalink2RequestGroup::createRequestGroup
dctx.reset(new DownloadContext());
// piece length is overridden by the one in torrent file.
dctx->setPieceLength(option->getAsInt(PREF_PIECE_LENGTH));
- std::vector<SharedHandle<FileEntry> > fileEntries;
+ std::vector<std::shared_ptr<FileEntry> > fileEntries;
int64_t offset = 0;
- for(std::vector<SharedHandle<MetalinkEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<MetalinkEntry> >::const_iterator i =
mes.begin(), eoi = mes.end(); i != eoi; ++i) {
A2_LOG_INFO(fmt("Metalink: Queueing %s for download as a member.",
(*i)->getPath().c_str()));
@@ -306,7 +306,7 @@ Metalink2RequestGroup::createRequestGroup
std::vector<std::string> uris;
std::for_each((*i)->resources.begin(), (*i)->resources.end(),
AccumulateNonP2PUri(uris));
- SharedHandle<FileEntry> fe
+ std::shared_ptr<FileEntry> fe
(new FileEntry
(util::applyDir(option->get(PREF_DIR), (*i)->file->getPath()),
(*i)->file->getLength(), offset, uris));
@@ -335,7 +335,7 @@ Metalink2RequestGroup::createRequestGroup
// Inject depenency between rg and torrentRg here if
// torrentRg is true
if(torrentRg) {
- SharedHandle<Dependency> dep(new BtDependency(rg.get(), torrentRg));
+ std::shared_ptr<Dependency> dep(new BtDependency(rg.get(), torrentRg));
rg->dependsOn(dep);
torrentRg->belongsTo(rg->getGID());
// metadata download may take very long time. If URIs are
@@ -344,8 +344,8 @@ Metalink2RequestGroup::createRequestGroup
time_t currentBtStopTimeout =
torrentRg->getOption()->getAsInt(PREF_BT_STOP_TIMEOUT);
if(currentBtStopTimeout == 0 || currentBtStopTimeout > btStopTimeout) {
- std::vector<SharedHandle<FileEntry> >::const_iterator i;
- std::vector<SharedHandle<FileEntry> >::const_iterator eoi
+ std::vector<std::shared_ptr<FileEntry> >::const_iterator i;
+ std::vector<std::shared_ptr<FileEntry> >::const_iterator eoi
= dctx->getFileEntries().end();
for(i = dctx->getFileEntries().begin(); i != eoi; ++i) {
if((*i)->getRemainingUris().empty()) {
diff --git a/src/Metalink2RequestGroup.h b/src/Metalink2RequestGroup.h
index c8d60c4b..9b2574ac 100644
--- a/src/Metalink2RequestGroup.h
+++ b/src/Metalink2RequestGroup.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <string>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "A2STR.h"
namespace aria2 {
@@ -52,20 +52,20 @@ class MetalinkEntry;
class Metalink2RequestGroup {
private:
void
- createRequestGroup(std::vector<SharedHandle<RequestGroup> >& groups,
- const std::vector<SharedHandle<MetalinkEntry> >& entries,
- const SharedHandle<Option>& option);
+ createRequestGroup(std::vector<std::shared_ptr<RequestGroup> >& groups,
+ const std::vector<std::shared_ptr<MetalinkEntry> >& entries,
+ const std::shared_ptr<Option>& option);
public:
Metalink2RequestGroup();
- void generate(std::vector<SharedHandle<RequestGroup> >& groups,
+ void generate(std::vector<std::shared_ptr<RequestGroup> >& groups,
const std::string& metalinkFile,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<Option>& option,
const std::string& baseUri = A2STR::NIL);
- void generate(std::vector<SharedHandle<RequestGroup> >& groups,
- const SharedHandle<BinaryStream>& binaryStream,
- const SharedHandle<Option>& option,
+ void generate(std::vector<std::shared_ptr<RequestGroup> >& groups,
+ const std::shared_ptr<BinaryStream>& binaryStream,
+ const std::shared_ptr<Option>& option,
const std::string& baseUri = A2STR::NIL);
};
diff --git a/src/MetalinkEntry.cc b/src/MetalinkEntry.cc
index ee1008a4..e41b5d44 100644
--- a/src/MetalinkEntry.cc
+++ b/src/MetalinkEntry.cc
@@ -70,7 +70,7 @@ public:
std::sort(locations_.begin(), locations_.end());
}
- void operator()(SharedHandle<MetalinkResource>& res) {
+ void operator()(std::shared_ptr<MetalinkResource>& res) {
if(std::binary_search
(locations_.begin(), locations_.end(), res->location)) {
res->priority += priorityToAdd_;
@@ -122,7 +122,7 @@ public:
AddProtocolPriority(const std::string& protocol, int prefToAdd):
protocol_(protocol), priorityToAdd_(prefToAdd) {}
- void operator()(const SharedHandle<MetalinkResource>& res) const
+ void operator()(const std::shared_ptr<MetalinkResource>& res) const
{
if(protocol_ == MetalinkResource::getTypeString(res->type)) {
res->priority += priorityToAdd_;
@@ -142,8 +142,8 @@ namespace {
template<typename T>
class PriorityHigher {
public:
- bool operator()(const SharedHandle<T>& res1,
- const SharedHandle<T>& res2)
+ bool operator()(const std::shared_ptr<T>& res1,
+ const std::shared_ptr<T>& res2)
{
return res1->priority < res2->priority;
}
@@ -163,9 +163,9 @@ void MetalinkEntry::reorderMetaurlsByPriority()
}
namespace {
-class Supported:public std::unary_function<SharedHandle<MetalinkResource>, bool> {
+class Supported:public std::unary_function<std::shared_ptr<MetalinkResource>, bool> {
public:
- bool operator()(const SharedHandle<MetalinkResource>& res) const
+ bool operator()(const std::shared_ptr<MetalinkResource>& res) const
{
switch(res->type) {
case MetalinkResource::TYPE_FTP:
@@ -191,15 +191,15 @@ void MetalinkEntry::dropUnsupportedResource() {
}
void MetalinkEntry::toFileEntry
-(std::vector<SharedHandle<FileEntry> >& fileEntries,
- const std::vector<SharedHandle<MetalinkEntry> >& metalinkEntries)
+(std::vector<std::shared_ptr<FileEntry> >& fileEntries,
+ const std::vector<std::shared_ptr<MetalinkEntry> >& metalinkEntries)
{
std::transform(metalinkEntries.begin(), metalinkEntries.end(),
std::back_inserter(fileEntries),
mem_fun_sh(&MetalinkEntry::getFile));
}
-void MetalinkEntry::setSignature(const SharedHandle<Signature>& signature)
+void MetalinkEntry::setSignature(const std::shared_ptr<Signature>& signature)
{
signature_ = signature;
}
diff --git a/src/MetalinkEntry.h b/src/MetalinkEntry.h
index fa15aaac..475efe0d 100644
--- a/src/MetalinkEntry.h
+++ b/src/MetalinkEntry.h
@@ -39,8 +39,7 @@
#include <string>
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -55,21 +54,21 @@ class Signature;
class MetalinkEntry {
public:
- SharedHandle<FileEntry> file;
+ std::shared_ptr<FileEntry> file;
std::string version;
std::vector<std::string> languages;
std::vector<std::string> oses;
// True if size is specified in Metalink document.
bool sizeKnown;
- std::vector<SharedHandle<MetalinkResource> > resources;
- std::vector<SharedHandle<MetalinkMetaurl> > metaurls;
+ std::vector<std::shared_ptr<MetalinkResource> > resources;
+ std::vector<std::shared_ptr<MetalinkMetaurl> > metaurls;
int maxConnections; // Metalink3Spec
#ifdef ENABLE_MESSAGE_DIGEST
- SharedHandle<Checksum> checksum;
- SharedHandle<ChunkChecksum> chunkChecksum;
+ std::shared_ptr<Checksum> checksum;
+ std::shared_ptr<ChunkChecksum> chunkChecksum;
#endif // ENABLE_MESSAGE_DIGEST
private:
- SharedHandle<Signature> signature_;
+ std::shared_ptr<Signature> signature_;
public:
MetalinkEntry();
@@ -81,7 +80,7 @@ public:
int64_t getLength() const;
- const SharedHandle<FileEntry>& getFile() const
+ const std::shared_ptr<FileEntry>& getFile() const
{
return file;
}
@@ -102,12 +101,12 @@ public:
void setProtocolPriority(const std::string& protocol, int priorityToAdd);
static void toFileEntry
- (std::vector<SharedHandle<FileEntry> >& fileEntries,
- const std::vector<SharedHandle<MetalinkEntry> >& metalinkEntries);
+ (std::vector<std::shared_ptr<FileEntry> >& fileEntries,
+ const std::vector<std::shared_ptr<MetalinkEntry> >& metalinkEntries);
- void setSignature(const SharedHandle<Signature>& signature);
+ void setSignature(const std::shared_ptr<Signature>& signature);
- const SharedHandle<Signature>& getSignature() const
+ const std::shared_ptr<Signature>& getSignature() const
{
return signature_;
}
diff --git a/src/MetalinkParserController.cc b/src/MetalinkParserController.cc
index 762aa81d..187e6cc1 100644
--- a/src/MetalinkParserController.cc
+++ b/src/MetalinkParserController.cc
@@ -237,7 +237,7 @@ void MetalinkParserController::commitResourceTransaction()
}
#ifdef ENABLE_BITTORRENT
if(tResource_->type == MetalinkResource::TYPE_BITTORRENT) {
- SharedHandle<MetalinkMetaurl> metaurl(new MetalinkMetaurl());
+ std::shared_ptr<MetalinkMetaurl> metaurl(new MetalinkMetaurl());
metaurl->url = tResource_->url;
metaurl->priority = tResource_->priority;
metaurl->mediatype = MetalinkMetaurl::MEDIATYPE_TORRENT;
diff --git a/src/MetalinkParserController.h b/src/MetalinkParserController.h
index e640a71e..c3bd537a 100644
--- a/src/MetalinkParserController.h
+++ b/src/MetalinkParserController.h
@@ -40,8 +40,7 @@
#include <string>
#include <utility>
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -58,21 +57,21 @@ class ChunkChecksum;
class MetalinkParserController {
private:
- SharedHandle<Metalinker> metalinker_;
+ std::shared_ptr<Metalinker> metalinker_;
- SharedHandle<MetalinkEntry> tEntry_;
+ std::shared_ptr<MetalinkEntry> tEntry_;
- SharedHandle<MetalinkResource> tResource_;
+ std::shared_ptr<MetalinkResource> tResource_;
- SharedHandle<MetalinkMetaurl> tMetaurl_;
+ std::shared_ptr<MetalinkMetaurl> tMetaurl_;
#ifdef ENABLE_MESSAGE_DIGEST
- SharedHandle<Checksum> tChecksum_;
+ std::shared_ptr<Checksum> tChecksum_;
- SharedHandle<ChunkChecksum> tChunkChecksumV4_; // Metalink4Spec
+ std::shared_ptr<ChunkChecksum> tChunkChecksumV4_; // Metalink4Spec
std::vector<std::string> tempChunkChecksumsV4_; // Metalink4Spec
- SharedHandle<ChunkChecksum> tChunkChecksum_; // Metalink3Spec
+ std::shared_ptr<ChunkChecksum> tChunkChecksum_; // Metalink3Spec
std::vector<std::pair<size_t, std::string> > tempChunkChecksums_;//Metalink3Spec
@@ -80,7 +79,7 @@ private:
#endif // ENABLE_MESSAGE_DIGEST
- SharedHandle<Signature> tSignature_;
+ std::shared_ptr<Signature> tSignature_;
std::string baseUri_;
public:
MetalinkParserController();
@@ -89,7 +88,7 @@ public:
void reset();
- const SharedHandle<Metalinker>& getResult() const
+ const std::shared_ptr<Metalinker>& getResult() const
{
return metalinker_;
}
diff --git a/src/MetalinkParserStateImpl.cc b/src/MetalinkParserStateImpl.cc
index b61d8f57..bcc76029 100644
--- a/src/MetalinkParserStateImpl.cc
+++ b/src/MetalinkParserStateImpl.cc
@@ -35,6 +35,7 @@
#include "MetalinkParserStateImpl.h"
#include <cstring>
+#include <algorithm>
#include "MetalinkParserStateV3Impl.h"
#include "MetalinkParserStateV4Impl.h"
diff --git a/src/MetalinkParserStateMachine.h b/src/MetalinkParserStateMachine.h
index 8beed5ea..0414a4ac 100644
--- a/src/MetalinkParserStateMachine.h
+++ b/src/MetalinkParserStateMachine.h
@@ -40,8 +40,8 @@
#include <string>
#include <vector>
#include <stack>
+#include <memory>
-#include "SharedHandle.h"
#include "MetalinkParserController.h"
#include "MetalinkParserState.h"
@@ -51,7 +51,7 @@ class Metalinker;
class MetalinkParserStateMachine : public ParserStateMachine {
private:
- SharedHandle<MetalinkParserController> ctrl_;
+ std::shared_ptr<MetalinkParserController> ctrl_;
std::stack<MetalinkParserState*> stateStack_;
@@ -265,7 +265,7 @@ public:
std::string getErrorString() const;
- const SharedHandle<Metalinker>& getResult() const
+ const std::shared_ptr<Metalinker>& getResult() const
{
return ctrl_->getResult();
}
diff --git a/src/MetalinkPostDownloadHandler.cc b/src/MetalinkPostDownloadHandler.cc
index 44f794cf..fbd47030 100644
--- a/src/MetalinkPostDownloadHandler.cc
+++ b/src/MetalinkPostDownloadHandler.cc
@@ -56,7 +56,7 @@ namespace aria2 {
MetalinkPostDownloadHandler::MetalinkPostDownloadHandler()
{
- SharedHandle<RequestGroupCriteria> cri
+ std::shared_ptr<RequestGroupCriteria> cri
(new ContentTypeRequestGroupCriteria
(getMetalinkContentTypes(), getMetalinkExtensions()));
setCriteria(cri);
@@ -67,13 +67,13 @@ MetalinkPostDownloadHandler::~MetalinkPostDownloadHandler() {}
namespace {
const std::string& getBaseUri(RequestGroup* requestGroup)
{
- const SharedHandle<DownloadContext>& dctx =
+ const std::shared_ptr<DownloadContext>& dctx =
requestGroup->getDownloadContext();
if(dctx->getFileEntries().empty()) {
return A2STR::NIL;
} else {
// TODO Check download result for each URI
- const SharedHandle<FileEntry>& entry = dctx->getFirstFileEntry();
+ const std::shared_ptr<FileEntry>& entry = dctx->getFirstFileEntry();
const std::deque<std::string>& spentUris = entry->getSpentUris();
if(spentUris.empty()) {
const std::deque<std::string>& remainingUris = entry->getRemainingUris();
@@ -90,22 +90,22 @@ const std::string& getBaseUri(RequestGroup* requestGroup)
} // namespace
void MetalinkPostDownloadHandler::getNextRequestGroups
-(std::vector<SharedHandle<RequestGroup> >& groups,
+(std::vector<std::shared_ptr<RequestGroup> >& groups,
RequestGroup* requestGroup)
{
A2_LOG_DEBUG(fmt("Generating RequestGroups for Metalink file %s",
requestGroup->getFirstFilePath().c_str()));
- SharedHandle<DiskAdaptor> diskAdaptor =
+ std::shared_ptr<DiskAdaptor> diskAdaptor =
requestGroup->getPieceStorage()->getDiskAdaptor();
try {
diskAdaptor->openExistingFile();
//requestOption.put(PREF_DIR, requestGroup->getDownloadContext()->getDir());
const std::string& baseUri = getBaseUri(requestGroup);
- std::vector<SharedHandle<RequestGroup> > newRgs;
+ std::vector<std::shared_ptr<RequestGroup> > newRgs;
Metalink2RequestGroup().generate(newRgs, diskAdaptor,
requestGroup->getOption(), baseUri);
requestGroup->followedBy(newRgs.begin(), newRgs.end());
- SharedHandle<MetadataInfo> mi =
+ std::shared_ptr<MetadataInfo> mi =
createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(),
requestGroup->getDownloadContext());
if(mi) {
diff --git a/src/MetalinkPostDownloadHandler.h b/src/MetalinkPostDownloadHandler.h
index bdb89e54..1f975ea7 100644
--- a/src/MetalinkPostDownloadHandler.h
+++ b/src/MetalinkPostDownloadHandler.h
@@ -47,7 +47,7 @@ public:
virtual ~MetalinkPostDownloadHandler();
virtual void
- getNextRequestGroups(std::vector<SharedHandle<RequestGroup> >& groups,
+ getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
RequestGroup* requestGroup);
};
diff --git a/src/Metalinker.cc b/src/Metalinker.cc
index 435c81e5..70e8fcfa 100644
--- a/src/Metalinker.cc
+++ b/src/Metalinker.cc
@@ -45,7 +45,7 @@ Metalinker::~Metalinker() {}
namespace {
class EntryQuery:
- public std::unary_function<SharedHandle<MetalinkEntry>, bool> {
+ public std::unary_function<std::shared_ptr<MetalinkEntry>, bool> {
private:
std::string version;
std::string language;
@@ -58,7 +58,7 @@ public:
language(language),
os(os) {}
- bool operator()(const SharedHandle<MetalinkEntry>& entry) const {
+ bool operator()(const std::shared_ptr<MetalinkEntry>& entry) const {
if(!version.empty()) {
if(version != entry->version) {
return false;
@@ -80,7 +80,7 @@ public:
} // namespace
void Metalinker::queryEntry
-(std::vector<SharedHandle<MetalinkEntry> >& queryResult,
+(std::vector<std::shared_ptr<MetalinkEntry> >& queryResult,
const std::string& version,
const std::string& language,
const std::string& os) const
@@ -90,7 +90,7 @@ void Metalinker::queryEntry
std::not1(EntryQuery(version, language, os)));
}
-void Metalinker::addEntry(const SharedHandle<MetalinkEntry>& entry)
+void Metalinker::addEntry(const std::shared_ptr<MetalinkEntry>& entry)
{
entries_.push_back(entry);
}
diff --git a/src/Metalinker.h b/src/Metalinker.h
index b6399d34..6e2726d9 100644
--- a/src/Metalinker.h
+++ b/src/Metalinker.h
@@ -39,8 +39,7 @@
#include <string>
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -48,7 +47,7 @@ class MetalinkEntry;
class Metalinker {
private:
- std::vector<SharedHandle<MetalinkEntry> > entries_;
+ std::vector<std::shared_ptr<MetalinkEntry> > entries_;
public:
Metalinker();
~Metalinker();
@@ -58,17 +57,17 @@ public:
Metalinker& operator=(const Metalinker&);
void queryEntry
- (std::vector<SharedHandle<MetalinkEntry> >& queryResult,
+ (std::vector<std::shared_ptr<MetalinkEntry> >& queryResult,
const std::string& version,
const std::string& language,
const std::string& os) const;
- const std::vector<SharedHandle<MetalinkEntry> >& getEntries() const
+ const std::vector<std::shared_ptr<MetalinkEntry> >& getEntries() const
{
return entries_;
}
- void addEntry(const SharedHandle<MetalinkEntry>& entry);
+ void addEntry(const std::shared_ptr<MetalinkEntry>& entry);
};
} // namespace aria2
diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc
index dcc46bcb..4bdbab03 100644
--- a/src/MultiDiskAdaptor.cc
+++ b/src/MultiDiskAdaptor.cc
@@ -54,7 +54,7 @@
namespace aria2 {
-DiskWriterEntry::DiskWriterEntry(const SharedHandle<FileEntry>& fileEntry)
+DiskWriterEntry::DiskWriterEntry(const std::shared_ptr<FileEntry>& fileEntry)
: fileEntry_(fileEntry),
open_(false),
needsFileAllocation_(false)
@@ -107,7 +107,7 @@ int64_t DiskWriterEntry::size() const
return File(getFilePath()).size();
}
-void DiskWriterEntry::setDiskWriter(const SharedHandle<DiskWriter>& diskWriter)
+void DiskWriterEntry::setDiskWriter(const std::shared_ptr<DiskWriter>& diskWriter)
{
diskWriter_ = diskWriter;
}
@@ -126,11 +126,11 @@ MultiDiskAdaptor::MultiDiskAdaptor()
MultiDiskAdaptor::~MultiDiskAdaptor() {}
namespace {
-SharedHandle<DiskWriterEntry> createDiskWriterEntry
-(const SharedHandle<FileEntry>& fileEntry,
+std::shared_ptr<DiskWriterEntry> createDiskWriterEntry
+(const std::shared_ptr<FileEntry>& fileEntry,
bool needsFileAllocation)
{
- SharedHandle<DiskWriterEntry> entry(new DiskWriterEntry(fileEntry));
+ std::shared_ptr<DiskWriterEntry> entry(new DiskWriterEntry(fileEntry));
entry->needsFileAllocation(needsFileAllocation);
return entry;
}
@@ -144,7 +144,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
return;
}
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
getFileEntries().begin(), eoi = getFileEntries().end(); i != eoi; ++i) {
diskWriterEntries_.push_back
(createDiskWriterEntry(*i, (*i)->isRequested()));
@@ -152,12 +152,12 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
std::map<std::string, bool> dwreq;
// TODO Currently, pieceLength_ == 0 is used for unit testing only.
if(pieceLength_ > 0) {
- std::vector<SharedHandle<DiskWriterEntry> >::const_iterator done =
+ std::vector<std::shared_ptr<DiskWriterEntry> >::const_iterator done =
diskWriterEntries_.begin();
- for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator itr =
+ for(std::vector<std::shared_ptr<DiskWriterEntry> >::const_iterator itr =
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
itr != eoi;) {
- const SharedHandle<FileEntry>& fileEntry = (*itr)->getFileEntry();
+ const std::shared_ptr<FileEntry>& fileEntry = (*itr)->getFileEntry();
if(!fileEntry->isRequested()) {
++itr;
@@ -166,9 +166,9 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
int64_t pieceStartOffset =
(fileEntry->getOffset()/pieceLength_)*pieceLength_;
if(itr != diskWriterEntries_.begin()) {
- for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<DiskWriterEntry> >::const_iterator i =
itr-1; true; --i) {
- const SharedHandle<FileEntry>& fileEntry = (*i)->getFileEntry();
+ const std::shared_ptr<FileEntry>& fileEntry = (*i)->getFileEntry();
if(pieceStartOffset <= fileEntry->getOffset() ||
pieceStartOffset < fileEntry->getLastOffset()) {
(*i)->needsFileAllocation(true);
@@ -218,7 +218,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
}
}
DefaultDiskWriterFactory dwFactory;
- for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<DiskWriterEntry> >::const_iterator i =
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
i != eoi; ++i) {
if((*i)->needsFileAllocation() ||
@@ -237,7 +237,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
}
void MultiDiskAdaptor::openIfNot
-(const SharedHandle<DiskWriterEntry>& entry, void (DiskWriterEntry::*open)())
+(const std::shared_ptr<DiskWriterEntry>& entry, void (DiskWriterEntry::*open)())
{
if(!entry->isOpen()) {
// A2_LOG_DEBUG(fmt("DiskWriterEntry: Cache MISS. offset=%s",
@@ -250,7 +250,7 @@ void MultiDiskAdaptor::openIfNot
// Choose one DiskWriterEntry randomly and close it.
size_t index =
SimpleRandomizer::getInstance()->getRandomNumber(numOpened);
- std::vector<SharedHandle<DiskWriterEntry> >::iterator i =
+ std::vector<std::shared_ptr<DiskWriterEntry> >::iterator i =
openedDiskWriterEntries_.begin();
std::advance(i, index);
(*i)->closeFile();
@@ -304,7 +304,7 @@ void MultiDiskAdaptor::closeFile()
}
namespace {
-bool isInRange(const SharedHandle<DiskWriterEntry> entry, int64_t offset)
+bool isInRange(const std::shared_ptr<DiskWriterEntry> entry, int64_t offset)
{
return entry->getFileEntry()->getOffset() <= offset &&
offset < entry->getFileEntry()->getLastOffset();
@@ -312,7 +312,7 @@ bool isInRange(const SharedHandle<DiskWriterEntry> entry, int64_t offset)
} // namespace
namespace {
-ssize_t calculateLength(const SharedHandle<DiskWriterEntry> entry,
+ssize_t calculateLength(const std::shared_ptr<DiskWriterEntry> entry,
int64_t fileOffset, ssize_t rem)
{
if(entry->getFileEntry()->getLength() < fileOffset+rem) {
@@ -326,7 +326,7 @@ ssize_t calculateLength(const SharedHandle<DiskWriterEntry> entry,
namespace {
class OffsetCompare {
public:
- bool operator()(int64_t offset, const SharedHandle<DiskWriterEntry>& dwe)
+ bool operator()(int64_t offset, const std::shared_ptr<DiskWriterEntry>& dwe)
{
return offset < dwe->getFileEntry()->getOffset();
}
@@ -353,7 +353,7 @@ DiskWriterEntries::const_iterator findFirstDiskWriterEntry
} // namespace
namespace {
-void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
+void throwOnDiskWriterNotOpened(const std::shared_ptr<DiskWriterEntry>& e,
int64_t offset)
{
throw DL_ABORT_EX
@@ -439,7 +439,7 @@ void MultiDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
size_t celloff = 0;
for(; dent != eod; ++dent) {
int64_t lstart = 0, lp = 0;
- const SharedHandle<FileEntry>& fent = (*dent)->getFileEntry();
+ const std::shared_ptr<FileEntry>& fent = (*dent)->getFileEntry();
for(; i != eoi;) {
if(std::max(fent->getOffset(),
static_cast<int64_t>((*i)->goff + celloff)) <
@@ -450,7 +450,7 @@ void MultiDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
throwOnDiskWriterNotOpened(*dent, (*i)->goff + celloff);
}
} else {
- A2_LOG_DEBUG(fmt("%s Cache flush loff=%"PRId64", len=%lu",
+ A2_LOG_DEBUG(fmt("%s Cache flush loff=%" PRId64 ", len=%lu",
fent->getPath().c_str(),
lstart,
static_cast<unsigned long>(buflen-buffoffset)));
@@ -461,7 +461,7 @@ void MultiDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
}
int64_t loff = fent->gtoloff((*i)->goff + celloff);
if(static_cast<int64_t>(lstart + buflen) < loff) {
- A2_LOG_DEBUG(fmt("%s Cache flush loff=%"PRId64", len=%lu",
+ A2_LOG_DEBUG(fmt("%s Cache flush loff=%" PRId64 ", len=%lu",
fent->getPath().c_str(),
lstart,
static_cast<unsigned long>(buflen-buffoffset)));
@@ -485,7 +485,7 @@ void MultiDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
celloff += wlen;
lp += wlen;
if(lp == fent->getLength() || buflen == sizeof(buf)) {
- A2_LOG_DEBUG(fmt("%s Cache flush loff=%"PRId64", len=%lu",
+ A2_LOG_DEBUG(fmt("%s Cache flush loff=%" PRId64 ", len=%lu",
fent->getPath().c_str(),
lstart,
static_cast<unsigned long>(buflen-buffoffset)));
@@ -505,7 +505,7 @@ void MultiDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
}
}
if(i == eoi) {
- A2_LOG_DEBUG(fmt("%s Cache flush loff=%"PRId64", len=%lu",
+ A2_LOG_DEBUG(fmt("%s Cache flush loff=%" PRId64 ", len=%lu",
fent->getPath().c_str(),
lstart,
static_cast<unsigned long>(buflen - buffoffset)));
@@ -527,16 +527,16 @@ bool MultiDiskAdaptor::fileExists()
int64_t MultiDiskAdaptor::size()
{
int64_t size = 0;
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
getFileEntries().begin(), eoi = getFileEntries().end(); i != eoi; ++i) {
size += File((*i)->getPath()).size();
}
return size;
}
-SharedHandle<FileAllocationIterator> MultiDiskAdaptor::fileAllocationIterator()
+std::shared_ptr<FileAllocationIterator> MultiDiskAdaptor::fileAllocationIterator()
{
- return SharedHandle<FileAllocationIterator>
+ return std::shared_ptr<FileAllocationIterator>
(new MultiFileAllocationIterator(this));
}
@@ -552,10 +552,10 @@ void MultiDiskAdaptor::disableReadOnly()
void MultiDiskAdaptor::enableMmap()
{
- for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<DiskWriterEntry> >::const_iterator i =
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
i != eoi; ++i) {
- const SharedHandle<DiskWriter>& dw = (*i)->getDiskWriter();
+ const std::shared_ptr<DiskWriter>& dw = (*i)->getDiskWriter();
if(dw) {
dw->enableMmap();
}
@@ -564,7 +564,7 @@ void MultiDiskAdaptor::enableMmap()
void MultiDiskAdaptor::cutTrailingGarbage()
{
- for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<DiskWriterEntry> >::const_iterator i =
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
i != eoi; ++i) {
int64_t length = (*i)->getFileEntry()->getLength();
@@ -584,7 +584,7 @@ void MultiDiskAdaptor::setMaxOpenFiles(int maxOpenFiles)
size_t MultiDiskAdaptor::utime(const Time& actime, const Time& modtime)
{
size_t numOK = 0;
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
getFileEntries().begin(), eoi = getFileEntries().end(); i != eoi; ++i) {
if((*i)->isRequested()) {
File f((*i)->getPath());
diff --git a/src/MultiDiskAdaptor.h b/src/MultiDiskAdaptor.h
index 545c993b..f778f9d8 100644
--- a/src/MultiDiskAdaptor.h
+++ b/src/MultiDiskAdaptor.h
@@ -45,12 +45,12 @@ class DiskWriter;
class DiskWriterEntry {
private:
- SharedHandle<FileEntry> fileEntry_;
- SharedHandle<DiskWriter> diskWriter_;
+ std::shared_ptr<FileEntry> fileEntry_;
+ std::shared_ptr<DiskWriter> diskWriter_;
bool open_;
bool needsFileAllocation_;
public:
- DiskWriterEntry(const SharedHandle<FileEntry>& fileEntry);
+ DiskWriterEntry(const std::shared_ptr<FileEntry>& fileEntry);
const std::string& getFilePath() const;
@@ -71,14 +71,14 @@ public:
int64_t size() const;
- const SharedHandle<FileEntry>& getFileEntry() const
+ const std::shared_ptr<FileEntry>& getFileEntry() const
{
return fileEntry_;
}
- void setDiskWriter(const SharedHandle<DiskWriter>& diskWriter);
+ void setDiskWriter(const std::shared_ptr<DiskWriter>& diskWriter);
- const SharedHandle<DiskWriter>& getDiskWriter() const
+ const std::shared_ptr<DiskWriter>& getDiskWriter() const
{
return diskWriter_;
}
@@ -97,7 +97,7 @@ public:
};
-typedef std::vector<SharedHandle<DiskWriterEntry> > DiskWriterEntries;
+typedef std::vector<std::shared_ptr<DiskWriterEntry> > DiskWriterEntries;
class MultiDiskAdaptor : public DiskAdaptor {
friend class MultiFileAllocationIterator;
@@ -105,7 +105,7 @@ private:
int32_t pieceLength_;
DiskWriterEntries diskWriterEntries_;
- std::vector<SharedHandle<DiskWriterEntry> > openedDiskWriterEntries_;
+ std::vector<std::shared_ptr<DiskWriterEntry> > openedDiskWriterEntries_;
int maxOpenFiles_;
@@ -113,7 +113,7 @@ private:
void resetDiskWriterEntries();
- void openIfNot(const SharedHandle<DiskWriterEntry>& entry,
+ void openIfNot(const std::shared_ptr<DiskWriterEntry>& entry,
void (DiskWriterEntry::*f)());
static const int DEFAULT_MAX_OPEN_FILES = 100;
@@ -141,7 +141,7 @@ public:
virtual int64_t size();
- virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
+ virtual std::shared_ptr<FileAllocationIterator> fileAllocationIterator();
virtual void enableReadOnly();
@@ -168,7 +168,7 @@ public:
virtual size_t utime(const Time& actime, const Time& modtime);
- const std::vector<SharedHandle<DiskWriterEntry> >&
+ const std::vector<std::shared_ptr<DiskWriterEntry> >&
getDiskWriterEntries() const
{
return diskWriterEntries_;
diff --git a/src/MultiFileAllocationIterator.cc b/src/MultiFileAllocationIterator.cc
index 58e4b22a..b2561e10 100644
--- a/src/MultiFileAllocationIterator.cc
+++ b/src/MultiFileAllocationIterator.cc
@@ -60,9 +60,9 @@ void MultiFileAllocationIterator::allocateChunk()
if(entries_.empty()) {
break;
}
- SharedHandle<DiskWriterEntry> entry = entries_.front();
+ std::shared_ptr<DiskWriterEntry> entry = entries_.front();
entries_.pop_front();
- SharedHandle<FileEntry> fileEntry = entry->getFileEntry();
+ std::shared_ptr<FileEntry> fileEntry = entry->getFileEntry();
// Open file before calling DiskWriterEntry::size()
diskAdaptor_->openIfNot(entry, &DiskWriterEntry::openFile);
if(entry->needsFileAllocation() && entry->size() < fileEntry->getLength()) {
@@ -121,7 +121,7 @@ int64_t MultiFileAllocationIterator::getTotalLength()
}
}
-const std::deque<SharedHandle<DiskWriterEntry> >&
+const std::deque<std::shared_ptr<DiskWriterEntry> >&
MultiFileAllocationIterator::getDiskWriterEntries() const
{
return entries_;
diff --git a/src/MultiFileAllocationIterator.h b/src/MultiFileAllocationIterator.h
index 28713d7f..8780c8d1 100644
--- a/src/MultiFileAllocationIterator.h
+++ b/src/MultiFileAllocationIterator.h
@@ -36,7 +36,9 @@
#define D_MULTI_FILE_ALLOCATION_ITERATOR_H
#include "FileAllocationIterator.h"
+
#include <deque>
+#include <memory>
namespace aria2 {
@@ -47,8 +49,8 @@ class MultiFileAllocationIterator:public FileAllocationIterator
{
private:
MultiDiskAdaptor* diskAdaptor_;
- std::deque<SharedHandle<DiskWriterEntry> > entries_;
- SharedHandle<FileAllocationIterator> fileAllocationIterator_;
+ std::deque<std::shared_ptr<DiskWriterEntry> > entries_;
+ std::shared_ptr<FileAllocationIterator> fileAllocationIterator_;
public:
MultiFileAllocationIterator(MultiDiskAdaptor* diskAdaptor);
@@ -62,7 +64,7 @@ public:
virtual int64_t getTotalLength();
- const std::deque<SharedHandle<DiskWriterEntry> >&
+ const std::deque<std::shared_ptr<DiskWriterEntry> >&
getDiskWriterEntries() const;
};
diff --git a/src/MultiUrlRequestInfo.cc b/src/MultiUrlRequestInfo.cc
index 655a66e4..c7839acf 100644
--- a/src/MultiUrlRequestInfo.cc
+++ b/src/MultiUrlRequestInfo.cc
@@ -104,11 +104,11 @@ void handler(int signal) {
} // namespace
MultiUrlRequestInfo::MultiUrlRequestInfo
-(std::vector<SharedHandle<RequestGroup> >& requestGroups,
- const SharedHandle<Option>& op,
- const SharedHandle<StatCalc>& statCalc,
- const SharedHandle<OutputFile>& summaryOut,
- const SharedHandle<UriListParser>& uriListParser)
+(std::vector<std::shared_ptr<RequestGroup> >& requestGroups,
+ const std::shared_ptr<Option>& op,
+ const std::shared_ptr<StatCalc>& statCalc,
+ const std::shared_ptr<OutputFile>& summaryOut,
+ const std::shared_ptr<UriListParser>& uriListParser)
: option_(op),
statCalc_(statCalc),
summaryOut_(summaryOut),
@@ -137,7 +137,7 @@ int MultiUrlRequestInfo::prepare()
{
global::globalHaltRequested = 0;
try {
- SharedHandle<Notifier> notifier(new Notifier());
+ std::shared_ptr<Notifier> notifier(new Notifier());
SingletonHolder<Notifier>::instance(notifier);
#ifdef ENABLE_SSL
@@ -150,7 +150,7 @@ int MultiUrlRequestInfo::prepare()
) {
// We set server TLS context to the SocketCore before creating
// DownloadEngine instance.
- SharedHandle<TLSContext> svTlsContext(TLSContext::make(TLS_SERVER));
+ std::shared_ptr<TLSContext> svTlsContext(TLSContext::make(TLS_SERVER));
svTlsContext->addCredentialFile(option_->get(PREF_RPC_CERTIFICATE),
option_->get(PREF_RPC_PRIVATE_KEY));
SocketCore::setServerTLSContext(svTlsContext);
@@ -168,7 +168,7 @@ int MultiUrlRequestInfo::prepare()
#ifdef ENABLE_WEBSOCKET
if(option_->getAsBool(PREF_ENABLE_RPC)) {
- SharedHandle<rpc::WebSocketSessionMan> wsSessionMan
+ std::shared_ptr<rpc::WebSocketSessionMan> wsSessionMan
(new rpc::WebSocketSessionMan());
e_->setWebSocketSessionMan(wsSessionMan);
SingletonHolder<Notifier>::instance()->addDownloadEventListener
@@ -189,7 +189,7 @@ int MultiUrlRequestInfo::prepare()
}
}
- SharedHandle<AuthConfigFactory> authConfigFactory(new AuthConfigFactory());
+ std::shared_ptr<AuthConfigFactory> authConfigFactory(new AuthConfigFactory());
File netrccf(option_->get(PREF_NETRC_PATH));
if(!option_->getAsBool(PREF_NO_NETRC) && netrccf.isFile()) {
#ifdef __MINGW32__
@@ -202,7 +202,7 @@ int MultiUrlRequestInfo::prepare()
A2_LOG_NOTICE(fmt(MSG_INCORRECT_NETRC_PERMISSION,
option_->get(PREF_NETRC_PATH).c_str()));
} else {
- SharedHandle<Netrc> netrc(new Netrc());
+ std::shared_ptr<Netrc> netrc(new Netrc());
netrc->parse(option_->get(PREF_NETRC_PATH));
authConfigFactory->setNetrc(netrc);
}
@@ -210,7 +210,7 @@ int MultiUrlRequestInfo::prepare()
e_->setAuthConfigFactory(authConfigFactory);
#ifdef ENABLE_SSL
- SharedHandle<TLSContext> clTlsContext(TLSContext::make(TLS_CLIENT));
+ std::shared_ptr<TLSContext> clTlsContext(TLSContext::make(TLS_CLIENT));
if(!option_->blank(PREF_CERTIFICATE) &&
!option_->blank(PREF_PRIVATE_KEY)) {
clTlsContext->addCredentialFile(option_->get(PREF_CERTIFICATE),
@@ -375,7 +375,7 @@ void MultiUrlRequestInfo::resetSignalHandlers()
#endif // SIGPIPE
}
-const SharedHandle<DownloadEngine>&
+const std::shared_ptr<DownloadEngine>&
MultiUrlRequestInfo::getDownloadEngine() const
{
return e_;
diff --git a/src/MultiUrlRequestInfo.h b/src/MultiUrlRequestInfo.h
index 6a324af0..82850114 100644
--- a/src/MultiUrlRequestInfo.h
+++ b/src/MultiUrlRequestInfo.h
@@ -40,8 +40,8 @@
#include <signal.h>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "DownloadResult.h"
#include "util.h"
@@ -56,17 +56,17 @@ class DownloadEngine;
class MultiUrlRequestInfo {
private:
- std::vector<SharedHandle<RequestGroup> > requestGroups_;
+ std::vector<std::shared_ptr<RequestGroup> > requestGroups_;
- SharedHandle<Option> option_;
+ std::shared_ptr<Option> option_;
- SharedHandle<StatCalc> statCalc_;
+ std::shared_ptr<StatCalc> statCalc_;
- SharedHandle<OutputFile> summaryOut_;
+ std::shared_ptr<OutputFile> summaryOut_;
- SharedHandle<UriListParser> uriListParser_;
+ std::shared_ptr<UriListParser> uriListParser_;
- SharedHandle<DownloadEngine> e_;
+ std::shared_ptr<DownloadEngine> e_;
sigset_t mask_;
@@ -81,11 +81,11 @@ public:
* requestGroups.
*/
MultiUrlRequestInfo
- (std::vector<SharedHandle<RequestGroup> >& requestGroups,
- const SharedHandle<Option>& op,
- const SharedHandle<StatCalc>& statCalc,
- const SharedHandle<OutputFile>& summaryOut,
- const SharedHandle<UriListParser>& uriListParser);
+ (std::vector<std::shared_ptr<RequestGroup> >& requestGroups,
+ const std::shared_ptr<Option>& op,
+ const std::shared_ptr<StatCalc>& statCalc,
+ const std::shared_ptr<OutputFile>& summaryOut,
+ const std::shared_ptr<UriListParser>& uriListParser);
virtual ~MultiUrlRequestInfo();
@@ -107,7 +107,7 @@ public:
// have completed.
error_code::Value getResult();
- const SharedHandle<DownloadEngine>& getDownloadEngine() const;
+ const std::shared_ptr<DownloadEngine>& getDownloadEngine() const;
// Signal handlers are not prepared if false is given.
void setUseSignalHandler(bool useSignalHandler)
diff --git a/src/NameResolveCommand.cc b/src/NameResolveCommand.cc
index f3f31912..fab43395 100644
--- a/src/NameResolveCommand.cc
+++ b/src/NameResolveCommand.cc
@@ -54,7 +54,7 @@ namespace aria2 {
NameResolveCommand::NameResolveCommand
(cuid_t cuid, DownloadEngine* e,
- const SharedHandle<UDPTrackerRequest>& req)
+ const std::shared_ptr<UDPTrackerRequest>& req)
: Command(cuid),
e_(e),
#ifdef ENABLE_ASYNC_DNS
diff --git a/src/NameResolveCommand.h b/src/NameResolveCommand.h
index 5353508c..bf2e9464 100644
--- a/src/NameResolveCommand.h
+++ b/src/NameResolveCommand.h
@@ -39,8 +39,7 @@
#include <string>
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
// TODO Make this class generic.
namespace aria2 {
@@ -56,7 +55,7 @@ private:
DownloadEngine* e_;
#ifdef ENABLE_ASYNC_DNS
- SharedHandle<AsyncNameResolverMan> asyncNameResolverMan_;
+ std::shared_ptr<AsyncNameResolverMan> asyncNameResolverMan_;
#endif // ENABLE_ASYNC_DNS
#ifdef ENABLE_ASYNC_DNS
@@ -64,14 +63,14 @@ private:
const std::string& hostname);
#endif // ENABLE_ASYNC_DNS
- SharedHandle<UDPTrackerRequest> req_;
+ std::shared_ptr<UDPTrackerRequest> req_;
void onShutdown();
void onFailure();
void onSuccess
(const std::vector<std::string>& addrs, DownloadEngine* e);
public:
NameResolveCommand(cuid_t cuid, DownloadEngine* e,
- const SharedHandle<UDPTrackerRequest>& req);
+ const std::shared_ptr<UDPTrackerRequest>& req);
virtual ~NameResolveCommand();
diff --git a/src/Netrc.cc b/src/Netrc.cc
index cbcfc063..0c7743d5 100644
--- a/src/Netrc.cc
+++ b/src/Netrc.cc
@@ -107,7 +107,7 @@ Netrc::Netrc() {}
Netrc::~Netrc() {}
-void Netrc::addAuthenticator(const SharedHandle<Authenticator>& authenticator)
+void Netrc::addAuthenticator(const std::shared_ptr<Authenticator>& authenticator)
{
authenticators_.push_back(authenticator);
}
@@ -146,7 +146,7 @@ void Netrc::parse(const std::string& path)
SET_ACCOUNT,
SET_MACDEF
};
- SharedHandle<Authenticator> authenticator;
+ std::shared_ptr<Authenticator> authenticator;
STATE state = GET_TOKEN;
while(1) {
std::string line = fp.getLine();
@@ -215,7 +215,7 @@ void Netrc::parse(const std::string& path)
storeAuthenticator(authenticator);
}
-void Netrc::storeAuthenticator(const SharedHandle<Authenticator>& authenticator)
+void Netrc::storeAuthenticator(const std::shared_ptr<Authenticator>& authenticator)
{
if(authenticator) {
authenticators_.push_back(authenticator);
@@ -229,18 +229,18 @@ private:
public:
AuthHostMatch(const std::string& hostname):hostname(hostname) {}
- bool operator()(const SharedHandle<Authenticator>& authenticator)
+ bool operator()(const std::shared_ptr<Authenticator>& authenticator)
{
return authenticator->match(hostname);
}
};
} // namespace
-SharedHandle<Authenticator>
+std::shared_ptr<Authenticator>
Netrc::findAuthenticator(const std::string& hostname) const
{
- SharedHandle<Authenticator> res;
- std::vector<SharedHandle<Authenticator> >::const_iterator itr =
+ std::shared_ptr<Authenticator> res;
+ std::vector<std::shared_ptr<Authenticator> >::const_iterator itr =
std::find_if(authenticators_.begin(), authenticators_.end(),
AuthHostMatch(hostname));
if(itr != authenticators_.end()) {
diff --git a/src/Netrc.h b/src/Netrc.h
index f97a4b8b..1fd25b27 100644
--- a/src/Netrc.h
+++ b/src/Netrc.h
@@ -39,8 +39,7 @@
#include <string>
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -137,9 +136,9 @@ public:
class Netrc {
private:
- std::vector<SharedHandle<Authenticator> > authenticators_;
+ std::vector<std::shared_ptr<Authenticator> > authenticators_;
- void storeAuthenticator(const SharedHandle<Authenticator>& authenticator);
+ void storeAuthenticator(const std::shared_ptr<Authenticator>& authenticator);
public:
Netrc();
@@ -147,15 +146,15 @@ public:
void parse(const std::string& path);
- SharedHandle<Authenticator> findAuthenticator
+ std::shared_ptr<Authenticator> findAuthenticator
(const std::string& hostname) const;
- const std::vector<SharedHandle<Authenticator> >& getAuthenticators() const
+ const std::vector<std::shared_ptr<Authenticator> >& getAuthenticators() const
{
return authenticators_;
}
- void addAuthenticator(const SharedHandle<Authenticator>& authenticator);
+ void addAuthenticator(const std::shared_ptr<Authenticator>& authenticator);
};
} // namespace aria2
diff --git a/src/NetrcAuthResolver.cc b/src/NetrcAuthResolver.cc
index ea6d298c..04fcc9c1 100644
--- a/src/NetrcAuthResolver.cc
+++ b/src/NetrcAuthResolver.cc
@@ -40,7 +40,7 @@ namespace aria2 {
NetrcAuthResolver::NetrcAuthResolver():ignoreDefault_(false) {}
-SharedHandle<AuthConfig>
+std::shared_ptr<AuthConfig>
NetrcAuthResolver::resolveAuthConfig(const std::string& hostname)
{
if(!getUserDefinedAuthConfig()) {
@@ -50,27 +50,27 @@ NetrcAuthResolver::resolveAuthConfig(const std::string& hostname)
}
}
-SharedHandle<AuthConfig>
+std::shared_ptr<AuthConfig>
NetrcAuthResolver::findNetrcAuthenticator(const std::string& hostname) const
{
if(!netrc_) {
return getDefaultAuthConfig();
} else {
- SharedHandle<Authenticator> auth = netrc_->findAuthenticator(hostname);
+ std::shared_ptr<Authenticator> auth = netrc_->findAuthenticator(hostname);
if(!auth) {
return getDefaultAuthConfig();
} else {
if(ignoreDefault_ && auth->getMachine().empty()) {
return getDefaultAuthConfig();
} else {
- return SharedHandle<AuthConfig>
+ return std::shared_ptr<AuthConfig>
(new AuthConfig(auth->getLogin(), auth->getPassword()));
}
}
}
}
-void NetrcAuthResolver::setNetrc(const SharedHandle<Netrc>& netrc)
+void NetrcAuthResolver::setNetrc(const std::shared_ptr<Netrc>& netrc)
{
netrc_ = netrc;
}
diff --git a/src/NetrcAuthResolver.h b/src/NetrcAuthResolver.h
index 84b748af..a92b5dff 100644
--- a/src/NetrcAuthResolver.h
+++ b/src/NetrcAuthResolver.h
@@ -43,21 +43,21 @@ class Netrc;
class NetrcAuthResolver : public AbstractAuthResolver {
private:
- SharedHandle<Netrc> netrc_;
+ std::shared_ptr<Netrc> netrc_;
bool ignoreDefault_;
- SharedHandle<AuthConfig> findNetrcAuthenticator
+ std::shared_ptr<AuthConfig> findNetrcAuthenticator
(const std::string& hostname) const;
public:
NetrcAuthResolver();
- virtual SharedHandle<AuthConfig> resolveAuthConfig
+ virtual std::shared_ptr<AuthConfig> resolveAuthConfig
(const std::string& hostname);
- void setNetrc(const SharedHandle<Netrc>& netrc);
+ void setNetrc(const std::shared_ptr<Netrc>& netrc);
- const SharedHandle<Netrc>& getNetrc() const
+ const std::shared_ptr<Netrc>& getNetrc() const
{
return netrc_;
}
diff --git a/src/Notifier.cc b/src/Notifier.cc
index 5228e76f..da43a8cf 100644
--- a/src/Notifier.cc
+++ b/src/Notifier.cc
@@ -43,7 +43,7 @@ Notifier::Notifier() {}
Notifier::~Notifier() {}
void Notifier::addDownloadEventListener
-(const SharedHandle<DownloadEventListener>& listener)
+(const std::shared_ptr<DownloadEventListener>& listener)
{
listeners_.push_back(listener);
}
@@ -51,7 +51,7 @@ void Notifier::addDownloadEventListener
void Notifier::notifyDownloadEvent
(DownloadEvent event, const RequestGroup* group)
{
- for(std::vector<SharedHandle<DownloadEventListener> >::const_iterator i =
+ for(std::vector<std::shared_ptr<DownloadEventListener> >::const_iterator i =
listeners_.begin(), eoi = listeners_.end(); i != eoi; ++i) {
(*i)->onEvent(event, group);
}
diff --git a/src/Notifier.h b/src/Notifier.h
index 39787326..e4586c6c 100644
--- a/src/Notifier.h
+++ b/src/Notifier.h
@@ -38,9 +38,9 @@
#include "common.h"
#include <vector>
+#include <memory>
#include <aria2/aria2.h>
-#include "SharedHandle.h"
namespace aria2 {
@@ -56,17 +56,17 @@ public:
Notifier();
~Notifier();
void addDownloadEventListener
- (const SharedHandle<DownloadEventListener>& listener);
+ (const std::shared_ptr<DownloadEventListener>& listener);
// Notifies the download event to all listeners.
void notifyDownloadEvent(DownloadEvent event, const RequestGroup* group);
void notifyDownloadEvent(DownloadEvent event,
- const SharedHandle<RequestGroup>& group)
+ const std::shared_ptr<RequestGroup>& group)
{
notifyDownloadEvent(event, group.get());
}
private:
- std::vector<SharedHandle<DownloadEventListener> > listeners_;
+ std::vector<std::shared_ptr<DownloadEventListener> > listeners_;
};
} // namespace aria2
diff --git a/src/NullHandle.h b/src/NullHandle.h
index 0e739bda..487a3a3c 100644
--- a/src/NullHandle.h
+++ b/src/NullHandle.h
@@ -35,16 +35,18 @@
#ifndef D_NULL_HANDLE_H
#define D_NULL_HANDLE_H
-#include "SharedHandle.h"
+#include "common.h"
+
+#include <memory>
namespace aria2 {
-// Returns const reference of SharedHandle<T>(). Static variable null
+// Returns const reference of std::shared_ptr<T>(). Static variable null
// is shared by all instantiation of this function template.
template<typename T>
-const SharedHandle<T>& getNull()
+const std::shared_ptr<T>& getNull()
{
- static SharedHandle<T> null;
+ static std::shared_ptr<T> null;
return null;
}
diff --git a/src/NullSinkStreamFilter.h b/src/NullSinkStreamFilter.h
index 23d59c86..629ddd75 100644
--- a/src/NullSinkStreamFilter.h
+++ b/src/NullSinkStreamFilter.h
@@ -48,8 +48,8 @@ public:
virtual void init() {}
virtual ssize_t transform
- (const SharedHandle<BinaryStream>& out,
- const SharedHandle<Segment>& segment,
+ (const std::shared_ptr<BinaryStream>& out,
+ const std::shared_ptr<Segment>& segment,
const unsigned char* inbuf, size_t inlen)
{
bytesProcessed_ = inlen;
@@ -75,7 +75,7 @@ public:
return bytesProcessed_;
}
- virtual bool installDelegate(const SharedHandle<StreamFilter>& filter)
+ virtual bool installDelegate(const std::shared_ptr<StreamFilter>& filter)
{
return false;
}
diff --git a/src/NullWebSocketSessionMan.h b/src/NullWebSocketSessionMan.h
index 0e5e34d5..acef66d3 100644
--- a/src/NullWebSocketSessionMan.h
+++ b/src/NullWebSocketSessionMan.h
@@ -38,8 +38,7 @@
#include "common.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
// Empty implementation for build without WebSocket support.
@@ -55,8 +54,8 @@ class WebSocketSessionMan {
public:
WebSocketSessionMan() {}
~WebSocketSessionMan() {}
- void addSession(const SharedHandle<WebSocketSession>& wsSession) {}
- void removeSession(const SharedHandle<WebSocketSession>& wsSession) {}
+ void addSession(const std::shared_ptr<WebSocketSession>& wsSession) {}
+ void removeSession(const std::shared_ptr<WebSocketSession>& wsSession) {}
void addNotification(const std::string& method, const RequestGroup* group) {}
};
diff --git a/src/Option.cc b/src/Option.cc
index f86060d7..00ada34a 100644
--- a/src/Option.cc
+++ b/src/Option.cc
@@ -171,12 +171,12 @@ void Option::merge(const Option& option)
}
}
-void Option::setParent(const SharedHandle<Option>& parent)
+void Option::setParent(const std::shared_ptr<Option>& parent)
{
parent_ = parent;
}
-const SharedHandle<Option>& Option::getParent() const
+const std::shared_ptr<Option>& Option::getParent() const
{
return parent_;
}
diff --git a/src/Option.h b/src/Option.h
index c90703e4..ba397c10 100644
--- a/src/Option.h
+++ b/src/Option.h
@@ -39,8 +39,7 @@
#include <string>
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -50,7 +49,7 @@ class Option {
private:
std::vector<std::string> table_;
std::vector<unsigned char> use_;
- SharedHandle<Option> parent_;
+ std::shared_ptr<Option> parent_;
public:
Option();
~Option();
@@ -91,8 +90,8 @@ public:
// left unmodified for this object.
void merge(const Option& option);
// Sets parent Option object for this object.
- void setParent(const SharedHandle<Option>& parent);
- const SharedHandle<Option>& getParent() const;
+ void setParent(const std::shared_ptr<Option>& parent);
+ const std::shared_ptr<Option>& getParent() const;
};
} // namespace aria2
diff --git a/src/OptionHandler.h b/src/OptionHandler.h
index eb9272c2..14f77346 100644
--- a/src/OptionHandler.h
+++ b/src/OptionHandler.h
@@ -42,7 +42,6 @@
#include <iosfwd>
#include <functional>
-#include "SharedHandle.h"
#include "console.h"
namespace aria2 {
diff --git a/src/OptionHandlerException.cc b/src/OptionHandlerException.cc
index eb740e5b..6fe1b23c 100644
--- a/src/OptionHandlerException.cc
+++ b/src/OptionHandlerException.cc
@@ -63,9 +63,9 @@ OptionHandlerException::OptionHandlerException
OptionHandlerException::~OptionHandlerException() throw() {}
-SharedHandle<Exception> OptionHandlerException::copy() const
+std::shared_ptr<Exception> OptionHandlerException::copy() const
{
- SharedHandle<Exception> e(new OptionHandlerException(*this));
+ std::shared_ptr<Exception> e(new OptionHandlerException(*this));
return e;
}
diff --git a/src/OptionHandlerException.h b/src/OptionHandlerException.h
index 49c456c9..5426ee9d 100644
--- a/src/OptionHandlerException.h
+++ b/src/OptionHandlerException.h
@@ -44,7 +44,7 @@ class OptionHandlerException:public RecoverableException {
private:
const Pref* pref_;
protected:
- virtual SharedHandle<Exception> copy() const;
+ virtual std::shared_ptr<Exception> copy() const;
public:
OptionHandlerException(const char* file, int line,
const Pref* pref);
diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc
index d0740fd6..9e0e3cec 100644
--- a/src/OptionHandlerFactory.cc
+++ b/src/OptionHandlerFactory.cc
@@ -1351,7 +1351,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
OptionHandler* op(new DefaultOptionHandler
(PREF_USER_AGENT,
TEXT_USER_AGENT,
- "aria2/"PACKAGE_VERSION,
+ "aria2/" PACKAGE_VERSION,
A2STR::NIL,
OptionHandler::REQ_ARG,
'U'));
diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc
index 06b4de93..8efc62c8 100644
--- a/src/OptionHandlerImpl.cc
+++ b/src/OptionHandlerImpl.cc
@@ -611,7 +611,7 @@ void PrioritizePieceOptionHandler::parseArg
// error.
std::vector<size_t> result;
util::parsePrioritizePieceRange
- (result, optarg, std::vector<SharedHandle<FileEntry> >(), 1024);
+ (result, optarg, std::vector<std::shared_ptr<FileEntry> >(), 1024);
option.put(pref_, optarg);
}
diff --git a/src/OptionParser.cc b/src/OptionParser.cc
index 1cce8495..0cc3ca59 100644
--- a/src/OptionParser.cc
+++ b/src/OptionParser.cc
@@ -38,6 +38,7 @@
#include <getopt.h>
#include <cstring>
+#include <cassert>
#include <istream>
#include <utility>
@@ -354,9 +355,9 @@ const OptionHandler* OptionParser::findByShortName(char shortName) const
return findById(shortOpts_[idx]);
}
-SharedHandle<OptionParser> OptionParser::optionParser_;
+std::shared_ptr<OptionParser> OptionParser::optionParser_;
-const SharedHandle<OptionParser>& OptionParser::getInstance()
+const std::shared_ptr<OptionParser>& OptionParser::getInstance()
{
if(!optionParser_) {
optionParser_.reset(new OptionParser());
diff --git a/src/OptionParser.h b/src/OptionParser.h
index 4f7d11a5..02688212 100644
--- a/src/OptionParser.h
+++ b/src/OptionParser.h
@@ -40,9 +40,9 @@
#include <string>
#include <vector>
#include <iosfwd>
+#include <memory>
#include <aria2/aria2.h>
-#include "SharedHandle.h"
namespace aria2 {
@@ -55,7 +55,7 @@ private:
std::vector<OptionHandler*> handlers_;
// Index of handler in handlers_ for option who has short option name.
std::vector<size_t> shortOpts_;
- static SharedHandle<OptionParser> optionParser_;
+ static std::shared_ptr<OptionParser> optionParser_;
public:
OptionParser();
~OptionParser();
@@ -96,7 +96,7 @@ public:
// Hidden options are not returned.
const OptionHandler* findByShortName(char shortName) const;
- static const SharedHandle<OptionParser>& getInstance();
+ static const std::shared_ptr<OptionParser>& getInstance();
// Deletes statically allocated instace. Call this at the end of the
// program.
static void deleteInstance();
diff --git a/src/Peer.h b/src/Peer.h
index ec6a22ec..b0f4a09e 100644
--- a/src/Peer.h
+++ b/src/Peer.h
@@ -42,7 +42,6 @@
#include <set>
#include <algorithm>
-#include "SharedHandle.h"
#include "TimerA2.h"
#include "BtConstants.h"
#include "PeerStat.h"
diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc
index 6ae633d1..df10c9ee 100644
--- a/src/PeerAbstractCommand.cc
+++ b/src/PeerAbstractCommand.cc
@@ -51,9 +51,9 @@ namespace aria2 {
PeerAbstractCommand::PeerAbstractCommand
(cuid_t cuid,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s)
+ const std::shared_ptr<SocketCore>& s)
: Command(cuid),
checkPoint_(global::wallclock()),
// TODO referring global option
@@ -136,7 +136,7 @@ void PeerAbstractCommand::disableReadCheckSocket()
}
}
-void PeerAbstractCommand::setReadCheckSocket(const SharedHandle<SocketCore>& socket)
+void PeerAbstractCommand::setReadCheckSocket(const std::shared_ptr<SocketCore>& socket)
{
if(!socket->isOpen()) {
disableReadCheckSocket();
@@ -164,7 +164,7 @@ void PeerAbstractCommand::disableWriteCheckSocket()
}
}
-void PeerAbstractCommand::setWriteCheckSocket(const SharedHandle<SocketCore>& socket)
+void PeerAbstractCommand::setWriteCheckSocket(const std::shared_ptr<SocketCore>& socket)
{
if(!socket->isOpen()) {
disableWriteCheckSocket();
diff --git a/src/PeerAbstractCommand.h b/src/PeerAbstractCommand.h
index 50aa719c..147237c1 100644
--- a/src/PeerAbstractCommand.h
+++ b/src/PeerAbstractCommand.h
@@ -36,7 +36,9 @@
#define D_PEER_ABSTRACT_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "TimerA2.h"
namespace aria2 {
@@ -51,13 +53,13 @@ private:
Timer checkPoint_;
time_t timeout_;
DownloadEngine* e_;
- SharedHandle<SocketCore> socket_;
- SharedHandle<Peer> peer_;
+ std::shared_ptr<SocketCore> socket_;
+ std::shared_ptr<Peer> peer_;
bool checkSocketIsReadable_;
bool checkSocketIsWritable_;
- SharedHandle<SocketCore> readCheckTarget_;
- SharedHandle<SocketCore> writeCheckTarget_;
+ std::shared_ptr<SocketCore> readCheckTarget_;
+ std::shared_ptr<SocketCore> writeCheckTarget_;
bool noCheck_;
protected:
DownloadEngine* getDownloadEngine() const
@@ -65,14 +67,14 @@ protected:
return e_;
}
- const SharedHandle<SocketCore>& getSocket() const
+ const std::shared_ptr<SocketCore>& getSocket() const
{
return socket_;
}
void createSocket();
- const SharedHandle<Peer>& getPeer() const
+ const std::shared_ptr<Peer>& getPeer() const
{
return peer_;
}
@@ -85,18 +87,18 @@ protected:
virtual void onFailure(const Exception& err) {};
virtual bool exitBeforeExecute() = 0;
virtual bool executeInternal() = 0;
- void setReadCheckSocket(const SharedHandle<SocketCore>& socket);
- void setWriteCheckSocket(const SharedHandle<SocketCore>& socket);
+ void setReadCheckSocket(const std::shared_ptr<SocketCore>& socket);
+ void setWriteCheckSocket(const std::shared_ptr<SocketCore>& socket);
void disableReadCheckSocket();
void disableWriteCheckSocket();
void setNoCheck(bool check);
void updateKeepAlive();
public:
PeerAbstractCommand(cuid_t cuid,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s =
- SharedHandle<SocketCore>());
+ const std::shared_ptr<SocketCore>& s =
+ std::shared_ptr<SocketCore>());
virtual ~PeerAbstractCommand();
diff --git a/src/PeerChokeCommand.cc b/src/PeerChokeCommand.cc
index 035b0636..8568e7d8 100644
--- a/src/PeerChokeCommand.cc
+++ b/src/PeerChokeCommand.cc
@@ -58,13 +58,13 @@ bool PeerChokeCommand::execute() {
}
void PeerChokeCommand::setBtRuntime
-(const SharedHandle<BtRuntime>& btRuntime)
+(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
void PeerChokeCommand::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
diff --git a/src/PeerChokeCommand.h b/src/PeerChokeCommand.h
index 54feb6eb..8cf5e7a5 100644
--- a/src/PeerChokeCommand.h
+++ b/src/PeerChokeCommand.h
@@ -36,7 +36,8 @@
#define D_PEER_CHOKE_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -48,9 +49,9 @@ class PeerChokeCommand : public Command {
private:
DownloadEngine* e_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
- SharedHandle<BtRuntime> btRuntime_;
+ std::shared_ptr<BtRuntime> btRuntime_;
public:
PeerChokeCommand(cuid_t cuid,
DownloadEngine* e);
@@ -59,9 +60,9 @@ public:
virtual bool execute();
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
};
} // namespace aria2
diff --git a/src/PeerConnection.cc b/src/PeerConnection.cc
index d5b6188c..99c19ac6 100644
--- a/src/PeerConnection.cc
+++ b/src/PeerConnection.cc
@@ -64,7 +64,7 @@ enum {
} // namespace
PeerConnection::PeerConnection
-(cuid_t cuid, const SharedHandle<Peer>& peer, const SharedHandle<SocketCore>& socket)
+(cuid_t cuid, const std::shared_ptr<Peer>& peer, const std::shared_ptr<SocketCore>& socket)
: cuid_(cuid),
peer_(peer),
socket_(socket),
@@ -232,8 +232,8 @@ void PeerConnection::readData
}
void PeerConnection::enableEncryption
-(const SharedHandle<ARC4Encryptor>& encryptor,
- const SharedHandle<ARC4Encryptor>& decryptor)
+(const std::shared_ptr<ARC4Encryptor>& encryptor,
+ const std::shared_ptr<ARC4Encryptor>& decryptor)
{
encryptor_ = encryptor;
decryptor_ = decryptor;
diff --git a/src/PeerConnection.h b/src/PeerConnection.h
index d3bfec39..09c676ea 100644
--- a/src/PeerConnection.h
+++ b/src/PeerConnection.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <unistd.h>
+#include <memory>
-#include "SharedHandle.h"
#include "SocketBuffer.h"
#include "Command.h"
@@ -57,8 +57,8 @@ class ARC4Encryptor;
class PeerConnection {
private:
cuid_t cuid_;
- SharedHandle<Peer> peer_;
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<Peer> peer_;
+ std::shared_ptr<SocketCore> socket_;
int msgState_;
// The capacity of the buffer resbuf_
@@ -77,8 +77,8 @@ private:
SocketBuffer socketBuffer_;
bool encryptionEnabled_;
- SharedHandle<ARC4Encryptor> encryptor_;
- SharedHandle<ARC4Encryptor> decryptor_;
+ std::shared_ptr<ARC4Encryptor> encryptor_;
+ std::shared_ptr<ARC4Encryptor> decryptor_;
bool prevPeek_;
@@ -89,8 +89,8 @@ private:
public:
PeerConnection
(cuid_t cuid,
- const SharedHandle<Peer>& peer,
- const SharedHandle<SocketCore>& socket);
+ const std::shared_ptr<Peer>& peer,
+ const std::shared_ptr<SocketCore>& socket);
~PeerConnection();
@@ -112,8 +112,8 @@ public:
bool receiveHandshake
(unsigned char* data, size_t& dataLength, bool peek = false);
- void enableEncryption(const SharedHandle<ARC4Encryptor>& encryptor,
- const SharedHandle<ARC4Encryptor>& decryptor);
+ void enableEncryption(const std::shared_ptr<ARC4Encryptor>& encryptor,
+ const std::shared_ptr<ARC4Encryptor>& decryptor);
void presetBuffer(const unsigned char* data, size_t length);
diff --git a/src/PeerInitiateConnectionCommand.cc b/src/PeerInitiateConnectionCommand.cc
index 5803805b..118163ce 100644
--- a/src/PeerInitiateConnectionCommand.cc
+++ b/src/PeerInitiateConnectionCommand.cc
@@ -56,9 +56,9 @@ namespace aria2 {
PeerInitiateConnectionCommand::PeerInitiateConnectionCommand
(cuid_t cuid,
RequestGroup* requestGroup,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
DownloadEngine* e,
- const SharedHandle<BtRuntime>& btRuntime,
+ const std::shared_ptr<BtRuntime>& btRuntime,
bool mseHandshakeEnabled)
: PeerAbstractCommand(cuid, peer, e),
requestGroup_(requestGroup),
@@ -106,7 +106,7 @@ bool PeerInitiateConnectionCommand::executeInternal() {
bool PeerInitiateConnectionCommand::prepareForNextPeer(time_t wait) {
if(peerStorage_->isPeerAvailable() && btRuntime_->lessThanEqMinPeers()) {
cuid_t ncuid = getDownloadEngine()->newCUID();
- SharedHandle<Peer> peer = peerStorage_->checkoutPeer(ncuid);
+ std::shared_ptr<Peer> peer = peerStorage_->checkoutPeer(ncuid);
// sanity check
if(peer) {
PeerInitiateConnectionCommand* command;
@@ -131,13 +131,13 @@ bool PeerInitiateConnectionCommand::exitBeforeExecute()
}
void PeerInitiateConnectionCommand::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
void PeerInitiateConnectionCommand::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
diff --git a/src/PeerInitiateConnectionCommand.h b/src/PeerInitiateConnectionCommand.h
index db7262db..50a4f514 100644
--- a/src/PeerInitiateConnectionCommand.h
+++ b/src/PeerInitiateConnectionCommand.h
@@ -48,11 +48,11 @@ class PeerInitiateConnectionCommand : public PeerAbstractCommand {
private:
RequestGroup* requestGroup_;
- SharedHandle<BtRuntime> btRuntime_;
+ std::shared_ptr<BtRuntime> btRuntime_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
bool mseHandshakeEnabled_;
protected:
@@ -64,16 +64,16 @@ protected:
public:
PeerInitiateConnectionCommand(cuid_t cuid,
RequestGroup* requestGroup,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
DownloadEngine* e,
- const SharedHandle<BtRuntime>& btRuntime,
+ const std::shared_ptr<BtRuntime>& btRuntime,
bool mseHandshakeEnabled = true);
virtual ~PeerInitiateConnectionCommand();
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
};
} // namespace aria2
diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc
index f07e42b5..5d762023 100644
--- a/src/PeerInteractionCommand.cc
+++ b/src/PeerInteractionCommand.cc
@@ -82,14 +82,14 @@ namespace aria2 {
PeerInteractionCommand::PeerInteractionCommand
(cuid_t cuid,
RequestGroup* requestGroup,
- const SharedHandle<Peer>& p,
+ const std::shared_ptr<Peer>& p,
DownloadEngine* e,
- const SharedHandle<BtRuntime>& btRuntime,
- const SharedHandle<PieceStorage>& pieceStorage,
- const SharedHandle<PeerStorage>& peerStorage,
- const SharedHandle<SocketCore>& s,
+ const std::shared_ptr<BtRuntime>& btRuntime,
+ const std::shared_ptr<PieceStorage>& pieceStorage,
+ const std::shared_ptr<PeerStorage>& peerStorage,
+ const std::shared_ptr<SocketCore>& s,
Seq sequence,
- const SharedHandle<PeerConnection>& passedPeerConnection)
+ const std::shared_ptr<PeerConnection>& passedPeerConnection)
:PeerAbstractCommand(cuid, p, e, s),
requestGroup_(requestGroup),
btRuntime_(btRuntime),
@@ -114,19 +114,19 @@ PeerInteractionCommand::PeerInteractionCommand
family = AF_INET;
}
- SharedHandle<TorrentAttribute> torrentAttrs =
+ std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(requestGroup_->getDownloadContext());
bool metadataGetMode = torrentAttrs->metadata.empty();
- SharedHandle<ExtensionMessageRegistry> exMsgRegistry
+ std::shared_ptr<ExtensionMessageRegistry> exMsgRegistry
(new ExtensionMessageRegistry());
exMsgRegistry->setExtensionMessageID(ExtensionMessageRegistry::UT_PEX, 8);
// http://www.bittorrent.org/beps/bep_0009.html
exMsgRegistry->setExtensionMessageID(ExtensionMessageRegistry::UT_METADATA,
9);
- SharedHandle<UTMetadataRequestFactory> utMetadataRequestFactory;
- SharedHandle<UTMetadataRequestTracker> utMetadataRequestTracker;
+ std::shared_ptr<UTMetadataRequestFactory> utMetadataRequestFactory;
+ std::shared_ptr<UTMetadataRequestTracker> utMetadataRequestTracker;
if(metadataGetMode) {
utMetadataRequestFactory.reset(new UTMetadataRequestFactory());
utMetadataRequestTracker.reset(new UTMetadataRequestTracker());
@@ -140,7 +140,7 @@ PeerInteractionCommand::PeerInteractionCommand
extensionMessageFactoryPtr->setUTMetadataRequestTracker
(utMetadataRequestTracker.get());
// PieceStorage will be set later.
- SharedHandle<ExtensionMessageFactory> extensionMessageFactory
+ std::shared_ptr<ExtensionMessageFactory> extensionMessageFactory
(extensionMessageFactoryPtr);
@@ -166,10 +166,10 @@ PeerInteractionCommand::PeerInteractionCommand
if(metadataGetMode) {
factoryPtr->enableMetadataGetMode();
}
- SharedHandle<BtMessageFactory> factory(factoryPtr);
+ std::shared_ptr<BtMessageFactory> factory(factoryPtr);
- SharedHandle<PeerConnection> peerConnection;
+ std::shared_ptr<PeerConnection> peerConnection;
if(!passedPeerConnection) {
peerConnection.reset(new PeerConnection(cuid, getPeer(), getSocket()));
} else {
@@ -201,14 +201,14 @@ PeerInteractionCommand::PeerInteractionCommand
dispatcherPtr->setRequestGroupMan
(getDownloadEngine()->getRequestGroupMan().get());
dispatcherPtr->setPeerConnection(peerConnection);
- SharedHandle<BtMessageDispatcher> dispatcher(dispatcherPtr);
+ std::shared_ptr<BtMessageDispatcher> dispatcher(dispatcherPtr);
DefaultBtMessageReceiver* receiverPtr(new DefaultBtMessageReceiver());
receiverPtr->setDownloadContext(requestGroup_->getDownloadContext());
receiverPtr->setPeerConnection(peerConnection.get());
receiverPtr->setDispatcher(dispatcherPtr);
receiverPtr->setBtMessageFactory(factoryPtr);
- SharedHandle<BtMessageReceiver> receiver(receiverPtr);
+ std::shared_ptr<BtMessageReceiver> receiver(receiverPtr);
DefaultBtRequestFactory* reqFactoryPtr(new DefaultBtRequestFactory());
reqFactoryPtr->setPeer(getPeer());
@@ -216,7 +216,7 @@ PeerInteractionCommand::PeerInteractionCommand
reqFactoryPtr->setBtMessageDispatcher(dispatcherPtr);
reqFactoryPtr->setBtMessageFactory(factoryPtr);
reqFactoryPtr->setCuid(cuid);
- SharedHandle<BtRequestFactory> reqFactory(reqFactoryPtr);
+ std::shared_ptr<BtRequestFactory> reqFactory(reqFactoryPtr);
DefaultBtInteractive* btInteractivePtr
(new DefaultBtInteractive(requestGroup_->getDownloadContext(), getPeer()));
@@ -260,7 +260,7 @@ PeerInteractionCommand::PeerInteractionCommand
if(metadataGetMode) {
btInteractivePtr->enableMetadataGetMode();
}
- SharedHandle<BtInteractive> btInteractive(btInteractivePtr);
+ std::shared_ptr<BtInteractive> btInteractive(btInteractivePtr);
btInteractive_ = btInteractive;
@@ -328,7 +328,7 @@ bool PeerInteractionCommand::executeInternal() {
break;
}
}
- SharedHandle<BtMessage> handshakeMessage =
+ std::shared_ptr<BtMessage> handshakeMessage =
btInteractive_->receiveHandshake();
if(!handshakeMessage) {
done = true;
@@ -339,7 +339,7 @@ bool PeerInteractionCommand::executeInternal() {
break;
}
case RECEIVER_WAIT_HANDSHAKE: {
- SharedHandle<BtMessage> handshakeMessage =
+ std::shared_ptr<BtMessage> handshakeMessage =
btInteractive_->receiveAndSendHandshake();
if(!handshakeMessage) {
done = true;
@@ -392,7 +392,7 @@ bool PeerInteractionCommand::executeInternal() {
bool PeerInteractionCommand::prepareForNextPeer(time_t wait) {
if(peerStorage_->isPeerAvailable() && btRuntime_->lessThanEqMinPeers()) {
cuid_t ncuid = getDownloadEngine()->newCUID();
- SharedHandle<Peer> peer = peerStorage_->checkoutPeer(ncuid);
+ std::shared_ptr<Peer> peer = peerStorage_->checkoutPeer(ncuid);
// sanity check
if(peer) {
PeerInitiateConnectionCommand* command;
@@ -424,7 +424,7 @@ bool PeerInteractionCommand::exitBeforeExecute()
return btRuntime_->isHalt();
}
-const SharedHandle<Option>& PeerInteractionCommand::getOption() const
+const std::shared_ptr<Option>& PeerInteractionCommand::getOption() const
{
return requestGroup_->getOption();
}
diff --git a/src/PeerInteractionCommand.h b/src/PeerInteractionCommand.h
index 9dbdecbd..dae71ddc 100644
--- a/src/PeerInteractionCommand.h
+++ b/src/PeerInteractionCommand.h
@@ -57,16 +57,16 @@ public:
private:
RequestGroup* requestGroup_;
- SharedHandle<BtRuntime> btRuntime_;
+ std::shared_ptr<BtRuntime> btRuntime_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
Seq sequence_;
- SharedHandle<BtInteractive> btInteractive_;
+ std::shared_ptr<BtInteractive> btInteractive_;
- const SharedHandle<Option>& getOption() const;
+ const std::shared_ptr<Option>& getOption() const;
protected:
virtual bool executeInternal();
virtual bool prepareForNextPeer(time_t wait);
@@ -76,15 +76,15 @@ protected:
public:
PeerInteractionCommand(cuid_t cuid,
RequestGroup* requestGroup,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
DownloadEngine* e,
- const SharedHandle<BtRuntime>& btRuntime,
- const SharedHandle<PieceStorage>& pieceStorage,
- const SharedHandle<PeerStorage>& peerStorage,
- const SharedHandle<SocketCore>& s,
+ const std::shared_ptr<BtRuntime>& btRuntime,
+ const std::shared_ptr<PieceStorage>& pieceStorage,
+ const std::shared_ptr<PeerStorage>& peerStorage,
+ const std::shared_ptr<SocketCore>& s,
Seq sequence,
- const SharedHandle<PeerConnection>& peerConnection =
- SharedHandle<PeerConnection>());
+ const std::shared_ptr<PeerConnection>& peerConnection =
+ std::shared_ptr<PeerConnection>());
virtual ~PeerInteractionCommand();
};
diff --git a/src/PeerListenCommand.cc b/src/PeerListenCommand.cc
index 75044680..c70a8590 100644
--- a/src/PeerListenCommand.cc
+++ b/src/PeerListenCommand.cc
@@ -107,13 +107,13 @@ bool PeerListenCommand::execute() {
return true;
}
for(int i = 0; i < 3 && socket_->isReadable(0); ++i) {
- SharedHandle<SocketCore> peerSocket;
+ std::shared_ptr<SocketCore> peerSocket;
try {
peerSocket = socket_->acceptConnection();
std::pair<std::string, uint16_t> peerInfo;
peerSocket->getPeerInfo(peerInfo);
- SharedHandle<Peer> peer(new Peer(peerInfo.first, peerInfo.second, true));
+ std::shared_ptr<Peer> peer(new Peer(peerInfo.first, peerInfo.second, true));
cuid_t cuid = e_->newCUID();
Command* command =
new ReceiverMSEHandshakeCommand(cuid, peer, e_, peerSocket);
diff --git a/src/PeerListenCommand.h b/src/PeerListenCommand.h
index e061bf54..fa59cfdd 100644
--- a/src/PeerListenCommand.h
+++ b/src/PeerListenCommand.h
@@ -36,7 +36,9 @@
#define D_PEER_LISTEN_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "SegList.h"
namespace aria2 {
@@ -48,7 +50,7 @@ class PeerListenCommand : public Command {
private:
DownloadEngine* e_;
int family_;
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<SocketCore> socket_;
public:
PeerListenCommand(cuid_t cuid, DownloadEngine* e, int family);
diff --git a/src/PeerReceiveHandshakeCommand.cc b/src/PeerReceiveHandshakeCommand.cc
index b93e049d..5cdd51c3 100644
--- a/src/PeerReceiveHandshakeCommand.cc
+++ b/src/PeerReceiveHandshakeCommand.cc
@@ -63,10 +63,10 @@ namespace aria2 {
PeerReceiveHandshakeCommand::PeerReceiveHandshakeCommand
(cuid_t cuid,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s,
- const SharedHandle<PeerConnection>& peerConnection)
+ const std::shared_ptr<SocketCore>& s,
+ const std::shared_ptr<PeerConnection>& peerConnection)
: PeerAbstractCommand(cuid, peer, e, s),
peerConnection_(peerConnection)
{
@@ -102,19 +102,19 @@ bool PeerReceiveHandshakeCommand::executeInternal()
// check info_hash
std::string infoHash(&data[28], &data[28+INFO_HASH_LENGTH]);
- SharedHandle<DownloadContext> downloadContext =
+ std::shared_ptr<DownloadContext> downloadContext =
getDownloadEngine()->getBtRegistry()->getDownloadContext(infoHash);
if(!downloadContext) {
throw DL_ABORT_EX
(fmt("Unknown info hash %s",
util::toHex(infoHash).c_str()));
}
- const SharedHandle<BtObject>& btObject =
+ const std::shared_ptr<BtObject>& btObject =
getDownloadEngine()->getBtRegistry()->get
(downloadContext->getOwnerRequestGroup()->getGID());
- const SharedHandle<BtRuntime>& btRuntime = btObject->btRuntime;
- const SharedHandle<PieceStorage>& pieceStorage = btObject->pieceStorage;
- const SharedHandle<PeerStorage>& peerStorage = btObject->peerStorage;
+ const std::shared_ptr<BtRuntime>& btRuntime = btObject->btRuntime;
+ const std::shared_ptr<PieceStorage>& pieceStorage = btObject->pieceStorage;
+ const std::shared_ptr<PeerStorage>& peerStorage = btObject->peerStorage;
if(!btRuntime->ready()) {
throw DL_ABORT_EX
(fmt("Unknown info hash %s",
diff --git a/src/PeerReceiveHandshakeCommand.h b/src/PeerReceiveHandshakeCommand.h
index 4e8a199a..8c0adfff 100644
--- a/src/PeerReceiveHandshakeCommand.h
+++ b/src/PeerReceiveHandshakeCommand.h
@@ -46,18 +46,18 @@ class Peer;
class PeerReceiveHandshakeCommand:public PeerAbstractCommand
{
private:
- SharedHandle<PeerConnection> peerConnection_;
+ std::shared_ptr<PeerConnection> peerConnection_;
protected:
virtual bool executeInternal();
virtual bool exitBeforeExecute();
public:
PeerReceiveHandshakeCommand
(cuid_t cuid,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s,
- const SharedHandle<PeerConnection>& peerConnection =
- SharedHandle<PeerConnection>());
+ const std::shared_ptr<SocketCore>& s,
+ const std::shared_ptr<PeerConnection>& peerConnection =
+ std::shared_ptr<PeerConnection>());
virtual ~PeerReceiveHandshakeCommand();
};
diff --git a/src/PeerStorage.h b/src/PeerStorage.h
index 8db226da..18954d0c 100644
--- a/src/PeerStorage.h
+++ b/src/PeerStorage.h
@@ -40,8 +40,8 @@
#include <deque>
#include <vector>
#include <set>
+#include <memory>
-#include "SharedHandle.h"
#include "TransferStat.h"
#include "Command.h"
#include "a2functional.h"
@@ -50,7 +50,7 @@ namespace aria2 {
class Peer;
-typedef std::set<SharedHandle<Peer>, RefLess<Peer> > PeerSet;
+typedef std::set<std::shared_ptr<Peer>, RefLess<Peer> > PeerSet;
class PeerStorage {
public:
@@ -60,12 +60,12 @@ public:
* Adds new peer to the internal peer list.
* If the peer is added successfully, returns true. Otherwise returns false.
*/
- virtual bool addPeer(const SharedHandle<Peer>& peer) = 0;
+ virtual bool addPeer(const std::shared_ptr<Peer>& peer) = 0;
/**
* Adds all peers in peers to internal peer list.
*/
- virtual void addPeer(const std::vector<SharedHandle<Peer> >& peers) = 0;
+ virtual void addPeer(const std::vector<std::shared_ptr<Peer> >& peers) = 0;
/**
* Returns the number of peers, including used and unused ones.
@@ -75,7 +75,7 @@ public:
/**
* Returns internal dropped peer list.
*/
- virtual const std::deque<SharedHandle<Peer> >& getDroppedPeers() = 0;
+ virtual const std::deque<std::shared_ptr<Peer> >& getDroppedPeers() = 0;
/**
* Returns true if at least one unused peer exists.
@@ -102,14 +102,14 @@ public:
/**
* Moves first peer in unused peer list to used peer set and calls
* Peer::usedBy(cuid). If there is no peer available, returns
- * SharedHandle<Peer>().
+ * std::shared_ptr<Peer>().
*/
- virtual SharedHandle<Peer> checkoutPeer(cuid_t cuid) = 0;
+ virtual std::shared_ptr<Peer> checkoutPeer(cuid_t cuid) = 0;
/**
* Tells PeerStorage object that peer is no longer used in the session.
*/
- virtual void returnPeer(const SharedHandle<Peer>& peer) = 0;
+ virtual void returnPeer(const std::shared_ptr<Peer>& peer) = 0;
virtual bool chokeRoundIntervalElapsed() = 0;
diff --git a/src/Piece.cc b/src/Piece.cc
index d2751da7..521788f2 100644
--- a/src/Piece.cc
+++ b/src/Piece.cc
@@ -33,6 +33,9 @@
*/
/* copyright --> */
#include "Piece.h"
+
+#include <cassert>
+
#include "util.h"
#include "BitfieldMan.h"
#include "A2STR.h"
@@ -242,8 +245,8 @@ std::string Piece::getDigest()
}
namespace {
-void updateHashWithRead(const SharedHandle<MessageDigest>& mdctx,
- const SharedHandle<DiskAdaptor>& adaptor,
+void updateHashWithRead(const std::shared_ptr<MessageDigest>& mdctx,
+ const std::shared_ptr<DiskAdaptor>& adaptor,
int64_t offset, size_t len)
{
const size_t BUFSIZE = 4096;
@@ -269,9 +272,9 @@ void updateHashWithRead(const SharedHandle<MessageDigest>& mdctx,
} // namespace
std::string Piece::getDigestWithWrCache
-(size_t pieceLength, const SharedHandle<DiskAdaptor>& adaptor)
+(size_t pieceLength, const std::shared_ptr<DiskAdaptor>& adaptor)
{
- SharedHandle<MessageDigest> mdctx(MessageDigest::create(hashType_));
+ std::shared_ptr<MessageDigest> mdctx(MessageDigest::create(hashType_));
int64_t start = static_cast<int64_t>(index_)*pieceLength;
int64_t goff = start;
if(wrCache_) {
@@ -317,7 +320,7 @@ void Piece::removeUser(cuid_t cuid)
}
void Piece::initWrCache(WrDiskCache* diskCache,
- const SharedHandle<DiskAdaptor>& diskAdaptor)
+ const std::shared_ptr<DiskAdaptor>& diskAdaptor)
{
if(!diskCache) {
return;
diff --git a/src/Piece.h b/src/Piece.h
index ca3573ee..bdba7dd2 100644
--- a/src/Piece.h
+++ b/src/Piece.h
@@ -40,8 +40,8 @@
#include <stdint.h>
#include <vector>
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "Command.h"
namespace aria2 {
@@ -72,7 +72,7 @@ private:
std::string hashType_;
- SharedHandle<MessageDigest> mdctx_;
+ std::shared_ptr<MessageDigest> mdctx_;
#endif // ENABLE_MESSAGE_DIGEST
@@ -179,7 +179,7 @@ public:
// Returns raw hash value, not hex digest, which is calculated using
// cached data and data on disk.
std::string getDigestWithWrCache(size_t pieceLength,
- const SharedHandle<DiskAdaptor>& adaptor);
+ const std::shared_ptr<DiskAdaptor>& adaptor);
#endif // ENABLE_MESSAGE_DIGEST
/**
@@ -204,7 +204,7 @@ public:
}
void initWrCache(WrDiskCache* diskCache,
- const SharedHandle<DiskAdaptor>& diskAdaptor);
+ const std::shared_ptr<DiskAdaptor>& diskAdaptor);
void flushWrCache(WrDiskCache* diskCache);
void clearWrCache(WrDiskCache* diskCache);
void updateWrCache(WrDiskCache* diskCache, unsigned char* data,
diff --git a/src/PieceHashCheckIntegrityEntry.cc b/src/PieceHashCheckIntegrityEntry.cc
index 7af39539..f4e12010 100644
--- a/src/PieceHashCheckIntegrityEntry.cc
+++ b/src/PieceHashCheckIntegrityEntry.cc
@@ -49,7 +49,7 @@ PieceHashCheckIntegrityEntry::~PieceHashCheckIntegrityEntry() {}
bool PieceHashCheckIntegrityEntry::isValidationReady()
{
- const SharedHandle<DownloadContext>& dctx =
+ const std::shared_ptr<DownloadContext>& dctx =
getRequestGroup()->getDownloadContext();
return dctx->isPieceHashVerificationAvailable();
}
@@ -57,7 +57,7 @@ bool PieceHashCheckIntegrityEntry::isValidationReady()
void PieceHashCheckIntegrityEntry::initValidator()
{
#ifdef ENABLE_MESSAGE_DIGEST
- SharedHandle<IteratableChunkChecksumValidator> validator
+ std::shared_ptr<IteratableChunkChecksumValidator> validator
(new IteratableChunkChecksumValidator
(getRequestGroup()->getDownloadContext(),
getRequestGroup()->getPieceStorage()));
diff --git a/src/PieceStatMan.h b/src/PieceStatMan.h
index 96ea824b..dd70c125 100644
--- a/src/PieceStatMan.h
+++ b/src/PieceStatMan.h
@@ -39,8 +39,6 @@
#include <vector>
-#include "SharedHandle.h"
-
namespace aria2 {
class PieceStatMan {
diff --git a/src/PieceStorage.h b/src/PieceStorage.h
index 14b7160a..06bccb50 100644
--- a/src/PieceStorage.h
+++ b/src/PieceStorage.h
@@ -39,8 +39,8 @@
#include <string>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
#include "Command.h"
@@ -62,7 +62,7 @@ public:
* Returns true if the peer has a piece that localhost doesn't have.
* Otherwise returns false.
*/
- virtual bool hasMissingPiece(const SharedHandle<Peer>& peer) = 0;
+ virtual bool hasMissingPiece(const std::shared_ptr<Peer>& peer) = 0;
// Stores pieces that the peer has but localhost doesn't. Those
// pieces will be marked "used" status in order to prevent other
@@ -73,17 +73,17 @@ public:
// pieces is greater than or equal to minMissingBlocks. If there is
// M missing pieces left where M < N, M pieces are stored.
virtual void getMissingPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
cuid_t cuid) = 0;
// Same as getMissingPiece(pieces, minMissingBlocks, peer), but the
// indexes in excludedIndexes are excluded.
virtual void getMissingPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid) = 0;
@@ -97,17 +97,17 @@ public:
// greater than or equal to minMissingBlocks. If there is M missing
// pieces left where M < N, M pieces are stored.
virtual void getMissingFastPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
cuid_t cuid) = 0;
// Same as getMissingFastPiece(pieces, minMissingBlocks, peer), but
// the indexes in excludedIndexes are excluded.
virtual void getMissingFastPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid) = 0;
@@ -117,15 +117,15 @@ public:
* from get the same piece. But in end game mode, same piece may be returned
* to several commands.
*/
- virtual SharedHandle<Piece>
- getMissingPiece(const SharedHandle<Peer>& peer, cuid_t cuid) = 0;
+ virtual std::shared_ptr<Piece>
+ getMissingPiece(const std::shared_ptr<Peer>& peer, cuid_t cuid) = 0;
/**
- * Same as getMissingPiece(const SharedHandle<Peer>& peer), but the indexes in
+ * Same as getMissingPiece(const std::shared_ptr<Peer>& peer), but the indexes in
* excludedIndexes are excluded.
*/
- virtual SharedHandle<Piece> getMissingPiece
- (const SharedHandle<Peer>& peer,
+ virtual std::shared_ptr<Piece> getMissingPiece
+ (const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid) = 0;
#endif // ENABLE_BITTORRENT
@@ -137,7 +137,7 @@ public:
* Returns a missing piece if available. Otherwise returns 0;
* If ignoreBitfield is set, indexes of true bit are excluded.
*/
- virtual SharedHandle<Piece> getMissingPiece
+ virtual std::shared_ptr<Piece> getMissingPiece
(size_t minSplitSize,
const unsigned char* ignoreBitfield,
size_t length,
@@ -149,13 +149,13 @@ public:
* then returns 0.
* Also returns 0 if any of missing piece is not available.
*/
- virtual SharedHandle<Piece> getMissingPiece(size_t index, cuid_t cuid) = 0;
+ virtual std::shared_ptr<Piece> getMissingPiece(size_t index, cuid_t cuid) = 0;
/**
* Returns the piece denoted by index.
* No status of the piece is changed in this method.
*/
- virtual SharedHandle<Piece> getPiece(size_t index) = 0;
+ virtual std::shared_ptr<Piece> getPiece(size_t index) = 0;
/**
* Marks the piece whose index is index as missing.
@@ -165,12 +165,12 @@ public:
/**
* Tells that the download of the specfied piece completes.
*/
- virtual void completePiece(const SharedHandle<Piece>& piece) = 0;
+ virtual void completePiece(const std::shared_ptr<Piece>& piece) = 0;
/**
* Tells that the download of the specified piece is canceled.
*/
- virtual void cancelPiece(const SharedHandle<Piece>& piece, cuid_t cuid) = 0;
+ virtual void cancelPiece(const std::shared_ptr<Piece>& piece, cuid_t cuid) = 0;
/**
* Returns true if the specified piece is already downloaded.
@@ -227,7 +227,7 @@ public:
// TODO We can remove this.
virtual void setEndGamePieceNum(size_t num) = 0;
- virtual SharedHandle<DiskAdaptor> getDiskAdaptor() = 0;
+ virtual std::shared_ptr<DiskAdaptor> getDiskAdaptor() = 0;
virtual WrDiskCache* getWrDiskCache() = 0;
@@ -267,11 +267,11 @@ public:
virtual void markPiecesDone(int64_t length) = 0;
virtual void
- addInFlightPiece(const std::vector<SharedHandle<Piece> >& pieces) = 0;
+ addInFlightPiece(const std::vector<std::shared_ptr<Piece> >& pieces) = 0;
virtual size_t countInFlightPiece() = 0;
- virtual void getInFlightPieces(std::vector<SharedHandle<Piece> >& pieces) = 0;
+ virtual void getInFlightPieces(std::vector<std::shared_ptr<Piece> >& pieces) = 0;
virtual void addPieceStats(size_t index) = 0;
diff --git a/src/PiecedSegment.cc b/src/PiecedSegment.cc
index ab100d9a..e1ebcdde 100644
--- a/src/PiecedSegment.cc
+++ b/src/PiecedSegment.cc
@@ -39,7 +39,7 @@
namespace aria2 {
PiecedSegment::PiecedSegment
-(int32_t pieceLength, const SharedHandle<Piece>& piece)
+(int32_t pieceLength, const std::shared_ptr<Piece>& piece)
: piece_(piece),
pieceLength_(pieceLength)
{
@@ -124,7 +124,7 @@ void PiecedSegment::clear(WrDiskCache* diskCache)
#endif // ENABLE_MESSAGE_DIGEST
}
-SharedHandle<Piece> PiecedSegment::getPiece() const
+std::shared_ptr<Piece> PiecedSegment::getPiece() const
{
return piece_;
}
diff --git a/src/PiecedSegment.h b/src/PiecedSegment.h
index 94d423d4..4e7fda31 100644
--- a/src/PiecedSegment.h
+++ b/src/PiecedSegment.h
@@ -41,7 +41,7 @@ namespace aria2 {
class PiecedSegment:public Segment {
private:
- SharedHandle<Piece> piece_;
+ std::shared_ptr<Piece> piece_;
/**
* Piece class has length property but it is a actual length of piece.
* The last piece likely have shorter length than the other length.
@@ -50,7 +50,7 @@ private:
int32_t writtenLength_;
public:
- PiecedSegment(int32_t pieceLength, const SharedHandle<Piece>& piece);
+ PiecedSegment(int32_t pieceLength, const std::shared_ptr<Piece>& piece);
virtual ~PiecedSegment();
@@ -92,7 +92,7 @@ public:
virtual void clear(WrDiskCache* diskCache);
- virtual SharedHandle<Piece> getPiece() const;
+ virtual std::shared_ptr<Piece> getPiece() const;
};
} // namespace aria2
diff --git a/src/PollEventPoll.cc b/src/PollEventPoll.cc
index ba4f479b..eee58e4c 100644
--- a/src/PollEventPoll.cc
+++ b/src/PollEventPoll.cc
@@ -96,7 +96,7 @@ void PollEventPoll::poll(const struct timeval& tv)
while((res = ::poll(pollfds_, pollfdNum_, timeout)) == -1 &&
errno == EINTR);
if(res > 0) {
- SharedHandle<KSocketEntry> se(new KSocketEntry(0));
+ std::shared_ptr<KSocketEntry> se(new KSocketEntry(0));
for(struct pollfd* first = pollfds_, *last = pollfds_+pollfdNum_;
first != last; ++first) {
if(first->revents) {
@@ -152,7 +152,7 @@ int PollEventPoll::translateEvents(EventPoll::EventType events)
bool PollEventPoll::addEvents
(sock_t socket, const PollEventPoll::KEvent& event)
{
- SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
+ std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
KSocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.addSelf(*i);
@@ -189,7 +189,7 @@ bool PollEventPoll::addEvents
#ifdef ENABLE_ASYNC_DNS
bool PollEventPoll::addEvents
(sock_t socket, Command* command, int events,
- const SharedHandle<AsyncNameResolver>& rs)
+ const std::shared_ptr<AsyncNameResolver>& rs)
{
return addEvents(socket, KADNSEvent(rs, command, socket, events));
}
@@ -198,7 +198,7 @@ bool PollEventPoll::addEvents
bool PollEventPoll::deleteEvents
(sock_t socket, const PollEventPoll::KEvent& event)
{
- SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
+ std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
KSocketEntrySet::iterator i = socketEntries_.find(socketEntry);
if(i == socketEntries_.end()) {
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
@@ -226,7 +226,7 @@ bool PollEventPoll::deleteEvents
#ifdef ENABLE_ASYNC_DNS
bool PollEventPoll::deleteEvents
-(sock_t socket, Command* command, const SharedHandle<AsyncNameResolver>& rs)
+(sock_t socket, Command* command, const std::shared_ptr<AsyncNameResolver>& rs)
{
return deleteEvents(socket, KADNSEvent(rs, command, socket, 0));
}
@@ -241,9 +241,9 @@ bool PollEventPoll::deleteEvents
#ifdef ENABLE_ASYNC_DNS
bool PollEventPoll::addNameResolver
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
- SharedHandle<KAsyncNameResolverEntry> entry
+ std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
KAsyncNameResolverEntrySet::iterator itr =
nameResolverEntries_.lower_bound(entry);
@@ -257,9 +257,9 @@ bool PollEventPoll::addNameResolver
}
bool PollEventPoll::deleteNameResolver
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
- SharedHandle<KAsyncNameResolverEntry> entry
+ std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
if(itr == nameResolverEntries_.end()) {
diff --git a/src/PollEventPoll.h b/src/PollEventPoll.h
index af4de886..730a7da6 100644
--- a/src/PollEventPoll.h
+++ b/src/PollEventPoll.h
@@ -70,12 +70,12 @@ private:
friend int accumulateEvent(int events, const KEvent& event);
private:
- typedef std::set<SharedHandle<KSocketEntry>,
- DerefLess<SharedHandle<KSocketEntry> > > KSocketEntrySet;
+ typedef std::set<std::shared_ptr<KSocketEntry>,
+ DerefLess<std::shared_ptr<KSocketEntry> > > KSocketEntrySet;
KSocketEntrySet socketEntries_;
#ifdef ENABLE_ASYNC_DNS
- typedef std::set<SharedHandle<KAsyncNameResolverEntry>,
- DerefLess<SharedHandle<KAsyncNameResolverEntry> > >
+ typedef std::set<std::shared_ptr<KAsyncNameResolverEntry>,
+ DerefLess<std::shared_ptr<KAsyncNameResolverEntry> > >
KAsyncNameResolverEntrySet;
KAsyncNameResolverEntrySet nameResolverEntries_;
#endif // ENABLE_ASYNC_DNS
@@ -93,10 +93,10 @@ private:
bool deleteEvents(sock_t socket, const KEvent& event);
bool addEvents(sock_t socket, Command* command, int events,
- const SharedHandle<AsyncNameResolver>& rs);
+ const std::shared_ptr<AsyncNameResolver>& rs);
bool deleteEvents(sock_t socket, Command* command,
- const SharedHandle<AsyncNameResolver>& rs);
+ const std::shared_ptr<AsyncNameResolver>& rs);
static int translateEvents(EventPoll::EventType events);
public:
@@ -113,10 +113,10 @@ public:
Command* command, EventPoll::EventType events);
#ifdef ENABLE_ASYNC_DNS
- virtual bool addNameResolver(const SharedHandle<AsyncNameResolver>& resolver,
+ virtual bool addNameResolver(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command);
virtual bool deleteNameResolver
- (const SharedHandle<AsyncNameResolver>& resolver, Command* command);
+ (const std::shared_ptr<AsyncNameResolver>& resolver, Command* command);
#endif // ENABLE_ASYNC_DNS
static const int IEV_READ = POLLIN;
diff --git a/src/PortEventPoll.cc b/src/PortEventPoll.cc
index 577fe074..0610cd97 100644
--- a/src/PortEventPoll.cc
+++ b/src/PortEventPoll.cc
@@ -174,7 +174,7 @@ int translateEvents(EventPoll::EventType events)
bool PortEventPoll::addEvents(sock_t socket,
const PortEventPoll::KEvent& event)
{
- SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
+ std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
KSocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
int r = 0;
int errNum = 0;
@@ -215,7 +215,7 @@ bool PortEventPoll::addEvents(sock_t socket, Command* command,
#ifdef ENABLE_ASYNC_DNS
bool PortEventPoll::addEvents(sock_t socket, Command* command, int events,
- const SharedHandle<AsyncNameResolver>& rs)
+ const std::shared_ptr<AsyncNameResolver>& rs)
{
return addEvents(socket, KADNSEvent(rs, command, socket, events));
}
@@ -224,7 +224,7 @@ bool PortEventPoll::addEvents(sock_t socket, Command* command, int events,
bool PortEventPoll::deleteEvents(sock_t socket,
const PortEventPoll::KEvent& event)
{
- SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
+ std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
KSocketEntrySet::iterator i = socketEntries_.find(socketEntry);
if(i == socketEntries_.end()) {
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
@@ -255,7 +255,7 @@ bool PortEventPoll::deleteEvents(sock_t socket,
#ifdef ENABLE_ASYNC_DNS
bool PortEventPoll::deleteEvents(sock_t socket, Command* command,
- const SharedHandle<AsyncNameResolver>& rs)
+ const std::shared_ptr<AsyncNameResolver>& rs)
{
return deleteEvents(socket, KADNSEvent(rs, command, socket, 0));
}
@@ -270,9 +270,9 @@ bool PortEventPoll::deleteEvents(sock_t socket, Command* command,
#ifdef ENABLE_ASYNC_DNS
bool PortEventPoll::addNameResolver
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
- SharedHandle<KAsyncNameResolverEntry> entry
+ std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
if(itr == nameResolverEntries_.end()) {
@@ -285,9 +285,9 @@ bool PortEventPoll::addNameResolver
}
bool PortEventPoll::deleteNameResolver
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
- SharedHandle<KAsyncNameResolverEntry> entry
+ std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
if(itr == nameResolverEntries_.end()) {
diff --git a/src/PortEventPoll.h b/src/PortEventPoll.h
index ad4a4364..3f25e3dd 100644
--- a/src/PortEventPoll.h
+++ b/src/PortEventPoll.h
@@ -77,12 +77,12 @@ private:
friend int accumulateEvent(int events, const KEvent& event);
private:
- typedef std::set<SharedHandle<KSocketEntry>,
- DerefLess<SharedHandle<KSocketEntry> > > KSocketEntrySet;
+ typedef std::set<std::shared_ptr<KSocketEntry>,
+ DerefLess<std::shared_ptr<KSocketEntry> > > KSocketEntrySet;
KSocketEntrySet socketEntries_;
#ifdef ENABLE_ASYNC_DNS
- typedef std::set<SharedHandle<KAsyncNameResolverEntry>,
- DerefLess<SharedHandle<KAsyncNameResolverEntry> > >
+ typedef std::set<std::shared_ptr<KAsyncNameResolverEntry>,
+ DerefLess<std::shared_ptr<KAsyncNameResolverEntry> > >
KAsyncNameResolverEntrySet;
KAsyncNameResolverEntrySet nameResolverEntries_;
#endif // ENABLE_ASYNC_DNS
@@ -100,10 +100,10 @@ private:
bool deleteEvents(sock_t socket, const KEvent& event);
bool addEvents(sock_t socket, Command* command, int events,
- const SharedHandle<AsyncNameResolver>& rs);
+ const std::shared_ptr<AsyncNameResolver>& rs);
bool deleteEvents(sock_t socket, Command* command,
- const SharedHandle<AsyncNameResolver>& rs);
+ const std::shared_ptr<AsyncNameResolver>& rs);
public:
PortEventPoll();
@@ -121,10 +121,10 @@ public:
Command* command, EventPoll::EventType events);
#ifdef ENABLE_ASYNC_DNS
- virtual bool addNameResolver(const SharedHandle<AsyncNameResolver>& resolver,
+ virtual bool addNameResolver(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command);
virtual bool deleteNameResolver
- (const SharedHandle<AsyncNameResolver>& resolver, Command* command);
+ (const std::shared_ptr<AsyncNameResolver>& resolver, Command* command);
#endif // ENABLE_ASYNC_DNS
static const int IEV_READ = POLLIN;
diff --git a/src/PostDownloadHandler.h b/src/PostDownloadHandler.h
index e89b14d1..fe21dbfc 100644
--- a/src/PostDownloadHandler.h
+++ b/src/PostDownloadHandler.h
@@ -49,7 +49,7 @@ public:
virtual ~PostDownloadHandler() {}
virtual void
- getNextRequestGroups(std::vector<SharedHandle<RequestGroup> >& groups,
+ getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
RequestGroup* requestGroup) = 0;
};
diff --git a/src/PriorityPieceSelector.cc b/src/PriorityPieceSelector.cc
index eb03ed56..98ff96b7 100644
--- a/src/PriorityPieceSelector.cc
+++ b/src/PriorityPieceSelector.cc
@@ -38,7 +38,7 @@
namespace aria2 {
PriorityPieceSelector::PriorityPieceSelector
-(const SharedHandle<PieceSelector>& selector):
+(const std::shared_ptr<PieceSelector>& selector):
selector_(selector) {}
bool PriorityPieceSelector::select
diff --git a/src/PriorityPieceSelector.h b/src/PriorityPieceSelector.h
index 5401747d..8360af56 100644
--- a/src/PriorityPieceSelector.h
+++ b/src/PriorityPieceSelector.h
@@ -38,8 +38,7 @@
#include "PieceSelector.h"
#include <vector>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -47,9 +46,9 @@ class PriorityPieceSelector:public PieceSelector {
private:
std::vector<size_t> prioritizedPieces_;
- SharedHandle<PieceSelector> selector_;
+ std::shared_ptr<PieceSelector> selector_;
public:
- PriorityPieceSelector(const SharedHandle<PieceSelector>& selector);
+ PriorityPieceSelector(const std::shared_ptr<PieceSelector>& selector);
virtual bool select
(size_t& index, const unsigned char* bitfield, size_t nbits) const;
diff --git a/src/RarestPieceSelector.cc b/src/RarestPieceSelector.cc
index 3cc78077..a561c34f 100644
--- a/src/RarestPieceSelector.cc
+++ b/src/RarestPieceSelector.cc
@@ -43,7 +43,7 @@
namespace aria2 {
RarestPieceSelector::RarestPieceSelector
-(const SharedHandle<PieceStatMan>& pieceStatMan):pieceStatMan_(pieceStatMan) {}
+(const std::shared_ptr<PieceStatMan>& pieceStatMan):pieceStatMan_(pieceStatMan) {}
bool RarestPieceSelector::select
(size_t& index, const unsigned char* bitfield, size_t nbits) const
diff --git a/src/RarestPieceSelector.h b/src/RarestPieceSelector.h
index 4496e602..91abe956 100644
--- a/src/RarestPieceSelector.h
+++ b/src/RarestPieceSelector.h
@@ -36,7 +36,8 @@
#define D_RAREST_PIECE_SELECTOR_H
#include "PieceSelector.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -44,9 +45,9 @@ class PieceStatMan;
class RarestPieceSelector:public PieceSelector {
private:
- SharedHandle<PieceStatMan> pieceStatMan_;
+ std::shared_ptr<PieceStatMan> pieceStatMan_;
public:
- RarestPieceSelector(const SharedHandle<PieceStatMan>& pieceStatMan);
+ RarestPieceSelector(const std::shared_ptr<PieceStatMan>& pieceStatMan);
virtual bool select
(size_t& index, const unsigned char* bitfield, size_t nbits) const;
diff --git a/src/ReceiverMSEHandshakeCommand.cc b/src/ReceiverMSEHandshakeCommand.cc
index e64e591e..c458a924 100644
--- a/src/ReceiverMSEHandshakeCommand.cc
+++ b/src/ReceiverMSEHandshakeCommand.cc
@@ -55,9 +55,9 @@ namespace aria2 {
ReceiverMSEHandshakeCommand::ReceiverMSEHandshakeCommand
(cuid_t cuid,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s):
+ const std::shared_ptr<SocketCore>& s):
PeerAbstractCommand(cuid, peer, e, s),
sequence_(RECEIVER_IDENTIFY_HANDSHAKE),
@@ -103,7 +103,7 @@ bool ReceiverMSEHandshakeCommand::executeInternal()
("The legacy BitTorrent handshake is not acceptable by the"
" preference.");
}
- SharedHandle<PeerConnection> peerConnection
+ std::shared_ptr<PeerConnection> peerConnection
(new PeerConnection(getCuid(), getPeer(), getSocket()));
peerConnection->presetBuffer(mseHandshake_->getBuffer(),
mseHandshake_->getBufferLength());
@@ -145,7 +145,7 @@ bool ReceiverMSEHandshakeCommand::executeInternal()
break;
}
case RECEIVER_RECEIVE_PAD_C_LENGTH: {
- std::vector<SharedHandle<DownloadContext> > downloadContexts;
+ std::vector<std::shared_ptr<DownloadContext> > downloadContexts;
getDownloadEngine()->getBtRegistry()->getAllDownloadContext
(std::back_inserter(downloadContexts));
if(mseHandshake_->receiveReceiverHashAndPadCLength(downloadContexts)) {
@@ -206,7 +206,7 @@ bool ReceiverMSEHandshakeCommand::executeInternal()
void ReceiverMSEHandshakeCommand::createCommand()
{
- SharedHandle<PeerConnection> peerConnection
+ std::shared_ptr<PeerConnection> peerConnection
(new PeerConnection(getCuid(), getPeer(), getSocket()));
if(mseHandshake_->getNegotiatedCryptoType() == MSEHandshake::CRYPTO_ARC4) {
peerConnection->enableEncryption(mseHandshake_->getEncryptor(),
diff --git a/src/ReceiverMSEHandshakeCommand.h b/src/ReceiverMSEHandshakeCommand.h
index eb76acc0..a5feea30 100644
--- a/src/ReceiverMSEHandshakeCommand.h
+++ b/src/ReceiverMSEHandshakeCommand.h
@@ -68,9 +68,9 @@ protected:
virtual bool exitBeforeExecute();
public:
ReceiverMSEHandshakeCommand(cuid_t cuid,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& s);
+ const std::shared_ptr<SocketCore>& s);
virtual ~ReceiverMSEHandshakeCommand();
};
diff --git a/src/RecoverableException.cc b/src/RecoverableException.cc
index 546c86eb..75f73b81 100644
--- a/src/RecoverableException.cc
+++ b/src/RecoverableException.cc
@@ -36,9 +36,9 @@
namespace aria2 {
-SharedHandle<Exception> RecoverableException::copy() const
+std::shared_ptr<Exception> RecoverableException::copy() const
{
- SharedHandle<Exception> e(new RecoverableException(*this));
+ std::shared_ptr<Exception> e(new RecoverableException(*this));
return e;
}
diff --git a/src/RecoverableException.h b/src/RecoverableException.h
index 87a6b07e..e5a98d81 100644
--- a/src/RecoverableException.h
+++ b/src/RecoverableException.h
@@ -40,7 +40,7 @@ namespace aria2 {
class RecoverableException:public Exception {
protected:
- virtual SharedHandle<Exception> copy() const;
+ virtual std::shared_ptr<Exception> copy() const;
public:
RecoverableException(const char* file, int line, const std::string& msg);
diff --git a/src/Request.cc b/src/Request.cc
index 6a58c304..ad7b934f 100644
--- a/src/Request.cc
+++ b/src/Request.cc
@@ -158,7 +158,7 @@ void Request::setMaxPipelinedRequest(int num)
maxPipelinedRequest_ = num;
}
-const SharedHandle<PeerStat>& Request::initPeerStat()
+const std::shared_ptr<PeerStat>& Request::initPeerStat()
{
// Use host and protocol in original URI, because URI selector
// selects URI based on original URI, not redirected one.
diff --git a/src/Request.h b/src/Request.h
index ebdad6b3..24850584 100644
--- a/src/Request.h
+++ b/src/Request.h
@@ -37,8 +37,8 @@
#include "common.h"
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
#include "uri.h"
@@ -73,7 +73,7 @@ private:
bool pipeliningHint_;
// maximum number of pipelined requests
int maxPipelinedRequest_;
- SharedHandle<PeerStat> peerStat_;
+ std::shared_ptr<PeerStat> peerStat_;
bool removalRequested_;
uint16_t connectedPort_;
Timer wakeTime_;
@@ -176,12 +176,12 @@ public:
return method_;
}
- const SharedHandle<PeerStat>& getPeerStat() const
+ const std::shared_ptr<PeerStat>& getPeerStat() const
{
return peerStat_;
}
- const SharedHandle<PeerStat>& initPeerStat();
+ const std::shared_ptr<PeerStat>& initPeerStat();
void requestRemoval()
{
diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc
index 1491981d..d62c8431 100644
--- a/src/RequestGroup.cc
+++ b/src/RequestGroup.cc
@@ -120,8 +120,8 @@
namespace aria2 {
-RequestGroup::RequestGroup(const SharedHandle<GroupId>& gid,
- const SharedHandle<Option>& option)
+RequestGroup::RequestGroup(const std::shared_ptr<GroupId>& gid,
+ const std::shared_ptr<Option>& option)
: gid_(gid),
state_(STATE_WAITING),
option_(option),
@@ -216,12 +216,12 @@ void RequestGroup::closeFile()
// TODO The function name is not intuitive at all.. it does not convey
// that this function open file.
-SharedHandle<CheckIntegrityEntry> RequestGroup::createCheckIntegrityEntry()
+std::shared_ptr<CheckIntegrityEntry> RequestGroup::createCheckIntegrityEntry()
{
- SharedHandle<BtProgressInfoFile> infoFile
+ std::shared_ptr<BtProgressInfoFile> infoFile
(new DefaultBtProgressInfoFile(downloadContext_, pieceStorage_,
option_.get()));
- SharedHandle<CheckIntegrityEntry> checkEntry;
+ std::shared_ptr<CheckIntegrityEntry> checkEntry;
if(option_->getAsBool(PREF_CHECK_INTEGRITY) &&
downloadContext_->isPieceHashVerificationAvailable()) {
// When checking piece hash, we don't care file is downloaded and
@@ -287,14 +287,14 @@ void RequestGroup::createInitialCommand
#ifdef ENABLE_BITTORRENT
{
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
- SharedHandle<TorrentAttribute> torrentAttrs =
+ std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(downloadContext_);
bool metadataGetMode = torrentAttrs->metadata.empty();
if(option_->getAsBool(PREF_DRY_RUN)) {
throw DOWNLOAD_FAILURE_EXCEPTION
("Cancel BitTorrent download in dry-run context.");
}
- SharedHandle<BtRegistry> btRegistry = e->getBtRegistry();
+ std::shared_ptr<BtRegistry> btRegistry = e->getBtRegistry();
if(btRegistry->getDownloadContext(torrentAttrs->infoHash)) {
// TODO If metadataGetMode == false and each FileEntry has
// URI, then go without BT.
@@ -320,7 +320,7 @@ void RequestGroup::createInitialCommand
}
DefaultBtProgressInfoFile* progressInfoFilePtr = 0;
- SharedHandle<BtProgressInfoFile> progressInfoFile;
+ std::shared_ptr<BtProgressInfoFile> progressInfoFile;
if(!metadataGetMode) {
progressInfoFilePtr = new DefaultBtProgressInfoFile(downloadContext_,
pieceStorage_,
@@ -328,7 +328,7 @@ void RequestGroup::createInitialCommand
progressInfoFile.reset(progressInfoFilePtr);
}
- SharedHandle<BtRuntime> btRuntime(new BtRuntime());
+ std::shared_ptr<BtRuntime> btRuntime(new BtRuntime());
btRuntime->setMaxPeers(option_->getAsInt(PREF_BT_MAX_PEERS));
btRuntime_ = btRuntime.get();
if(progressInfoFilePtr) {
@@ -339,7 +339,7 @@ void RequestGroup::createInitialCommand
peerStoragePtr->setBtRuntime(btRuntime);
peerStoragePtr->setPieceStorage(pieceStorage_);
peerStorage_ = peerStoragePtr;
- SharedHandle<PeerStorage> peerStorage(peerStoragePtr);
+ std::shared_ptr<PeerStorage> peerStorage(peerStoragePtr);
if(progressInfoFilePtr) {
progressInfoFilePtr->setPeerStorage(peerStorage);
}
@@ -352,11 +352,11 @@ void RequestGroup::createInitialCommand
btAnnouncePtr->setUserDefinedInterval
(option_->getAsInt(PREF_BT_TRACKER_INTERVAL));
btAnnouncePtr->shuffleAnnounce();
- SharedHandle<BtAnnounce> btAnnounce(btAnnouncePtr);
+ std::shared_ptr<BtAnnounce> btAnnounce(btAnnouncePtr);
assert(!btRegistry->get(gid_->getNumericId()));
btRegistry->put
- (gid_->getNumericId(), SharedHandle<BtObject>
+ (gid_->getNumericId(), std::shared_ptr<BtObject>
(new BtObject
(downloadContext_,
pieceStorage_,
@@ -385,7 +385,7 @@ void RequestGroup::createInitialCommand
" recommended. See --enable-dht option."));
}
- SharedHandle<CheckIntegrityEntry> entry
+ std::shared_ptr<CheckIntegrityEntry> entry
(new BtCheckIntegrityEntry(this));
entry->onDownloadIncomplete(commands, e);
@@ -463,7 +463,7 @@ void RequestGroup::createInitialCommand
e->addCommand(command);
}
}
- SharedHandle<CheckIntegrityEntry> entry(new BtCheckIntegrityEntry(this));
+ std::shared_ptr<CheckIntegrityEntry> entry(new BtCheckIntegrityEntry(this));
// --bt-seed-unverified=true is given and download has completed, skip
// validation for piece hashes.
if(option_->getAsBool(PREF_BT_SEED_UNVERIFIED) &&
@@ -489,12 +489,12 @@ void RequestGroup::createInitialCommand
downloadContext_->getBasePath().c_str()),
error_code::DUPLICATE_DOWNLOAD);
}
- SharedHandle<BtProgressInfoFile> progressInfoFile
+ std::shared_ptr<BtProgressInfoFile> progressInfoFile
(new DefaultBtProgressInfoFile
- (downloadContext_, SharedHandle<PieceStorage>(), option_.get()));
+ (downloadContext_, std::shared_ptr<PieceStorage>(), option_.get()));
adjustFilename(progressInfoFile);
initPieceStorage();
- SharedHandle<CheckIntegrityEntry> checkEntry =
+ std::shared_ptr<CheckIntegrityEntry> checkEntry =
createCheckIntegrityEntry();
if(checkEntry) {
processCheckIntegrityEntry(commands, checkEntry, e);
@@ -520,7 +520,7 @@ void RequestGroup::createInitialCommand
if(downloadContext_->getFileEntries().size() > 1) {
pieceStorage_->setupFileFilter();
}
- SharedHandle<BtProgressInfoFile> progressInfoFile
+ std::shared_ptr<BtProgressInfoFile> progressInfoFile
(new DefaultBtProgressInfoFile(downloadContext_,
pieceStorage_,
option_.get()));
@@ -547,7 +547,7 @@ void RequestGroup::createInitialCommand
}
}
progressInfoFile_ = progressInfoFile;
- SharedHandle<CheckIntegrityEntry> checkIntegrityEntry
+ std::shared_ptr<CheckIntegrityEntry> checkIntegrityEntry
(new StreamCheckIntegrityEntry(this));
processCheckIntegrityEntry(commands, checkIntegrityEntry, e);
}
@@ -555,7 +555,7 @@ void RequestGroup::createInitialCommand
void RequestGroup::processCheckIntegrityEntry
(std::vector<Command*>& commands,
- const SharedHandle<CheckIntegrityEntry>& entry,
+ const std::shared_ptr<CheckIntegrityEntry>& entry,
DownloadEngine* e)
{
int64_t actualFileSize = pieceStorage_->getDiskAdaptor()->size();
@@ -584,7 +584,7 @@ void RequestGroup::processCheckIntegrityEntry
void RequestGroup::initPieceStorage()
{
- SharedHandle<PieceStorage> tempPieceStorage;
+ std::shared_ptr<PieceStorage> tempPieceStorage;
if(downloadContext_->knowsTotalLength() &&
// Following conditions are needed for chunked encoding with
// content-length = 0. Google's dl server used this before.
@@ -596,7 +596,7 @@ void RequestGroup::initPieceStorage()
#ifdef ENABLE_BITTORRENT
DefaultPieceStorage* ps =
new DefaultPieceStorage(downloadContext_, option_.get());
- SharedHandle<PieceStorage> psHolder(ps);
+ std::shared_ptr<PieceStorage> psHolder(ps);
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
if(isUriSuppliedForRequsetFileEntry
(downloadContext_->getFileEntries().begin(),
@@ -605,7 +605,7 @@ void RequestGroup::initPieceStorage()
// integrated downloads. Currently multi-file integrated
// download is not supported.
A2_LOG_DEBUG("Using LongestSequencePieceSelector");
- SharedHandle<PieceSelector> longestPieceSelector
+ std::shared_ptr<PieceSelector> longestPieceSelector
(new LongestSequencePieceSelector());
ps->setPieceSelector(longestPieceSelector);
}
@@ -618,7 +618,7 @@ void RequestGroup::initPieceStorage()
if(!result.empty()) {
std::random_shuffle(result.begin(), result.end(),
*(SimpleRandomizer::getInstance().get()));
- SharedHandle<PriorityPieceSelector> priSelector
+ std::shared_ptr<PriorityPieceSelector> priSelector
(new PriorityPieceSelector(ps->getPieceSelector()));
priSelector->setPriorityPiece(result.begin(), result.end());
ps->setPieceSelector(priSelector);
@@ -628,7 +628,7 @@ void RequestGroup::initPieceStorage()
#else // !ENABLE_BITTORRENT
DefaultPieceStorage* ps =
new DefaultPieceStorage(downloadContext_, option_.get());
- SharedHandle<PieceStorage> psHolder(ps);
+ std::shared_ptr<PieceStorage> psHolder(ps);
#endif // !ENABLE_BITTORRENT
if(requestGroupMan_) {
ps->setWrDiskCache(requestGroupMan_->getWrDiskCache());
@@ -640,14 +640,14 @@ void RequestGroup::initPieceStorage()
} else {
UnknownLengthPieceStorage* ps =
new UnknownLengthPieceStorage(downloadContext_);
- SharedHandle<PieceStorage> psHolder(ps);
+ std::shared_ptr<PieceStorage> psHolder(ps);
if(diskWriterFactory_) {
ps->setDiskWriterFactory(diskWriterFactory_);
}
tempPieceStorage.swap(psHolder);
}
tempPieceStorage->initStorage();
- SharedHandle<SegmentMan> tempSegmentMan(new SegmentMan(downloadContext_,
+ std::shared_ptr<SegmentMan> tempSegmentMan(new SegmentMan(downloadContext_,
tempPieceStorage));
pieceStorage_.swap(tempPieceStorage);
@@ -679,7 +679,7 @@ bool RequestGroup::downloadFinishedByFileLength()
}
void RequestGroup::adjustFilename
-(const SharedHandle<BtProgressInfoFile>& infoFile)
+(const std::shared_ptr<BtProgressInfoFile>& infoFile)
{
if(!isPreLocalFileCheckEnabled()) {
// OK, no need to care about filename.
@@ -715,7 +715,7 @@ void RequestGroup::adjustFilename
}
void RequestGroup::removeDefunctControlFile
-(const SharedHandle<BtProgressInfoFile>& progressInfoFile)
+(const std::shared_ptr<BtProgressInfoFile>& progressInfoFile)
{
// Remove the control file if download file doesn't exist
if(progressInfoFile->exists() &&
@@ -728,7 +728,7 @@ void RequestGroup::removeDefunctControlFile
}
void RequestGroup::loadAndOpenFile
-(const SharedHandle<BtProgressInfoFile>& progressInfoFile)
+(const std::shared_ptr<BtProgressInfoFile>& progressInfoFile)
{
try {
if(!isPreLocalFileCheckEnabled()) {
@@ -1033,7 +1033,7 @@ void RequestGroup::preDownloadProcessing()
A2_LOG_DEBUG(fmt("Finding PreDownloadHandler for path %s.",
getFirstFilePath().c_str()));
try {
- for(std::vector<SharedHandle<PreDownloadHandler> >::const_iterator itr =
+ for(std::vector<std::shared_ptr<PreDownloadHandler> >::const_iterator itr =
preDownloadHandlers_.begin(), eoi = preDownloadHandlers_.end();
itr != eoi; ++itr) {
if((*itr)->canHandle(this)) {
@@ -1050,12 +1050,12 @@ void RequestGroup::preDownloadProcessing()
}
void RequestGroup::postDownloadProcessing
-(std::vector<SharedHandle<RequestGroup> >& groups)
+(std::vector<std::shared_ptr<RequestGroup> >& groups)
{
A2_LOG_DEBUG(fmt("Finding PostDownloadHandler for path %s.",
getFirstFilePath().c_str()));
try {
- for(std::vector<SharedHandle<PostDownloadHandler> >::const_iterator itr =
+ for(std::vector<std::shared_ptr<PostDownloadHandler> >::const_iterator itr =
postDownloadHandlers_.begin(), eoi = postDownloadHandlers_.end();
itr != eoi; ++itr) {
if((*itr)->canHandle(this)) {
@@ -1107,25 +1107,25 @@ bool RequestGroup::isDependencyResolved()
return dependency_->resolve();
}
-void RequestGroup::dependsOn(const SharedHandle<Dependency>& dep)
+void RequestGroup::dependsOn(const std::shared_ptr<Dependency>& dep)
{
dependency_ = dep;
}
void RequestGroup::setDiskWriterFactory
-(const SharedHandle<DiskWriterFactory>& diskWriterFactory)
+(const std::shared_ptr<DiskWriterFactory>& diskWriterFactory)
{
diskWriterFactory_ = diskWriterFactory;
}
void RequestGroup::addPostDownloadHandler
-(const SharedHandle<PostDownloadHandler>& handler)
+(const std::shared_ptr<PostDownloadHandler>& handler)
{
postDownloadHandlers_.push_back(handler);
}
void RequestGroup::addPreDownloadHandler
-(const SharedHandle<PreDownloadHandler>& handler)
+(const std::shared_ptr<PreDownloadHandler>& handler)
{
preDownloadHandlers_.push_back(handler);
}
@@ -1140,13 +1140,13 @@ void RequestGroup::clearPreDownloadHandler()
preDownloadHandlers_.clear();
}
-void RequestGroup::setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage)
+void RequestGroup::setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
void RequestGroup::setProgressInfoFile
-(const SharedHandle<BtProgressInfoFile>& progressInfoFile)
+(const std::shared_ptr<BtProgressInfoFile>& progressInfoFile)
{
progressInfoFile_ = progressInfoFile;
}
@@ -1158,12 +1158,12 @@ bool RequestGroup::needsFileAllocation() const
!pieceStorage_->getDiskAdaptor()->fileAllocationIterator()->finished();
}
-SharedHandle<DownloadResult> RequestGroup::createDownloadResult() const
+std::shared_ptr<DownloadResult> RequestGroup::createDownloadResult() const
{
A2_LOG_DEBUG(fmt("GID#%s - Creating DownloadResult.",
gid_->toHex().c_str()));
TransferStat st = calculateStat();
- SharedHandle<DownloadResult> res(new DownloadResult());
+ std::shared_ptr<DownloadResult> res(new DownloadResult());
res->gid = gid_;
res->fileEntries = downloadContext_->getFileEntries();
res->inMemoryDownload = inMemoryDownload_;
@@ -1207,7 +1207,7 @@ void RequestGroup::reportDownloadFinished()
int64_t completedLength = getCompletedLength();
double shareRatio = completedLength == 0 ? 0.0 :
1.0*stat.allTimeUploadLength/completedLength;
- SharedHandle<TorrentAttribute> attrs =
+ std::shared_ptr<TorrentAttribute> attrs =
bittorrent::getTorrentAttrs(downloadContext_);
if(!attrs->metadata.empty()) {
A2_LOG_NOTICE(fmt(MSG_SHARE_RATIO_REPORT,
@@ -1219,7 +1219,7 @@ void RequestGroup::reportDownloadFinished()
#endif // ENABLE_BITTORRENT
}
-void RequestGroup::setURISelector(const SharedHandle<URISelector>& uriSelector)
+void RequestGroup::setURISelector(const std::shared_ptr<URISelector>& uriSelector)
{
uriSelector_ = uriSelector;
}
@@ -1290,7 +1290,7 @@ void RequestGroup::removeControlFile() const
}
void RequestGroup::setDownloadContext
-(const SharedHandle<DownloadContext>& downloadContext)
+(const std::shared_ptr<DownloadContext>& downloadContext)
{
downloadContext_ = downloadContext;
if(downloadContext_) {
diff --git a/src/RequestGroup.h b/src/RequestGroup.h
index 7713d4ba..3fe0ce33 100644
--- a/src/RequestGroup.h
+++ b/src/RequestGroup.h
@@ -40,8 +40,8 @@
#include <string>
#include <algorithm>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "TransferStat.h"
#include "TimeA2.h"
#include "Request.h"
@@ -88,11 +88,11 @@ public:
STATE_ACTIVE
};
private:
- SharedHandle<GroupId> gid_;
+ std::shared_ptr<GroupId> gid_;
int state_;
- SharedHandle<Option> option_;
+ std::shared_ptr<Option> option_;
int numConcurrentCommand_;
@@ -105,19 +105,19 @@ private:
int numCommand_;
- SharedHandle<SegmentMan> segmentMan_;
+ std::shared_ptr<SegmentMan> segmentMan_;
- SharedHandle<DownloadContext> downloadContext_;
+ std::shared_ptr<DownloadContext> downloadContext_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
bool saveControlFile_;
- SharedHandle<BtProgressInfoFile> progressInfoFile_;
+ std::shared_ptr<BtProgressInfoFile> progressInfoFile_;
- SharedHandle<DiskWriterFactory> diskWriterFactory_;
+ std::shared_ptr<DiskWriterFactory> diskWriterFactory_;
- SharedHandle<Dependency> dependency_;
+ std::shared_ptr<Dependency> dependency_;
bool fileAllocationEnabled_;
@@ -131,11 +131,11 @@ private:
bool pauseRequested_;
- std::vector<SharedHandle<PreDownloadHandler> > preDownloadHandlers_;
+ std::vector<std::shared_ptr<PreDownloadHandler> > preDownloadHandlers_;
- std::vector<SharedHandle<PostDownloadHandler> > postDownloadHandlers_;
+ std::vector<std::shared_ptr<PostDownloadHandler> > postDownloadHandlers_;
- SharedHandle<URISelector> uriSelector_;
+ std::shared_ptr<URISelector> uriSelector_;
Time lastModifiedTime_;
@@ -172,7 +172,7 @@ private:
// RequestGroup.
a2_gid_t belongsToGID_;
- SharedHandle<MetadataInfo> metadataInfo_;
+ std::shared_ptr<MetadataInfo> metadataInfo_;
RequestGroupMan* requestGroupMan_;
@@ -195,22 +195,22 @@ private:
error_code::Value downloadResult() const;
void removeDefunctControlFile
- (const SharedHandle<BtProgressInfoFile>& progressInfoFile);
+ (const std::shared_ptr<BtProgressInfoFile>& progressInfoFile);
public:
- RequestGroup(const SharedHandle<GroupId>& gid,
- const SharedHandle<Option>& option);
+ RequestGroup(const std::shared_ptr<GroupId>& gid,
+ const std::shared_ptr<Option>& option);
~RequestGroup();
bool isCheckIntegrityReady();
- const SharedHandle<SegmentMan>& getSegmentMan() const
+ const std::shared_ptr<SegmentMan>& getSegmentMan() const
{
return segmentMan_;
}
- SharedHandle<CheckIntegrityEntry> createCheckIntegrityEntry();
+ std::shared_ptr<CheckIntegrityEntry> createCheckIntegrityEntry();
// Returns first bootstrap commands to initiate a download.
// If this is HTTP/FTP download and file size is unknown, only 1 command
@@ -265,30 +265,30 @@ public:
return gid_->getNumericId();
}
- const SharedHandle<GroupId>& getGroupId() const
+ const std::shared_ptr<GroupId>& getGroupId() const
{
return gid_;
}
TransferStat calculateStat() const;
- const SharedHandle<DownloadContext>& getDownloadContext() const
+ const std::shared_ptr<DownloadContext>& getDownloadContext() const
{
return downloadContext_;
}
// This function also calls
// downloadContext->setOwnerRequestGroup(this).
- void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& downloadContext);
- const SharedHandle<PieceStorage>& getPieceStorage() const
+ const std::shared_ptr<PieceStorage>& getPieceStorage() const
{
return pieceStorage_;
}
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
- void setProgressInfoFile(const SharedHandle<BtProgressInfoFile>& progressInfoFile);
+ void setProgressInfoFile(const std::shared_ptr<BtProgressInfoFile>& progressInfoFile);
void increaseStreamCommand();
@@ -310,9 +310,9 @@ public:
}
// TODO is it better to move the following 2 methods to SingleFileDownloadContext?
- void setDiskWriterFactory(const SharedHandle<DiskWriterFactory>& diskWriterFactory);
+ void setDiskWriterFactory(const std::shared_ptr<DiskWriterFactory>& diskWriterFactory);
- const SharedHandle<DiskWriterFactory>& getDiskWriterFactory() const
+ const std::shared_ptr<DiskWriterFactory>& getDiskWriterFactory() const
{
return diskWriterFactory_;
}
@@ -365,26 +365,26 @@ public:
return pauseRequested_;
}
- void dependsOn(const SharedHandle<Dependency>& dep);
+ void dependsOn(const std::shared_ptr<Dependency>& dep);
bool isDependencyResolved();
void releaseRuntimeResource(DownloadEngine* e);
- void postDownloadProcessing(std::vector<SharedHandle<RequestGroup> >& groups);
+ void postDownloadProcessing(std::vector<std::shared_ptr<RequestGroup> >& groups);
- void addPostDownloadHandler(const SharedHandle<PostDownloadHandler>& handler);
+ void addPostDownloadHandler(const std::shared_ptr<PostDownloadHandler>& handler);
void clearPostDownloadHandler();
void preDownloadProcessing();
- void addPreDownloadHandler(const SharedHandle<PreDownloadHandler>& handler);
+ void addPreDownloadHandler(const std::shared_ptr<PreDownloadHandler>& handler);
void clearPreDownloadHandler();
void processCheckIntegrityEntry(std::vector<Command*>& commands,
- const SharedHandle<CheckIntegrityEntry>& entry,
+ const std::shared_ptr<CheckIntegrityEntry>& entry,
DownloadEngine* e);
// Initializes pieceStorage_ and segmentMan_. We guarantee that
@@ -396,24 +396,24 @@ public:
bool downloadFinishedByFileLength();
- void loadAndOpenFile(const SharedHandle<BtProgressInfoFile>& progressInfoFile);
+ void loadAndOpenFile(const std::shared_ptr<BtProgressInfoFile>& progressInfoFile);
void shouldCancelDownloadForSafety();
- void adjustFilename(const SharedHandle<BtProgressInfoFile>& infoFile);
+ void adjustFilename(const std::shared_ptr<BtProgressInfoFile>& infoFile);
- SharedHandle<DownloadResult> createDownloadResult() const;
+ std::shared_ptr<DownloadResult> createDownloadResult() const;
- const SharedHandle<Option>& getOption() const
+ const std::shared_ptr<Option>& getOption() const
{
return option_;
}
void reportDownloadFinished();
- void setURISelector(const SharedHandle<URISelector>& uriSelector);
+ void setURISelector(const std::shared_ptr<URISelector>& uriSelector);
- const SharedHandle<URISelector>& getURISelector() const
+ const std::shared_ptr<URISelector>& getURISelector() const
{
return uriSelector_;
}
@@ -534,12 +534,12 @@ public:
bool p2pInvolved() const;
- void setMetadataInfo(const SharedHandle<MetadataInfo>& info)
+ void setMetadataInfo(const std::shared_ptr<MetadataInfo>& info)
{
metadataInfo_ = info;
}
- const SharedHandle<MetadataInfo>& getMetadataInfo() const
+ const std::shared_ptr<MetadataInfo>& getMetadataInfo() const
{
return metadataInfo_;
}
diff --git a/src/RequestGroupCriteria.h b/src/RequestGroupCriteria.h
index 7cbaa332..7109a589 100644
--- a/src/RequestGroupCriteria.h
+++ b/src/RequestGroupCriteria.h
@@ -36,7 +36,6 @@
#define D_REQUEST_GROUP_CRITERIA_H
#include "common.h"
-#include "SharedHandle.h"
namespace aria2 {
diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc
index 60ededbb..c4b3c683 100644
--- a/src/RequestGroupMan.cc
+++ b/src/RequestGroupMan.cc
@@ -97,7 +97,7 @@ void appendReservedGroup(RequestGroupList& list,
} // namespace
RequestGroupMan::RequestGroupMan
-(const std::vector<SharedHandle<RequestGroup> >& requestGroups,
+(const std::vector<std::shared_ptr<RequestGroup> >& requestGroups,
int maxSimultaneousDownloads,
const Option* option)
: maxSimultaneousDownloads_(maxSimultaneousDownloads),
@@ -132,20 +132,20 @@ bool RequestGroupMan::downloadFinished()
}
void RequestGroupMan::addRequestGroup
-(const SharedHandle<RequestGroup>& group)
+(const std::shared_ptr<RequestGroup>& group)
{
requestGroups_.push_back(group->getGID(), group);
}
void RequestGroupMan::addReservedGroup
-(const std::vector<SharedHandle<RequestGroup> >& groups)
+(const std::vector<std::shared_ptr<RequestGroup> >& groups)
{
requestQueueCheck();
appendReservedGroup(reservedGroups_, groups.begin(), groups.end());
}
void RequestGroupMan::addReservedGroup
-(const SharedHandle<RequestGroup>& group)
+(const std::shared_ptr<RequestGroup>& group)
{
requestQueueCheck();
reservedGroups_.push_back(group->getGID(), group);
@@ -153,7 +153,7 @@ void RequestGroupMan::addReservedGroup
namespace {
struct RequestGroupKeyFunc {
- a2_gid_t operator()(const SharedHandle<RequestGroup>& rg) const
+ a2_gid_t operator()(const std::shared_ptr<RequestGroup>& rg) const
{
return rg->getGID();
}
@@ -161,7 +161,7 @@ struct RequestGroupKeyFunc {
} // namespace
void RequestGroupMan::insertReservedGroup
-(size_t pos, const std::vector<SharedHandle<RequestGroup> >& groups)
+(size_t pos, const std::vector<std::shared_ptr<RequestGroup> >& groups)
{
requestQueueCheck();
pos = std::min(reservedGroups_.size(), pos);
@@ -170,7 +170,7 @@ void RequestGroupMan::insertReservedGroup
}
void RequestGroupMan::insertReservedGroup
-(size_t pos, const SharedHandle<RequestGroup>& group)
+(size_t pos, const std::shared_ptr<RequestGroup>& group)
{
requestQueueCheck();
pos = std::min(reservedGroups_.size(), pos);
@@ -182,9 +182,9 @@ size_t RequestGroupMan::countRequestGroup() const
return requestGroups_.size();
}
-SharedHandle<RequestGroup> RequestGroupMan::findGroup(a2_gid_t gid) const
+std::shared_ptr<RequestGroup> RequestGroupMan::findGroup(a2_gid_t gid) const
{
- SharedHandle<RequestGroup> rg = requestGroups_.get(gid);
+ std::shared_ptr<RequestGroup> rg = requestGroups_.get(gid);
if(!rg) {
rg = reservedGroups_.get(gid);
}
@@ -211,7 +211,7 @@ bool RequestGroupMan::removeReservedGroup(a2_gid_t gid)
namespace {
void notifyDownloadEvent
-(DownloadEvent event, const SharedHandle<RequestGroup>& group)
+(DownloadEvent event, const std::shared_ptr<RequestGroup>& group)
{
// Check NULL to make unit test easier.
if(SingletonHolder<Notifier>::instance()) {
@@ -224,7 +224,7 @@ void notifyDownloadEvent
namespace {
void executeStopHook
-(const SharedHandle<RequestGroup>& group,
+(const std::shared_ptr<RequestGroup>& group,
const Option* option,
error_code::Value result)
{
@@ -256,9 +256,9 @@ private:
DownloadEngine* e_;
RequestGroupList& reservedGroups_;
- void saveSignature(const SharedHandle<RequestGroup>& group)
+ void saveSignature(const std::shared_ptr<RequestGroup>& group)
{
- SharedHandle<Signature> sig =
+ std::shared_ptr<Signature> sig =
group->getDownloadContext()->getSignature();
if(sig && !sig->getBody().empty()) {
// filename of signature file is the path to download file followed by
@@ -274,14 +274,14 @@ private:
// Collect statistics during download in PeerStats and update/register
// ServerStatMan
- void collectStat(const SharedHandle<RequestGroup>& group)
+ void collectStat(const std::shared_ptr<RequestGroup>& group)
{
if(group->getSegmentMan()) {
bool singleConnection =
group->getSegmentMan()->getPeerStats().size() == 1;
- const std::vector<SharedHandle<PeerStat> >& peerStats =
+ const std::vector<std::shared_ptr<PeerStat> >& peerStats =
group->getSegmentMan()->getFastestPeerStats();
- for(std::vector<SharedHandle<PeerStat> >::const_iterator i =
+ for(std::vector<std::shared_ptr<PeerStat> >::const_iterator i =
peerStats.begin(), eoi = peerStats.end(); i != eoi; ++i) {
if((*i)->getHostname().empty() || (*i)->getProtocol().empty()) {
continue;
@@ -289,7 +289,7 @@ private:
int speed = (*i)->getAvgDownloadSpeed();
if (speed == 0) continue;
- SharedHandle<ServerStat> ss =
+ std::shared_ptr<ServerStat> ss =
e_->getRequestGroupMan()->getOrCreateServerStat((*i)->getHostname(),
(*i)->getProtocol());
ss->increaseCounter();
@@ -315,7 +315,7 @@ public:
{
if(group->getNumCommand() == 0) {
collectStat(group);
- const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
+ const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
// DownloadContext::resetDownloadStopTime() is only called when
// download completed. If
// DownloadContext::getDownloadStopTime().isZero() is true, then
@@ -342,7 +342,7 @@ public:
} else {
group->saveControlFile();
}
- std::vector<SharedHandle<RequestGroup> > nextGroups;
+ std::vector<std::shared_ptr<RequestGroup> > nextGroups;
group->postDownloadProcessing(nextGroups);
if(!nextGroups.empty()) {
A2_LOG_DEBUG
@@ -360,9 +360,9 @@ public:
dctx->hasAttribute(CTX_ATTR_BT)) {
A2_LOG_INFO(fmt(MSG_REMOVING_UNSELECTED_FILE,
GroupId::toHex(group->getGID()).c_str()));
- const std::vector<SharedHandle<FileEntry> >& files =
+ const std::vector<std::shared_ptr<FileEntry> >& files =
dctx->getFileEntries();
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
files.begin(), eoi = files.end(); i != eoi; ++i) {
if(!(*i)->isRequested()) {
if(File((*i)->getPath()).remove()) {
@@ -396,7 +396,7 @@ public:
// TODO Should we have to prepend spend uris to remaining uris
// in case PREF_REUSE_URI is disabed?
} else {
- SharedHandle<DownloadResult> dr = group->createDownloadResult();
+ std::shared_ptr<DownloadResult> dr = group->createDownloadResult();
e_->getRequestGroupMan()->addDownloadResult(dr);
executeStopHook(group, e_->getOption(), dr->result);
group->releaseRuntimeResource(e_);
@@ -421,11 +421,11 @@ void RequestGroupMan::removeStoppedGroup(DownloadEngine* e)
}
void RequestGroupMan::configureRequestGroup
-(const SharedHandle<RequestGroup>& requestGroup) const
+(const std::shared_ptr<RequestGroup>& requestGroup) const
{
const std::string& uriSelectorValue =
requestGroup->getOption()->get(PREF_URI_SELECTOR);
- SharedHandle<URISelector> sel;
+ std::shared_ptr<URISelector> sel;
if(uriSelectorValue == V_FEEDBACK) {
sel.reset(new FeedbackURISelector(serverStatMan_));
} else if(uriSelectorValue == V_INORDER) {
@@ -439,7 +439,7 @@ void RequestGroupMan::configureRequestGroup
}
namespace {
-void createInitialCommand(const SharedHandle<RequestGroup>& requestGroup,
+void createInitialCommand(const std::shared_ptr<RequestGroup>& requestGroup,
std::vector<Command*>& commands,
DownloadEngine* e)
{
@@ -455,11 +455,11 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
}
int count = 0;
int num = maxSimultaneousDownloads_-requestGroups_.size();
- std::vector<SharedHandle<RequestGroup> > pending;
+ std::vector<std::shared_ptr<RequestGroup> > pending;
while(count < num && (uriListParser_ || !reservedGroups_.empty())) {
if(uriListParser_ && reservedGroups_.empty()) {
- std::vector<SharedHandle<RequestGroup> > groups;
+ std::vector<std::shared_ptr<RequestGroup> > groups;
// May throw exception
bool ok = createRequestGroupFromUriListParser(groups, option_,
uriListParser_.get());
@@ -472,7 +472,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
}
}
}
- SharedHandle<RequestGroup> groupToAdd = *reservedGroups_.begin();
+ std::shared_ptr<RequestGroup> groupToAdd = *reservedGroups_.begin();
reservedGroups_.pop_front();
if((keepRunning_ && groupToAdd->isPauseRequested()) ||
!groupToAdd->isDependencyResolved()) {
@@ -525,7 +525,7 @@ void RequestGroupMan::save()
{
for(RequestGroupList::iterator itr = requestGroups_.begin(),
eoi = requestGroups_.end(); itr != eoi; ++itr) {
- const SharedHandle<RequestGroup>& rg = *itr;
+ const std::shared_ptr<RequestGroup>& rg = *itr;
if(rg->allDownloadFinished() &&
!rg->getDownloadContext()->isChecksumVerificationNeeded()) {
rg->removeControlFile();
@@ -557,7 +557,7 @@ RequestGroupMan::DownloadStat RequestGroupMan::getDownloadStat() const
for(DownloadResultList::const_iterator itr =
downloadResults_.begin(), eoi = downloadResults_.end(); itr != eoi;
++itr) {
- const SharedHandle<DownloadResult>& dr = *itr;
+ const std::shared_ptr<DownloadResult>& dr = *itr;
if(dr->belongsTo != 0) {
continue;
}
@@ -646,7 +646,7 @@ void RequestGroupMan::showDownloadResults(OutputFile& o, bool full) const
for(DownloadResultList::const_iterator itr =
downloadResults_.begin(), eoi = downloadResults_.end(); itr != eoi;
++itr) {
- const SharedHandle<DownloadResult>& dr = *itr;
+ const std::shared_ptr<DownloadResult>& dr = *itr;
if(dr->belongsTo != 0) {
continue;
}
@@ -697,7 +697,7 @@ namespace {
void formatDownloadResultCommon
(std::ostream& o,
const char* status,
- const SharedHandle<DownloadResult>& downloadResult)
+ const std::shared_ptr<DownloadResult>& downloadResult)
{
o << std::setw(3) << downloadResult->gid->toAbbrevHex() << "|"
<< std::setw(4) << status << "|"
@@ -716,16 +716,16 @@ void formatDownloadResultCommon
void RequestGroupMan::formatDownloadResultFull
(OutputFile& out,
const char* status,
- const SharedHandle<DownloadResult>& downloadResult) const
+ const std::shared_ptr<DownloadResult>& downloadResult) const
{
BitfieldMan bt(downloadResult->pieceLength, downloadResult->totalLength);
bt.setBitfield(reinterpret_cast<const unsigned char*>
(downloadResult->bitfield.data()),
downloadResult->bitfield.size());
bool head = true;
- const std::vector<SharedHandle<FileEntry> >& fileEntries =
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
downloadResult->fileEntries;
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
if(!(*i)->isRequested()) {
continue;
@@ -758,11 +758,11 @@ void RequestGroupMan::formatDownloadResultFull
std::string RequestGroupMan::formatDownloadResult
(const char* status,
- const SharedHandle<DownloadResult>& downloadResult) const
+ const std::shared_ptr<DownloadResult>& downloadResult) const
{
std::stringstream o;
formatDownloadResultCommon(o, status, downloadResult);
- const std::vector<SharedHandle<FileEntry> >& fileEntries =
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
downloadResult->fileEntries;
writeFilePath(fileEntries.begin(), fileEntries.end(), o,
downloadResult->inMemoryDownload);
@@ -795,9 +795,9 @@ bool RequestGroupMan::isSameFileBeingDownloaded(RequestGroup* requestGroup) cons
std::vector<std::string> files;
for(RequestGroupList::const_iterator itr = requestGroups_.begin(),
eoi = requestGroups_.end(); itr != eoi; ++itr) {
- const SharedHandle<RequestGroup>& rg = *itr;
+ const std::shared_ptr<RequestGroup>& rg = *itr;
if(rg.get() != requestGroup) {
- const std::vector<SharedHandle<FileEntry> >& entries =
+ const std::vector<std::shared_ptr<FileEntry> >& entries =
rg->getDownloadContext()->getFileEntries();
std::transform(entries.begin(), entries.end(),
std::back_inserter(files),
@@ -805,7 +805,7 @@ bool RequestGroupMan::isSameFileBeingDownloaded(RequestGroup* requestGroup) cons
}
}
std::sort(files.begin(), files.end());
- const std::vector<SharedHandle<FileEntry> >& entries =
+ const std::vector<std::shared_ptr<FileEntry> >& entries =
requestGroup->getDownloadContext()->getFileEntries();
return sameFilePathExists(files.begin(), files.end(),
entries.begin(), entries.end());
@@ -833,7 +833,7 @@ TransferStat RequestGroupMan::calculateStat()
return netStat_.toTransferStat();
}
-SharedHandle<DownloadResult>
+std::shared_ptr<DownloadResult>
RequestGroupMan::findDownloadResult(a2_gid_t gid) const
{
return downloadResults_.get(gid);
@@ -844,7 +844,7 @@ bool RequestGroupMan::removeDownloadResult(a2_gid_t gid)
return downloadResults_.remove(gid);
}
-void RequestGroupMan::addDownloadResult(const SharedHandle<DownloadResult>& dr)
+void RequestGroupMan::addDownloadResult(const std::shared_ptr<DownloadResult>& dr)
{
bool rv = downloadResults_.push_back(dr->gid->getNumericId(), dr);
assert(rv);
@@ -852,7 +852,7 @@ void RequestGroupMan::addDownloadResult(const SharedHandle<DownloadResult>& dr)
DownloadResultList::iterator i = downloadResults_.begin();
// Save last encountered error code so that we can report it
// later.
- const SharedHandle<DownloadResult>& dr = *i;
+ const std::shared_ptr<DownloadResult>& dr = *i;
if(dr->belongsTo == 0 && dr->result != error_code::FINISHED) {
removedLastErrorResult_ = dr->result;
++removedErrorResult_;
@@ -866,18 +866,18 @@ void RequestGroupMan::purgeDownloadResult()
downloadResults_.clear();
}
-SharedHandle<ServerStat>
+std::shared_ptr<ServerStat>
RequestGroupMan::findServerStat(const std::string& hostname,
const std::string& protocol) const
{
return serverStatMan_->find(hostname, protocol);
}
-SharedHandle<ServerStat>
+std::shared_ptr<ServerStat>
RequestGroupMan::getOrCreateServerStat(const std::string& hostname,
const std::string& protocol)
{
- SharedHandle<ServerStat> ss = findServerStat(hostname, protocol);
+ std::shared_ptr<ServerStat> ss = findServerStat(hostname, protocol);
if(!ss) {
ss.reset(new ServerStat(hostname, protocol));
addServerStat(ss);
@@ -885,7 +885,7 @@ RequestGroupMan::getOrCreateServerStat(const std::string& hostname,
return ss;
}
-bool RequestGroupMan::addServerStat(const SharedHandle<ServerStat>& serverStat)
+bool RequestGroupMan::addServerStat(const std::shared_ptr<ServerStat>& serverStat)
{
return serverStatMan_->add(serverStat);
}
@@ -927,7 +927,7 @@ void RequestGroupMan::getUsedHosts
std::vector<Triplet<size_t, int, std::string> > tempHosts;
for(RequestGroupList::const_iterator i = requestGroups_.begin(),
eoi = requestGroups_.end(); i != eoi; ++i) {
- const SharedHandle<RequestGroup>& rg = *i;
+ const std::shared_ptr<RequestGroup>& rg = *i;
const FileEntry::InFlightRequestSet& inFlightReqs =
rg->getDownloadContext()->getFirstFileEntry()->getInFlightRequests();
for(FileEntry::InFlightRequestSet::iterator j =
@@ -948,7 +948,7 @@ void RequestGroupMan::getUsedHosts
if(k == eok) {
std::string protocol = uri::getFieldString(us, USR_SCHEME,
(*j)->getUri().c_str());
- SharedHandle<ServerStat> ss = findServerStat(host, protocol);
+ std::shared_ptr<ServerStat> ss = findServerStat(host, protocol);
int invDlSpeed = (ss && ss->isOK()) ?
-(static_cast<int>(ss->getDownloadSpeed())) : 0;
tempHosts.push_back(makeTriplet(1, invDlSpeed, host));
@@ -962,7 +962,7 @@ void RequestGroupMan::getUsedHosts
}
void RequestGroupMan::setUriListParser
-(const SharedHandle<UriListParser>& uriListParser)
+(const std::shared_ptr<UriListParser>& uriListParser)
{
uriListParser_ = uriListParser;
}
diff --git a/src/RequestGroupMan.h b/src/RequestGroupMan.h
index ab595372..21df6a76 100644
--- a/src/RequestGroupMan.h
+++ b/src/RequestGroupMan.h
@@ -41,8 +41,8 @@
#include <deque>
#include <vector>
#include <map>
+#include <memory>
-#include "SharedHandle.h"
#include "DownloadResult.h"
#include "TransferStat.h"
#include "RequestGroup.h"
@@ -62,9 +62,9 @@ class UriListParser;
class WrDiskCache;
typedef IndexedList<a2_gid_t,
- SharedHandle<RequestGroup> > RequestGroupList;
+ std::shared_ptr<RequestGroup> > RequestGroupList;
typedef IndexedList<a2_gid_t,
- SharedHandle<DownloadResult> > DownloadResultList;
+ std::shared_ptr<DownloadResult> > DownloadResultList;
class RequestGroupMan {
private:
@@ -76,7 +76,7 @@ private:
const Option* option_;
- SharedHandle<ServerStatMan> serverStatMan_;
+ std::shared_ptr<ServerStatMan> serverStatMan_;
int maxOverallDownloadSpeedLimit_;
@@ -100,27 +100,27 @@ private:
size_t maxDownloadResult_;
// UriListParser for deferred input.
- SharedHandle<UriListParser> uriListParser_;
+ std::shared_ptr<UriListParser> uriListParser_;
WrDiskCache* wrDiskCache_;
void formatDownloadResultFull
(OutputFile& out,
const char* status,
- const SharedHandle<DownloadResult>& downloadResult) const;
+ const std::shared_ptr<DownloadResult>& downloadResult) const;
std::string formatDownloadResult
(const char* status,
- const SharedHandle<DownloadResult>& downloadResult) const;
+ const std::shared_ptr<DownloadResult>& downloadResult) const;
void configureRequestGroup
- (const SharedHandle<RequestGroup>& requestGroup) const;
+ (const std::shared_ptr<RequestGroup>& requestGroup) const;
- void addRequestGroupIndex(const SharedHandle<RequestGroup>& group);
+ void addRequestGroupIndex(const std::shared_ptr<RequestGroup>& group);
void addRequestGroupIndex
- (const std::vector<SharedHandle<RequestGroup> >& groups);
+ (const std::vector<std::shared_ptr<RequestGroup> >& groups);
public:
- RequestGroupMan(const std::vector<SharedHandle<RequestGroup> >& requestGroups,
+ RequestGroupMan(const std::vector<std::shared_ptr<RequestGroup> >& requestGroups,
int maxSimultaneousDownloads,
const Option* option);
@@ -143,16 +143,16 @@ public:
// Note that this method does not call addRequestGroupIndex(). This
// method should be considered as private, but exposed for unit
// testing purpose.
- void addRequestGroup(const SharedHandle<RequestGroup>& group);
+ void addRequestGroup(const std::shared_ptr<RequestGroup>& group);
- void addReservedGroup(const std::vector<SharedHandle<RequestGroup> >& groups);
+ void addReservedGroup(const std::vector<std::shared_ptr<RequestGroup> >& groups);
- void addReservedGroup(const SharedHandle<RequestGroup>& group);
+ void addReservedGroup(const std::shared_ptr<RequestGroup>& group);
void insertReservedGroup
- (size_t pos, const std::vector<SharedHandle<RequestGroup> >& groups);
+ (size_t pos, const std::vector<std::shared_ptr<RequestGroup> >& groups);
- void insertReservedGroup(size_t pos, const SharedHandle<RequestGroup>& group);
+ void insertReservedGroup(size_t pos, const std::shared_ptr<RequestGroup>& group);
size_t countRequestGroup() const;
@@ -168,7 +168,7 @@ public:
// Returns RequestGroup object whose gid is gid. This method returns
// RequestGroup either in requestGroups_ or reservedGroups_.
- SharedHandle<RequestGroup> findGroup(a2_gid_t gid) const;
+ std::shared_ptr<RequestGroup> findGroup(a2_gid_t gid) const;
// Changes the position of download denoted by gid. If how is
// POS_SET, it moves the download to a position relative to the
@@ -230,7 +230,7 @@ public:
return downloadResults_;
}
- SharedHandle<DownloadResult> findDownloadResult(a2_gid_t gid) const;
+ std::shared_ptr<DownloadResult> findDownloadResult(a2_gid_t gid) const;
// Removes all download results.
void purgeDownloadResult();
@@ -239,15 +239,15 @@ public:
// result was removed. Otherwise returns false.
bool removeDownloadResult(a2_gid_t gid);
- void addDownloadResult(const SharedHandle<DownloadResult>& downloadResult);
+ void addDownloadResult(const std::shared_ptr<DownloadResult>& downloadResult);
- SharedHandle<ServerStat> findServerStat(const std::string& hostname,
+ std::shared_ptr<ServerStat> findServerStat(const std::string& hostname,
const std::string& protocol) const;
- SharedHandle<ServerStat> getOrCreateServerStat(const std::string& hostname,
+ std::shared_ptr<ServerStat> getOrCreateServerStat(const std::string& hostname,
const std::string& protocol);
- bool addServerStat(const SharedHandle<ServerStat>& serverStat);
+ bool addServerStat(const std::shared_ptr<ServerStat>& serverStat);
bool loadServerStat(const std::string& filename);
@@ -311,7 +311,7 @@ public:
// Returns currently used hosts and its use count.
void getUsedHosts(std::vector<std::pair<size_t, std::string> >& usedHosts);
- const SharedHandle<ServerStatMan>& getServerStatMan() const
+ const std::shared_ptr<ServerStatMan>& getServerStatMan() const
{
return serverStatMan_;
}
@@ -321,7 +321,7 @@ public:
maxDownloadResult_ = v;
}
- void setUriListParser(const SharedHandle<UriListParser>& uriListParser);
+ void setUriListParser(const std::shared_ptr<UriListParser>& uriListParser);
NetStat& getNetStat()
{
diff --git a/src/RequestSlot.h b/src/RequestSlot.h
index 9ad5e9fe..cb1f073e 100644
--- a/src/RequestSlot.h
+++ b/src/RequestSlot.h
@@ -55,7 +55,7 @@ private:
// PieceStorage::getPiece() repeatedly. It turns out that this process
// takes time(about 1.7% of processing time). To reduce it, we put piece here
// at the construction of RequestSlot as a cache.
- SharedHandle<Piece> piece_;
+ std::shared_ptr<Piece> piece_;
// inlined for performance reason
void copy(const RequestSlot& requestSlot)
@@ -70,7 +70,7 @@ private:
public:
RequestSlot(size_t index, int32_t begin, int32_t length, size_t blockIndex,
- const SharedHandle<Piece>& piece = SharedHandle<Piece>()):
+ const std::shared_ptr<Piece>& piece = std::shared_ptr<Piece>()):
dispatchedTime_(global::wallclock()),
index_(index), begin_(begin), length_(length), blockIndex_(blockIndex),
piece_(piece) {}
@@ -133,7 +133,7 @@ public:
size_t getBlockIndex() const { return blockIndex_; }
void setBlockIndex(size_t blockIndex) { blockIndex_ = blockIndex; }
- const SharedHandle<Piece>& getPiece() const
+ const std::shared_ptr<Piece>& getPiece() const
{
return piece_;
}
diff --git a/src/RpcMethod.cc b/src/RpcMethod.cc
index e61f9926..19467050 100644
--- a/src/RpcMethod.cc
+++ b/src/RpcMethod.cc
@@ -59,10 +59,10 @@ RpcMethod::RpcMethod()
RpcMethod::~RpcMethod() {}
-SharedHandle<ValueBase> RpcMethod::createErrorResponse
+std::shared_ptr<ValueBase> RpcMethod::createErrorResponse
(const Exception& e, const RpcRequest& req)
{
- SharedHandle<Dict> params = Dict::g();
+ std::shared_ptr<Dict> params = Dict::g();
params->put((req.jsonRpc ? "code" : "faultCode"), Integer::g(1));
params->put((req.jsonRpc ? "message" : "faultString"), std::string(e.what()));
return params;
@@ -85,7 +85,7 @@ void gatherOption
(InputIterator first, InputIterator last,
Pred pred,
Option* option,
- const SharedHandle<OptionParser>& optionParser)
+ const std::shared_ptr<OptionParser>& optionParser)
{
for(; first != last; ++first) {
const std::string& optionName = (*first).first;
diff --git a/src/RpcMethod.h b/src/RpcMethod.h
index caad0fa4..7f610731 100644
--- a/src/RpcMethod.h
+++ b/src/RpcMethod.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "ValueBase.h"
namespace aria2 {
@@ -64,12 +64,12 @@ struct RpcResponse;
// to RpcMethodFactory.
class RpcMethod {
private:
- SharedHandle<OptionParser> optionParser_;
+ std::shared_ptr<OptionParser> optionParser_;
protected:
// Subclass must implement this function to fulfil RpcRequest req.
// The return value of this method is used as a return value of RPC
// request.
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e) = 0;
void gatherRequestOption(Option* option, const Dict* optionsDict);
@@ -81,10 +81,10 @@ protected:
void gatherChangeableGlobalOption(Option* option, const Dict* optionDict);
- SharedHandle<ValueBase> createErrorResponse
+ std::shared_ptr<ValueBase> createErrorResponse
(const Exception& e, const RpcRequest& req);
- const SharedHandle<OptionParser>& getOptionParser() const
+ const std::shared_ptr<OptionParser>& getOptionParser() const
{
return optionParser_;
}
diff --git a/src/RpcMethodFactory.cc b/src/RpcMethodFactory.cc
index 5e73c1a1..3e1d5353 100644
--- a/src/RpcMethodFactory.cc
+++ b/src/RpcMethodFactory.cc
@@ -42,107 +42,107 @@ namespace aria2 {
namespace rpc {
namespace {
-SharedHandle<RpcMethod> getNoSuchMethod()
+std::shared_ptr<RpcMethod> getNoSuchMethod()
{
- static SharedHandle<RpcMethod> m(new NoSuchMethodRpcMethod());
+ static std::shared_ptr<RpcMethod> m(new NoSuchMethodRpcMethod());
return m;
}
} // namespace
namespace {
-SharedHandle<RpcMethod>
+std::shared_ptr<RpcMethod>
createMethod(const std::string& methodName)
{
if(methodName == AddUriRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new AddUriRpcMethod());
+ return std::shared_ptr<RpcMethod>(new AddUriRpcMethod());
#ifdef ENABLE_BITTORRENT
} else if(methodName == AddTorrentRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new AddTorrentRpcMethod());
+ return std::shared_ptr<RpcMethod>(new AddTorrentRpcMethod());
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
}
else if(methodName == AddMetalinkRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new AddMetalinkRpcMethod());
+ return std::shared_ptr<RpcMethod>(new AddMetalinkRpcMethod());
#endif // ENABLE_METALINK
}
else if(methodName == RemoveRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new RemoveRpcMethod());
+ return std::shared_ptr<RpcMethod>(new RemoveRpcMethod());
} else if(methodName == PauseRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new PauseRpcMethod());
+ return std::shared_ptr<RpcMethod>(new PauseRpcMethod());
} else if(methodName == ForcePauseRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new ForcePauseRpcMethod());
+ return std::shared_ptr<RpcMethod>(new ForcePauseRpcMethod());
} else if(methodName == PauseAllRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new PauseAllRpcMethod());
+ return std::shared_ptr<RpcMethod>(new PauseAllRpcMethod());
} else if(methodName == ForcePauseAllRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new ForcePauseAllRpcMethod());
+ return std::shared_ptr<RpcMethod>(new ForcePauseAllRpcMethod());
} else if(methodName == UnpauseRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new UnpauseRpcMethod());
+ return std::shared_ptr<RpcMethod>(new UnpauseRpcMethod());
} else if(methodName == UnpauseAllRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new UnpauseAllRpcMethod());
+ return std::shared_ptr<RpcMethod>(new UnpauseAllRpcMethod());
} else if(methodName == ForceRemoveRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new ForceRemoveRpcMethod());
+ return std::shared_ptr<RpcMethod>(new ForceRemoveRpcMethod());
} else if(methodName == ChangePositionRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new ChangePositionRpcMethod());
+ return std::shared_ptr<RpcMethod>(new ChangePositionRpcMethod());
} else if(methodName == TellStatusRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new TellStatusRpcMethod());
+ return std::shared_ptr<RpcMethod>(new TellStatusRpcMethod());
} else if(methodName == GetUrisRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new GetUrisRpcMethod());
+ return std::shared_ptr<RpcMethod>(new GetUrisRpcMethod());
} else if(methodName == GetFilesRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new GetFilesRpcMethod());
+ return std::shared_ptr<RpcMethod>(new GetFilesRpcMethod());
#ifdef ENABLE_BITTORRENT
}
else if(methodName == GetPeersRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new GetPeersRpcMethod());
+ return std::shared_ptr<RpcMethod>(new GetPeersRpcMethod());
#endif // ENABLE_BITTORRENT
} else if(methodName == GetServersRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new GetServersRpcMethod());
+ return std::shared_ptr<RpcMethod>(new GetServersRpcMethod());
} else if(methodName == TellActiveRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new TellActiveRpcMethod());
+ return std::shared_ptr<RpcMethod>(new TellActiveRpcMethod());
} else if(methodName == TellWaitingRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new TellWaitingRpcMethod());
+ return std::shared_ptr<RpcMethod>(new TellWaitingRpcMethod());
} else if(methodName == TellStoppedRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new TellStoppedRpcMethod());
+ return std::shared_ptr<RpcMethod>(new TellStoppedRpcMethod());
} else if(methodName == GetOptionRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new GetOptionRpcMethod());
+ return std::shared_ptr<RpcMethod>(new GetOptionRpcMethod());
} else if(methodName == ChangeUriRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new ChangeUriRpcMethod());
+ return std::shared_ptr<RpcMethod>(new ChangeUriRpcMethod());
} else if(methodName == ChangeOptionRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new ChangeOptionRpcMethod());
+ return std::shared_ptr<RpcMethod>(new ChangeOptionRpcMethod());
} else if(methodName == GetGlobalOptionRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new GetGlobalOptionRpcMethod());
+ return std::shared_ptr<RpcMethod>(new GetGlobalOptionRpcMethod());
} else if(methodName == ChangeGlobalOptionRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new ChangeGlobalOptionRpcMethod());
+ return std::shared_ptr<RpcMethod>(new ChangeGlobalOptionRpcMethod());
} else if(methodName == PurgeDownloadResultRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new PurgeDownloadResultRpcMethod());
+ return std::shared_ptr<RpcMethod>(new PurgeDownloadResultRpcMethod());
} else if(methodName == RemoveDownloadResultRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new RemoveDownloadResultRpcMethod());
+ return std::shared_ptr<RpcMethod>(new RemoveDownloadResultRpcMethod());
} else if(methodName == GetVersionRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new GetVersionRpcMethod());
+ return std::shared_ptr<RpcMethod>(new GetVersionRpcMethod());
} else if(methodName == GetSessionInfoRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new GetSessionInfoRpcMethod());
+ return std::shared_ptr<RpcMethod>(new GetSessionInfoRpcMethod());
} else if(methodName == ShutdownRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new ShutdownRpcMethod());
+ return std::shared_ptr<RpcMethod>(new ShutdownRpcMethod());
} else if(methodName == ForceShutdownRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new ForceShutdownRpcMethod());
+ return std::shared_ptr<RpcMethod>(new ForceShutdownRpcMethod());
} else if(methodName == GetGlobalStatRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new GetGlobalStatRpcMethod());
+ return std::shared_ptr<RpcMethod>(new GetGlobalStatRpcMethod());
} else if(methodName == SystemMulticallRpcMethod::getMethodName()) {
- return SharedHandle<RpcMethod>(new SystemMulticallRpcMethod());
+ return std::shared_ptr<RpcMethod>(new SystemMulticallRpcMethod());
} else {
- return SharedHandle<RpcMethod>();
+ return std::shared_ptr<RpcMethod>();
}
}
} // namespace
-std::map<std::string, SharedHandle<RpcMethod> > RpcMethodFactory::cache_;
+std::map<std::string, std::shared_ptr<RpcMethod> > RpcMethodFactory::cache_;
-SharedHandle<RpcMethod>
+std::shared_ptr<RpcMethod>
RpcMethodFactory::create(const std::string& methodName)
{
- std::map<std::string, SharedHandle<RpcMethod> >::const_iterator itr =
+ std::map<std::string, std::shared_ptr<RpcMethod> >::const_iterator itr =
cache_.find(methodName);
if(itr == cache_.end()) {
- SharedHandle<RpcMethod> m = createMethod(methodName);
+ std::shared_ptr<RpcMethod> m = createMethod(methodName);
if(m) {
cache_.insert(std::make_pair(methodName, m));
return m;
diff --git a/src/RpcMethodFactory.h b/src/RpcMethodFactory.h
index 063502fc..5d479d56 100644
--- a/src/RpcMethodFactory.h
+++ b/src/RpcMethodFactory.h
@@ -39,8 +39,7 @@
#include <string>
#include <map>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -50,9 +49,9 @@ class RpcMethod;
class RpcMethodFactory {
public:
- static SharedHandle<RpcMethod> create(const std::string& methodName);
+ static std::shared_ptr<RpcMethod> create(const std::string& methodName);
private:
- static std::map<std::string, SharedHandle<RpcMethod> > cache_;
+ static std::map<std::string, std::shared_ptr<RpcMethod> > cache_;
};
} // namespace rpc
diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc
index 64174194..4118104e 100644
--- a/src/RpcMethodImpl.cc
+++ b/src/RpcMethodImpl.cc
@@ -83,17 +83,17 @@ namespace aria2 {
namespace rpc {
namespace {
-const SharedHandle<String> VLB_TRUE = String::g("true");
-const SharedHandle<String> VLB_FALSE = String::g("false");
-const SharedHandle<String> VLB_OK = String::g("OK");
-const SharedHandle<String> VLB_ACTIVE = String::g("active");
-const SharedHandle<String> VLB_WAITING = String::g("waiting");
-const SharedHandle<String> VLB_PAUSED = String::g("paused");
-const SharedHandle<String> VLB_REMOVED = String::g("removed");
-const SharedHandle<String> VLB_ERROR = String::g("error");
-const SharedHandle<String> VLB_COMPLETE = String::g("complete");
-const SharedHandle<String> VLB_USED = String::g("used");
-const SharedHandle<String> VLB_ZERO = String::g("0");
+const std::shared_ptr<String> VLB_TRUE = String::g("true");
+const std::shared_ptr<String> VLB_FALSE = String::g("false");
+const std::shared_ptr<String> VLB_OK = String::g("OK");
+const std::shared_ptr<String> VLB_ACTIVE = String::g("active");
+const std::shared_ptr<String> VLB_WAITING = String::g("waiting");
+const std::shared_ptr<String> VLB_PAUSED = String::g("paused");
+const std::shared_ptr<String> VLB_REMOVED = String::g("removed");
+const std::shared_ptr<String> VLB_ERROR = String::g("error");
+const std::shared_ptr<String> VLB_COMPLETE = String::g("complete");
+const std::shared_ptr<String> VLB_USED = String::g("used");
+const std::shared_ptr<String> VLB_ZERO = String::g("0");
const std::string KEY_GID = "gid";
const std::string KEY_ERROR_CODE = "errorCode";
@@ -145,15 +145,15 @@ const std::string KEY_NUM_ACTIVE = "numActive";
} // namespace
namespace {
-SharedHandle<ValueBase> createGIDResponse(a2_gid_t gid)
+std::shared_ptr<ValueBase> createGIDResponse(a2_gid_t gid)
{
return String::g(GroupId::toHex(gid));
}
} // namespace
namespace {
-SharedHandle<ValueBase>
-addRequestGroup(const SharedHandle<RequestGroup>& group,
+std::shared_ptr<ValueBase>
+addRequestGroup(const std::shared_ptr<RequestGroup>& group,
DownloadEngine* e,
bool posGiven, int pos)
{
@@ -216,7 +216,7 @@ void extractUris(OutputIterator out, const List* src)
}
} // namespace
-SharedHandle<ValueBase> AddUriRpcMethod::process
+std::shared_ptr<ValueBase> AddUriRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const List* urisParam = checkRequiredParam<List>(req, 0);
@@ -229,13 +229,13 @@ SharedHandle<ValueBase> AddUriRpcMethod::process
throw DL_ABORT_EX("URI is not provided.");
}
- SharedHandle<Option> requestOption(new Option(*e->getOption()));
+ std::shared_ptr<Option> requestOption(new Option(*e->getOption()));
gatherRequestOption(requestOption.get(), optsParam);
bool posGiven = checkPosParam(posParam);
size_t pos = posGiven ? posParam->i() : 0;
- std::vector<SharedHandle<RequestGroup> > result;
+ std::vector<std::shared_ptr<RequestGroup> > result;
createRequestGroupForUri(result, requestOption, uris,
/* ignoreForceSeq = */ true,
/* ignoreLocalPath = */ true);
@@ -260,7 +260,7 @@ std::string getHexSha1(const std::string& s)
#endif // ENABLE_MESSAGE_DIGEST
#ifdef ENABLE_BITTORRENT
-SharedHandle<ValueBase> AddTorrentRpcMethod::process
+std::shared_ptr<ValueBase> AddTorrentRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* torrentParam = checkRequiredParam<String>(req, 0);
@@ -268,7 +268,7 @@ SharedHandle<ValueBase> AddTorrentRpcMethod::process
const Dict* optsParam = checkParam<Dict>(req, 2);
const Integer* posParam = checkParam<Integer>(req, 3);
- SharedHandle<String> tempTorrentParam;
+ std::shared_ptr<String> tempTorrentParam;
if(req.jsonRpc) {
tempTorrentParam = String::g
(base64::decode(torrentParam->s().begin(),
@@ -278,7 +278,7 @@ SharedHandle<ValueBase> AddTorrentRpcMethod::process
std::vector<std::string> uris;
extractUris(std::back_inserter(uris), urisParam);
- SharedHandle<Option> requestOption(new Option(*e->getOption()));
+ std::shared_ptr<Option> requestOption(new Option(*e->getOption()));
gatherRequestOption(requestOption.get(), optsParam);
bool posGiven = checkPosParam(posParam);
@@ -300,7 +300,7 @@ SharedHandle<ValueBase> AddTorrentRpcMethod::process
filename.clear();
}
}
- std::vector<SharedHandle<RequestGroup> > result;
+ std::vector<std::shared_ptr<RequestGroup> > result;
createRequestGroupForBitTorrent(result, requestOption, uris, filename,
torrentParam->s());
@@ -313,27 +313,27 @@ SharedHandle<ValueBase> AddTorrentRpcMethod::process
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
-SharedHandle<ValueBase> AddMetalinkRpcMethod::process
+std::shared_ptr<ValueBase> AddMetalinkRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* metalinkParam = checkRequiredParam<String>(req, 0);
const Dict* optsParam = checkParam<Dict>(req, 1);
const Integer* posParam = checkParam<Integer>(req, 2);
- SharedHandle<String> tempMetalinkParam;
+ std::shared_ptr<String> tempMetalinkParam;
if(req.jsonRpc) {
tempMetalinkParam = String::g
(base64::decode(metalinkParam->s().begin(),
metalinkParam->s().end()));
metalinkParam = tempMetalinkParam.get();
}
- SharedHandle<Option> requestOption(new Option(*e->getOption()));
+ std::shared_ptr<Option> requestOption(new Option(*e->getOption()));
gatherRequestOption(requestOption.get(), optsParam);
bool posGiven = checkPosParam(posParam);
size_t pos = posGiven ? posParam->i() : 0;
- std::vector<SharedHandle<RequestGroup> > result;
+ std::vector<std::shared_ptr<RequestGroup> > result;
#ifdef ENABLE_MESSAGE_DIGEST
std::string filename;
if(requestOption->getAsBool(PREF_RPC_SAVE_UPLOAD_METADATA)) {
@@ -361,14 +361,14 @@ SharedHandle<ValueBase> AddMetalinkRpcMethod::process
#else // !ENABLE_MESSAGE_DIGEST
createRequestGroupForMetalink(result, requestOption, metalinkParam->s());
#endif // !ENABLE_MESSAGE_DIGEST
- SharedHandle<List> gids = List::g();
+ std::shared_ptr<List> gids = List::g();
if(!result.empty()) {
if(posGiven) {
e->getRequestGroupMan()->insertReservedGroup(pos, result);
} else {
e->getRequestGroupMan()->addReservedGroup(result);
}
- for(std::vector<SharedHandle<RequestGroup> >::const_iterator i =
+ for(std::vector<std::shared_ptr<RequestGroup> >::const_iterator i =
result.begin(), eoi = result.end(); i != eoi; ++i) {
gids->append(GroupId::toHex((*i)->getGID()));
}
@@ -378,13 +378,13 @@ SharedHandle<ValueBase> AddMetalinkRpcMethod::process
#endif // ENABLE_METALINK
namespace {
-SharedHandle<ValueBase> removeDownload
+std::shared_ptr<ValueBase> removeDownload
(const RpcRequest& req, DownloadEngine* e, bool forceRemove)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
a2_gid_t gid = str2Gid(gidParam);
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(group) {
if(group->getState() == RequestGroup::STATE_ACTIVE) {
if(forceRemove) {
@@ -409,26 +409,26 @@ SharedHandle<ValueBase> removeDownload
}
} // namespace
-SharedHandle<ValueBase> RemoveRpcMethod::process
+std::shared_ptr<ValueBase> RemoveRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return removeDownload(req, e, false);
}
-SharedHandle<ValueBase> ForceRemoveRpcMethod::process
+std::shared_ptr<ValueBase> ForceRemoveRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return removeDownload(req, e, true);
}
namespace {
-SharedHandle<ValueBase> pauseDownload
+std::shared_ptr<ValueBase> pauseDownload
(const RpcRequest& req, DownloadEngine* e, bool forcePause)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
a2_gid_t gid = str2Gid(gidParam);
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(group) {
bool reserved = group->getState() == RequestGroup::STATE_WAITING;
if(pauseRequestGroup(group, reserved, forcePause)) {
@@ -441,13 +441,13 @@ SharedHandle<ValueBase> pauseDownload
}
} // namespace
-SharedHandle<ValueBase> PauseRpcMethod::process
+std::shared_ptr<ValueBase> PauseRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return pauseDownload(req, e, false);
}
-SharedHandle<ValueBase> ForcePauseRpcMethod::process
+std::shared_ptr<ValueBase> ForcePauseRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return pauseDownload(req, e, true);
@@ -465,7 +465,7 @@ void pauseRequestGroups
} // namespace
namespace {
-SharedHandle<ValueBase> pauseAllDownloads
+std::shared_ptr<ValueBase> pauseAllDownloads
(const RpcRequest& req, DownloadEngine* e, bool forcePause)
{
const RequestGroupList& groups = e->getRequestGroupMan()->getRequestGroups();
@@ -478,25 +478,25 @@ SharedHandle<ValueBase> pauseAllDownloads
}
} // namespace
-SharedHandle<ValueBase> PauseAllRpcMethod::process
+std::shared_ptr<ValueBase> PauseAllRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return pauseAllDownloads(req, e, false);
}
-SharedHandle<ValueBase> ForcePauseAllRpcMethod::process
+std::shared_ptr<ValueBase> ForcePauseAllRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return pauseAllDownloads(req, e, true);
}
-SharedHandle<ValueBase> UnpauseRpcMethod::process
+std::shared_ptr<ValueBase> UnpauseRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
a2_gid_t gid = str2Gid(gidParam);
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(!group ||
group->getState() != RequestGroup::STATE_WAITING ||
!group->isPauseRequested()) {
@@ -509,7 +509,7 @@ SharedHandle<ValueBase> UnpauseRpcMethod::process
return createGIDResponse(gid);
}
-SharedHandle<ValueBase> UnpauseAllRpcMethod::process
+std::shared_ptr<ValueBase> UnpauseAllRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const RequestGroupList& groups =
@@ -525,12 +525,12 @@ SharedHandle<ValueBase> UnpauseAllRpcMethod::process
namespace {
template<typename InputIterator>
void createUriEntry
-(const SharedHandle<List>& uriList,
+(const std::shared_ptr<List>& uriList,
InputIterator first, InputIterator last,
- const SharedHandle<String>& status)
+ const std::shared_ptr<String>& status)
{
for(; first != last; ++first) {
- SharedHandle<Dict> entry = Dict::g();
+ std::shared_ptr<Dict> entry = Dict::g();
entry->put(KEY_URI, *first);
entry->put(KEY_STATUS, status);
uriList->append(entry);
@@ -540,7 +540,7 @@ void createUriEntry
namespace {
void createUriEntry
-(const SharedHandle<List>& uriList, const SharedHandle<FileEntry>& file)
+(const std::shared_ptr<List>& uriList, const std::shared_ptr<FileEntry>& file)
{
createUriEntry(uriList,
file->getSpentUris().begin(),
@@ -556,13 +556,13 @@ void createUriEntry
namespace {
template<typename InputIterator>
void createFileEntry
-(const SharedHandle<List>& files,
+(const std::shared_ptr<List>& files,
InputIterator first, InputIterator last,
const BitfieldMan* bf)
{
size_t index = 1;
for(; first != last; ++first, ++index) {
- SharedHandle<Dict> entry = Dict::g();
+ std::shared_ptr<Dict> entry = Dict::g();
entry->put(KEY_INDEX, util::uitos(index));
entry->put(KEY_PATH, (*first)->getPath());
entry->put(KEY_SELECTED, (*first)->isRequested()?VLB_TRUE:VLB_FALSE);
@@ -571,7 +571,7 @@ void createFileEntry
((*first)->getOffset(), (*first)->getLength());
entry->put(KEY_COMPLETED_LENGTH, util::itos(completedLength));
- SharedHandle<List> uriList = List::g();
+ std::shared_ptr<List> uriList = List::g();
createUriEntry(uriList, *first);
entry->put(KEY_URIS, uriList);
files->append(entry);
@@ -582,7 +582,7 @@ void createFileEntry
namespace {
template<typename InputIterator>
void createFileEntry
-(const SharedHandle<List>& files,
+(const std::shared_ptr<List>& files,
InputIterator first, InputIterator last,
int64_t totalLength,
int32_t pieceLength,
@@ -598,11 +598,11 @@ void createFileEntry
namespace {
template<typename InputIterator>
void createFileEntry
-(const SharedHandle<List>& files,
+(const std::shared_ptr<List>& files,
InputIterator first, InputIterator last,
int64_t totalLength,
int32_t pieceLength,
- const SharedHandle<PieceStorage>& ps)
+ const std::shared_ptr<PieceStorage>& ps)
{
BitfieldMan bf(pieceLength, totalLength);
if(ps) {
@@ -621,11 +621,11 @@ bool requested_key
} // namespace
void gatherProgressCommon
-(const SharedHandle<Dict>& entryDict,
- const SharedHandle<RequestGroup>& group,
+(const std::shared_ptr<Dict>& entryDict,
+ const std::shared_ptr<RequestGroup>& group,
const std::vector<std::string>& keys)
{
- const SharedHandle<PieceStorage>& ps = group->getPieceStorage();
+ const std::shared_ptr<PieceStorage>& ps = group->getPieceStorage();
if(requested_key(keys, KEY_GID)) {
entryDict->put(KEY_GID, GroupId::toHex(group->getGID()).c_str());
}
@@ -660,7 +660,7 @@ void gatherProgressCommon
}
}
}
- const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
+ const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
if(requested_key(keys, KEY_PIECE_LENGTH)) {
entryDict->put(KEY_PIECE_LENGTH, util::itos(dctx->getPieceLength()));
}
@@ -669,7 +669,7 @@ void gatherProgressCommon
}
if(requested_key(keys, KEY_FOLLOWED_BY)) {
if(!group->followedBy().empty()) {
- SharedHandle<List> list = List::g();
+ std::shared_ptr<List> list = List::g();
// The element is GID.
for(std::vector<a2_gid_t>::const_iterator i = group->followedBy().begin(),
eoi = group->followedBy().end(); i != eoi; ++i) {
@@ -684,7 +684,7 @@ void gatherProgressCommon
}
}
if(requested_key(keys, KEY_FILES)) {
- SharedHandle<List> files = List::g();
+ std::shared_ptr<List> files = List::g();
createFileEntry
(files, dctx->getFileEntries().begin(), dctx->getFileEntries().end(),
dctx->getTotalLength(), dctx->getPieceLength(), ps);
@@ -697,8 +697,8 @@ void gatherProgressCommon
#ifdef ENABLE_BITTORRENT
void gatherBitTorrentMetadata
-(const SharedHandle<Dict>& btDict,
- const SharedHandle<TorrentAttribute>& torrentAttrs)
+(const std::shared_ptr<Dict>& btDict,
+ const std::shared_ptr<TorrentAttribute>& torrentAttrs)
{
if(!torrentAttrs->comment.empty()) {
btDict->put(KEY_COMMENT, torrentAttrs->comment);
@@ -709,11 +709,11 @@ void gatherBitTorrentMetadata
if(torrentAttrs->mode) {
btDict->put(KEY_MODE, bittorrent::getModeString(torrentAttrs->mode));
}
- SharedHandle<List> destAnnounceList = List::g();
+ std::shared_ptr<List> destAnnounceList = List::g();
for(std::vector<std::vector<std::string> >::const_iterator l =
torrentAttrs->announceList.begin(),
eoi = torrentAttrs->announceList.end(); l != eoi; ++l) {
- SharedHandle<List> destAnnounceTier = List::g();
+ std::shared_ptr<List> destAnnounceTier = List::g();
for(std::vector<std::string>::const_iterator t = (*l).begin(),
eoi2 = (*l).end(); t != eoi2; ++t) {
destAnnounceTier->append(*t);
@@ -722,7 +722,7 @@ void gatherBitTorrentMetadata
}
btDict->put(KEY_ANNOUNCE_LIST, destAnnounceList);
if(!torrentAttrs->metadata.empty()) {
- SharedHandle<Dict> infoDict = Dict::g();
+ std::shared_ptr<Dict> infoDict = Dict::g();
infoDict->put(KEY_NAME, torrentAttrs->name);
btDict->put(KEY_INFO, infoDict);
}
@@ -730,16 +730,16 @@ void gatherBitTorrentMetadata
namespace {
void gatherProgressBitTorrent
-(const SharedHandle<Dict>& entryDict,
- const SharedHandle<TorrentAttribute>& torrentAttrs,
- const SharedHandle<BtObject>& btObject,
+(const std::shared_ptr<Dict>& entryDict,
+ const std::shared_ptr<TorrentAttribute>& torrentAttrs,
+ const std::shared_ptr<BtObject>& btObject,
const std::vector<std::string>& keys)
{
if(requested_key(keys, KEY_INFO_HASH)) {
entryDict->put(KEY_INFO_HASH, util::toHex(torrentAttrs->infoHash));
}
if(requested_key(keys, KEY_BITTORRENT)) {
- SharedHandle<Dict> btDict = Dict::g();
+ std::shared_ptr<Dict> btDict = Dict::g();
gatherBitTorrentMetadata(btDict, torrentAttrs);
entryDict->put(KEY_BITTORRENT, btDict);
}
@@ -747,7 +747,7 @@ void gatherProgressBitTorrent
if(!btObject) {
entryDict->put(KEY_NUM_SEEDERS, VLB_ZERO);
} else {
- const SharedHandle<PeerStorage>& peerStorage = btObject->peerStorage;
+ const std::shared_ptr<PeerStorage>& peerStorage = btObject->peerStorage;
assert(peerStorage);
const PeerSet& peers = peerStorage->getUsedPeers();
entryDict->put(KEY_NUM_SEEDERS,
@@ -759,7 +759,7 @@ void gatherProgressBitTorrent
namespace {
void gatherPeer
-(const SharedHandle<List>& peers, const SharedHandle<PeerStorage>& ps)
+(const std::shared_ptr<List>& peers, const std::shared_ptr<PeerStorage>& ps)
{
const PeerSet& usedPeers = ps->getUsedPeers();
for(PeerSet::const_iterator i = usedPeers.begin(), eoi = usedPeers.end();
@@ -767,7 +767,7 @@ void gatherPeer
if(!(*i)->isActive()) {
continue;
}
- SharedHandle<Dict> peerEntry = Dict::g();
+ std::shared_ptr<Dict> peerEntry = Dict::g();
peerEntry->put(KEY_PEER_ID, util::torrentPercentEncode((*i)->getPeerId(),
PEER_ID_LENGTH));
peerEntry->put(KEY_IP, (*i)->getIPAddress());
@@ -793,17 +793,17 @@ void gatherPeer
namespace {
void gatherProgress
-(const SharedHandle<Dict>& entryDict,
- const SharedHandle<RequestGroup>& group,
+(const std::shared_ptr<Dict>& entryDict,
+ const std::shared_ptr<RequestGroup>& group,
DownloadEngine* e,
const std::vector<std::string>& keys)
{
gatherProgressCommon(entryDict, group, keys);
#ifdef ENABLE_BITTORRENT
if(group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
- SharedHandle<TorrentAttribute> torrentAttrs =
+ std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(group->getDownloadContext());
- const SharedHandle<BtObject>& btObject =
+ const std::shared_ptr<BtObject>& btObject =
e->getBtRegistry()->get(group->getGID());
gatherProgressBitTorrent(entryDict, torrentAttrs, btObject, keys);
}
@@ -812,7 +812,7 @@ void gatherProgress
} // namespace
void gatherStoppedDownload
-(const SharedHandle<Dict>& entryDict, const SharedHandle<DownloadResult>& ds,
+(const std::shared_ptr<Dict>& entryDict, const std::shared_ptr<DownloadResult>& ds,
const std::vector<std::string>& keys)
{
if(requested_key(keys, KEY_GID)) {
@@ -832,7 +832,7 @@ void gatherStoppedDownload
}
if(requested_key(keys, KEY_FOLLOWED_BY)) {
if(!ds->followedBy.empty()) {
- SharedHandle<List> list = List::g();
+ std::shared_ptr<List> list = List::g();
// The element is GID.
for(std::vector<a2_gid_t>::const_iterator i = ds->followedBy.begin(),
eoi = ds->followedBy.end(); i != eoi; ++i) {
@@ -847,7 +847,7 @@ void gatherStoppedDownload
}
}
if(requested_key(keys, KEY_FILES)) {
- SharedHandle<List> files = List::g();
+ std::shared_ptr<List> files = List::g();
createFileEntry(files, ds->fileEntries.begin(), ds->fileEntries.end(),
ds->totalLength, ds->pieceLength, ds->bitfield);
entryDict->put(KEY_FILES, files);
@@ -894,16 +894,16 @@ void gatherStoppedDownload
}
}
-SharedHandle<ValueBase> GetFilesRpcMethod::process
+std::shared_ptr<ValueBase> GetFilesRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
a2_gid_t gid = str2Gid(gidParam);
- SharedHandle<List> files = List::g();
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<List> files = List::g();
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(!group) {
- SharedHandle<DownloadResult> dr =
+ std::shared_ptr<DownloadResult> dr =
e->getRequestGroupMan()->findDownloadResult(gid);
if(!dr) {
throw DL_ABORT_EX(fmt("No file data is available for GID#%s",
@@ -913,8 +913,8 @@ SharedHandle<ValueBase> GetFilesRpcMethod::process
dr->totalLength, dr->pieceLength, dr->bitfield);
}
} else {
- const SharedHandle<PieceStorage>& ps = group->getPieceStorage();
- const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
+ const std::shared_ptr<PieceStorage>& ps = group->getPieceStorage();
+ const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
createFileEntry(files,
group->getDownloadContext()->getFileEntries().begin(),
group->getDownloadContext()->getFileEntries().end(),
@@ -925,18 +925,18 @@ SharedHandle<ValueBase> GetFilesRpcMethod::process
return files;
}
-SharedHandle<ValueBase> GetUrisRpcMethod::process
+std::shared_ptr<ValueBase> GetUrisRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
a2_gid_t gid = str2Gid(gidParam);
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(!group) {
throw DL_ABORT_EX(fmt("No URI data is available for GID#%s",
GroupId::toHex(gid).c_str()));
}
- SharedHandle<List> uriList = List::g();
+ std::shared_ptr<List> uriList = List::g();
// TODO Current implementation just returns first FileEntry's URIs.
if(!group->getDownloadContext()->getFileEntries().empty()) {
createUriEntry(uriList, group->getDownloadContext()->getFirstFileEntry());
@@ -945,19 +945,19 @@ SharedHandle<ValueBase> GetUrisRpcMethod::process
}
#ifdef ENABLE_BITTORRENT
-SharedHandle<ValueBase> GetPeersRpcMethod::process
+std::shared_ptr<ValueBase> GetPeersRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
a2_gid_t gid = str2Gid(gidParam);
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(!group) {
throw DL_ABORT_EX(fmt("No peer data is available for GID#%s",
GroupId::toHex(gid).c_str()));
}
- SharedHandle<List> peers = List::g();
- const SharedHandle<BtObject>& btObject =
+ std::shared_ptr<List> peers = List::g();
+ const std::shared_ptr<BtObject>& btObject =
e->getBtRegistry()->get(group->getGID());
if(btObject) {
assert(btObject->peerStorage);
@@ -967,7 +967,7 @@ SharedHandle<ValueBase> GetPeersRpcMethod::process
}
#endif // ENABLE_BITTORRENT
-SharedHandle<ValueBase> TellStatusRpcMethod::process
+std::shared_ptr<ValueBase> TellStatusRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
@@ -977,11 +977,11 @@ SharedHandle<ValueBase> TellStatusRpcMethod::process
std::vector<std::string> keys;
toStringList(std::back_inserter(keys), keysParam);
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
- SharedHandle<Dict> entryDict = Dict::g();
+ std::shared_ptr<Dict> entryDict = Dict::g();
if(!group) {
- SharedHandle<DownloadResult> ds =
+ std::shared_ptr<DownloadResult> ds =
e->getRequestGroupMan()->findDownloadResult(gid);
if(!ds) {
throw DL_ABORT_EX(fmt("No such download for GID#%s",
@@ -1005,17 +1005,17 @@ SharedHandle<ValueBase> TellStatusRpcMethod::process
return entryDict;
}
-SharedHandle<ValueBase> TellActiveRpcMethod::process
+std::shared_ptr<ValueBase> TellActiveRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const List* keysParam = checkParam<List>(req, 0);
std::vector<std::string> keys;
toStringList(std::back_inserter(keys), keysParam);
- SharedHandle<List> list = List::g();
+ std::shared_ptr<List> list = List::g();
const RequestGroupList& groups = e->getRequestGroupMan()->getRequestGroups();
for(RequestGroupList::const_iterator i = groups.begin(),
eoi = groups.end(); i != eoi; ++i) {
- SharedHandle<Dict> entryDict = Dict::g();
+ std::shared_ptr<Dict> entryDict = Dict::g();
if(requested_key(keys, KEY_STATUS)) {
entryDict->put(KEY_STATUS, VLB_ACTIVE);
}
@@ -1032,8 +1032,8 @@ TellWaitingRpcMethod::getItems(DownloadEngine* e) const
}
void TellWaitingRpcMethod::createEntry
-(const SharedHandle<Dict>& entryDict,
- const SharedHandle<RequestGroup>& item,
+(const std::shared_ptr<Dict>& entryDict,
+ const std::shared_ptr<RequestGroup>& item,
DownloadEngine* e,
const std::vector<std::string>& keys) const
{
@@ -1054,22 +1054,22 @@ TellStoppedRpcMethod::getItems(DownloadEngine* e) const
}
void TellStoppedRpcMethod::createEntry
-(const SharedHandle<Dict>& entryDict,
- const SharedHandle<DownloadResult>& item,
+(const std::shared_ptr<Dict>& entryDict,
+ const std::shared_ptr<DownloadResult>& item,
DownloadEngine* e,
const std::vector<std::string>& keys) const
{
gatherStoppedDownload(entryDict, item, keys);
}
-SharedHandle<ValueBase> PurgeDownloadResultRpcMethod::process
+std::shared_ptr<ValueBase> PurgeDownloadResultRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
e->getRequestGroupMan()->purgeDownloadResult();
return VLB_OK;
}
-SharedHandle<ValueBase> RemoveDownloadResultRpcMethod::process
+std::shared_ptr<ValueBase> RemoveDownloadResultRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
@@ -1082,14 +1082,14 @@ SharedHandle<ValueBase> RemoveDownloadResultRpcMethod::process
return VLB_OK;
}
-SharedHandle<ValueBase> ChangeOptionRpcMethod::process
+std::shared_ptr<ValueBase> ChangeOptionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
const Dict* optsParam = checkRequiredParam<Dict>(req, 1);
a2_gid_t gid = str2Gid(gidParam);
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
Option option;
if(group) {
if(group->getState() == RequestGroup::STATE_ACTIVE) {
@@ -1105,7 +1105,7 @@ SharedHandle<ValueBase> ChangeOptionRpcMethod::process
return VLB_OK;
}
-SharedHandle<ValueBase> ChangeGlobalOptionRpcMethod::process
+std::shared_ptr<ValueBase> ChangeGlobalOptionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const Dict* optsParam = checkRequiredParam<Dict>(req, 0);
@@ -1116,12 +1116,12 @@ SharedHandle<ValueBase> ChangeGlobalOptionRpcMethod::process
return VLB_OK;
}
-SharedHandle<ValueBase> GetVersionRpcMethod::process
+std::shared_ptr<ValueBase> GetVersionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
- SharedHandle<Dict> result = Dict::g();
+ std::shared_ptr<Dict> result = Dict::g();
result->put(KEY_VERSION, PACKAGE_VERSION);
- SharedHandle<List> featureList = List::g();
+ std::shared_ptr<List> featureList = List::g();
for(int feat = 0; feat < MAX_FEATURE; ++feat) {
const char* name = strSupportedFeature(feat);
if(name) {
@@ -1134,9 +1134,9 @@ SharedHandle<ValueBase> GetVersionRpcMethod::process
namespace {
void pushRequestOption
-(const SharedHandle<Dict>& dict,
- const SharedHandle<Option>& option,
- const SharedHandle<OptionParser>& oparser)
+(const std::shared_ptr<Dict>& dict,
+ const std::shared_ptr<Option>& option,
+ const std::shared_ptr<OptionParser>& oparser)
{
for(size_t i = 1, len = option::countOption(); i < len; ++i) {
const Pref* pref = option::i2p(i);
@@ -1148,16 +1148,16 @@ void pushRequestOption
}
} // namespace
-SharedHandle<ValueBase> GetOptionRpcMethod::process
+std::shared_ptr<ValueBase> GetOptionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
a2_gid_t gid = str2Gid(gidParam);
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
- SharedHandle<Dict> result = Dict::g();
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<Dict> result = Dict::g();
if(!group) {
- SharedHandle<DownloadResult> dr =
+ std::shared_ptr<DownloadResult> dr =
e->getRequestGroupMan()->findDownloadResult(gid);
if(!dr) {
throw DL_ABORT_EX(fmt("Cannot get option for GID#%s",
@@ -1170,10 +1170,10 @@ SharedHandle<ValueBase> GetOptionRpcMethod::process
return result;
}
-SharedHandle<ValueBase> GetGlobalOptionRpcMethod::process
+std::shared_ptr<ValueBase> GetGlobalOptionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
- SharedHandle<Dict> result = Dict::g();
+ std::shared_ptr<Dict> result = Dict::g();
for(size_t i = 0, len = e->getOption()->getTable().size(); i < len; ++i) {
const Pref* pref = option::i2p(i);
if(!e->getOption()->defined(pref)) {
@@ -1187,7 +1187,7 @@ SharedHandle<ValueBase> GetGlobalOptionRpcMethod::process
return result;
}
-SharedHandle<ValueBase> ChangePositionRpcMethod::process
+std::shared_ptr<ValueBase> ChangePositionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
@@ -1209,45 +1209,45 @@ SharedHandle<ValueBase> ChangePositionRpcMethod::process
}
size_t destPos =
e->getRequestGroupMan()->changeReservedGroupPosition(gid, pos, how);
- SharedHandle<Integer> result = Integer::g(destPos);
+ std::shared_ptr<Integer> result = Integer::g(destPos);
return result;
}
-SharedHandle<ValueBase> GetSessionInfoRpcMethod::process
+std::shared_ptr<ValueBase> GetSessionInfoRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
- SharedHandle<Dict> result = Dict::g();
+ std::shared_ptr<Dict> result = Dict::g();
result->put(KEY_SESSION_ID, util::toHex(e->getSessionId()));
return result;
}
-SharedHandle<ValueBase> GetServersRpcMethod::process
+std::shared_ptr<ValueBase> GetServersRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
a2_gid_t gid = str2Gid(gidParam);
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(!group || group->getState() != RequestGroup::STATE_ACTIVE) {
throw DL_ABORT_EX(fmt("No active download for GID#%s",
GroupId::toHex(gid).c_str()));
}
- const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
- const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries();
- SharedHandle<List> result = List::g();
+ const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
+ const std::vector<std::shared_ptr<FileEntry> >& files = dctx->getFileEntries();
+ std::shared_ptr<List> result = List::g();
size_t index = 1;
- for(std::vector<SharedHandle<FileEntry> >::const_iterator fi = files.begin(),
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator fi = files.begin(),
eoi = files.end(); fi != eoi; ++fi, ++index) {
- SharedHandle<Dict> fileEntry = Dict::g();
+ std::shared_ptr<Dict> fileEntry = Dict::g();
fileEntry->put(KEY_INDEX, util::uitos(index));
- SharedHandle<List> servers = List::g();
+ std::shared_ptr<List> servers = List::g();
const FileEntry::InFlightRequestSet& requests =
(*fi)->getInFlightRequests();
for(FileEntry::InFlightRequestSet::iterator ri =requests.begin(),
eoi = requests.end(); ri != eoi; ++ri) {
- SharedHandle<PeerStat> ps = (*ri)->getPeerStat();
+ std::shared_ptr<PeerStat> ps = (*ri)->getPeerStat();
if(ps) {
- SharedHandle<Dict> serverEntry = Dict::g();
+ std::shared_ptr<Dict> serverEntry = Dict::g();
serverEntry->put(KEY_URI, (*ri)->getUri());
serverEntry->put(KEY_CURRENT_URI, (*ri)->getCurrentUri());
serverEntry->put(KEY_DOWNLOAD_SPEED,
@@ -1261,7 +1261,7 @@ SharedHandle<ValueBase> GetServersRpcMethod::process
return result;
}
-SharedHandle<ValueBase> ChangeUriRpcMethod::process
+std::shared_ptr<ValueBase> ChangeUriRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* gidParam = checkRequiredParam<String>(req, 0);
@@ -1274,17 +1274,17 @@ SharedHandle<ValueBase> ChangeUriRpcMethod::process
bool posGiven = checkPosParam(posParam);
size_t pos = posGiven ? posParam->i() : 0;
size_t index = indexParam->i()-1;
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(!group) {
throw DL_ABORT_EX(fmt("Cannot remove URIs from GID#%s",
GroupId::toHex(gid).c_str()));
}
- const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
- const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries();
+ const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
+ const std::vector<std::shared_ptr<FileEntry> >& files = dctx->getFileEntries();
if(files.size() <= index) {
throw DL_ABORT_EX(fmt("fileIndex is out of range"));
}
- SharedHandle<FileEntry> s = files[index];
+ std::shared_ptr<FileEntry> s = files[index];
size_t delcount = 0;
for(List::ValueType::const_iterator i = delUrisParam->begin(),
eoi = delUrisParam->end(); i != eoi; ++i) {
@@ -1318,14 +1318,14 @@ SharedHandle<ValueBase> ChangeUriRpcMethod::process
e->addCommand(commands);
group->getSegmentMan()->recognizeSegmentFor(s);
}
- SharedHandle<List> res = List::g();
+ std::shared_ptr<List> res = List::g();
res->append(Integer::g(delcount));
res->append(Integer::g(addcount));
return res;
}
namespace {
-SharedHandle<ValueBase> goingShutdown
+std::shared_ptr<ValueBase> goingShutdown
(const RpcRequest& req, DownloadEngine* e, bool forceHalt)
{
// Schedule shutdown after 3seconds to give time to client to
@@ -1336,24 +1336,24 @@ SharedHandle<ValueBase> goingShutdown
}
} // namespace
-SharedHandle<ValueBase> ShutdownRpcMethod::process
+std::shared_ptr<ValueBase> ShutdownRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return goingShutdown(req, e, false);
}
-SharedHandle<ValueBase> ForceShutdownRpcMethod::process
+std::shared_ptr<ValueBase> ForceShutdownRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return goingShutdown(req, e, true);
}
-SharedHandle<ValueBase> GetGlobalStatRpcMethod::process
+std::shared_ptr<ValueBase> GetGlobalStatRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
- const SharedHandle<RequestGroupMan>& rgman = e->getRequestGroupMan();
+ const std::shared_ptr<RequestGroupMan>& rgman = e->getRequestGroupMan();
TransferStat ts = rgman->calculateStat();
- SharedHandle<Dict> res = Dict::g();
+ std::shared_ptr<Dict> res = Dict::g();
res->put(KEY_DOWNLOAD_SPEED, util::itos(ts.downloadSpeed));
res->put(KEY_UPLOAD_SPEED, util::itos(ts.uploadSpeed));
res->put(KEY_NUM_WAITING, util::uitos(rgman->getReservedGroups().size()));
@@ -1362,11 +1362,11 @@ SharedHandle<ValueBase> GetGlobalStatRpcMethod::process
return res;
}
-SharedHandle<ValueBase> SystemMulticallRpcMethod::process
+std::shared_ptr<ValueBase> SystemMulticallRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const List* methodSpecs = checkRequiredParam<List>(req, 0);
- SharedHandle<List> list = List::g();
+ std::shared_ptr<List> list = List::g();
for(List::ValueType::const_iterator i = methodSpecs->begin(),
eoi = methodSpecs->end(); i != eoi; ++i) {
const Dict* methodDict = downcast<Dict>(*i);
@@ -1386,19 +1386,19 @@ SharedHandle<ValueBase> SystemMulticallRpcMethod::process
(DL_ABORT_EX("Recursive system.multicall forbidden."), req));
continue;
}
- const SharedHandle<ValueBase>& tempParamsList = methodDict->get(KEY_PARAMS);
- SharedHandle<List> paramsList;
+ const std::shared_ptr<ValueBase>& tempParamsList = methodDict->get(KEY_PARAMS);
+ std::shared_ptr<List> paramsList;
if(downcast<List>(tempParamsList)) {
- paramsList = static_pointer_cast<List>(tempParamsList);
+ paramsList = std::static_pointer_cast<List>(tempParamsList);
} else {
paramsList = List::g();
}
- SharedHandle<RpcMethod> method = RpcMethodFactory::create(methodName->s());
+ std::shared_ptr<RpcMethod> method = RpcMethodFactory::create(methodName->s());
RpcRequest innerReq(methodName->s(), paramsList);
innerReq.jsonRpc = req.jsonRpc;
RpcResponse res = method->execute(innerReq, e);
if(res.code == 0) {
- SharedHandle<List> l = List::g();
+ std::shared_ptr<List> l = List::g();
l->append(res.param);
list->append(l);
} else {
@@ -1408,7 +1408,7 @@ SharedHandle<ValueBase> SystemMulticallRpcMethod::process
return list;
}
-SharedHandle<ValueBase> NoSuchMethodRpcMethod::process
+std::shared_ptr<ValueBase> NoSuchMethodRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
throw DL_ABORT_EX(fmt("No such method: %s", req.methodName.c_str()));
@@ -1417,7 +1417,7 @@ SharedHandle<ValueBase> NoSuchMethodRpcMethod::process
} // namespace rpc
bool pauseRequestGroup
-(const SharedHandle<RequestGroup>& group, bool reserved, bool forcePause)
+(const std::shared_ptr<RequestGroup>& group, bool reserved, bool forcePause)
{
if((reserved && !group->isPauseRequested()) ||
(!reserved &&
@@ -1441,12 +1441,12 @@ bool pauseRequestGroup
}
void changeOption
-(const SharedHandle<RequestGroup>& group,
+(const std::shared_ptr<RequestGroup>& group,
const Option& option,
DownloadEngine* e)
{
- const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
- const SharedHandle<Option>& grOption = group->getOption();
+ const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
+ const std::shared_ptr<Option>& grOption = group->getOption();
grOption->merge(option);
if(option.defined(PREF_CHECKSUM)) {
const std::string& checksum = grOption->get(PREF_CHECKSUM);
@@ -1467,8 +1467,8 @@ void changeOption
}
if(option.defined(PREF_MAX_CONNECTION_PER_SERVER)) {
int maxConn = grOption->getAsInt(PREF_MAX_CONNECTION_PER_SERVER);
- const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries();
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i = files.begin(),
+ const std::vector<std::shared_ptr<FileEntry> >& files = dctx->getFileEntries();
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i = files.begin(),
eoi = files.end(); i != eoi; ++i) {
(*i)->setMaxConnectionPerServer(maxConn);
}
@@ -1507,7 +1507,7 @@ void changeOption
group->setMaxUploadSpeedLimit(grOption->getAsInt(PREF_MAX_UPLOAD_LIMIT));
}
#ifdef ENABLE_BITTORRENT
- const SharedHandle<BtObject>& btObject =
+ const std::shared_ptr<BtObject>& btObject =
e->getBtRegistry()->get(group->getGID());
if(btObject) {
if(option.defined(PREF_BT_MAX_PEERS)) {
diff --git a/src/RpcMethodImpl.h b/src/RpcMethodImpl.h
index 72baf438..04265229 100644
--- a/src/RpcMethodImpl.h
+++ b/src/RpcMethodImpl.h
@@ -127,7 +127,7 @@ void toStringList(OutputIterator out, const List* src)
class AddUriRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -138,7 +138,7 @@ public:
class RemoveRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -149,7 +149,7 @@ public:
class ForceRemoveRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -160,7 +160,7 @@ public:
class PauseRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -171,7 +171,7 @@ public:
class ForcePauseRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -182,7 +182,7 @@ public:
class PauseAllRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -193,7 +193,7 @@ public:
class ForcePauseAllRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -204,7 +204,7 @@ public:
class UnpauseRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -215,7 +215,7 @@ public:
class UnpauseAllRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -227,7 +227,7 @@ public:
#ifdef ENABLE_BITTORRENT
class AddTorrentRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -240,7 +240,7 @@ public:
#ifdef ENABLE_METALINK
class AddMetalinkRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -252,7 +252,7 @@ public:
class PurgeDownloadResultRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -263,7 +263,7 @@ public:
class RemoveDownloadResultRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -274,7 +274,7 @@ public:
class GetUrisRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -285,7 +285,7 @@ public:
class GetFilesRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -297,7 +297,7 @@ public:
#ifdef ENABLE_BITTORRENT
class GetPeersRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -309,7 +309,7 @@ public:
class GetServersRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -320,7 +320,7 @@ public:
class TellStatusRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -331,7 +331,7 @@ public:
class TellActiveRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -374,9 +374,9 @@ private:
return std::make_pair(first, last);
}
protected:
- typedef IndexedList<a2_gid_t, SharedHandle<T> > ItemListType;
+ typedef IndexedList<a2_gid_t, std::shared_ptr<T> > ItemListType;
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e)
{
const Integer* offsetParam = checkRequiredParam<Integer>(req, 0);
@@ -391,9 +391,9 @@ protected:
std::pair<typename ItemListType::const_iterator,
typename ItemListType::const_iterator> range =
getPaginationRange(offset, num, items.begin(), items.end());
- SharedHandle<List> list = List::g();
+ std::shared_ptr<List> list = List::g();
for(; range.first != range.second; ++range.first) {
- SharedHandle<Dict> entryDict = Dict::g();
+ std::shared_ptr<Dict> entryDict = Dict::g();
createEntry(entryDict, *range.first, e, keys);
list->append(entryDict);
}
@@ -406,8 +406,8 @@ protected:
virtual const ItemListType& getItems(DownloadEngine* e) const = 0;
virtual void createEntry
- (const SharedHandle<Dict>& entryDict,
- const SharedHandle<T>& item,
+ (const std::shared_ptr<Dict>& entryDict,
+ const std::shared_ptr<T>& item,
DownloadEngine* e,
const std::vector<std::string>& keys) const = 0;
};
@@ -418,8 +418,8 @@ protected:
virtual const RequestGroupList& getItems(DownloadEngine* e) const;
virtual void createEntry
- (const SharedHandle<Dict>& entryDict,
- const SharedHandle<RequestGroup>& item,
+ (const std::shared_ptr<Dict>& entryDict,
+ const std::shared_ptr<RequestGroup>& item,
DownloadEngine* e,
const std::vector<std::string>& keys) const;
public:
@@ -435,8 +435,8 @@ protected:
virtual const DownloadResultList& getItems(DownloadEngine* e) const;
virtual void createEntry
- (const SharedHandle<Dict>& entryDict,
- const SharedHandle<DownloadResult>& item,
+ (const std::shared_ptr<Dict>& entryDict,
+ const std::shared_ptr<DownloadResult>& item,
DownloadEngine* e,
const std::vector<std::string>& keys) const;
public:
@@ -448,7 +448,7 @@ public:
class ChangeOptionRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -459,7 +459,7 @@ public:
class ChangeGlobalOptionRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -470,7 +470,7 @@ public:
class GetVersionRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -481,7 +481,7 @@ public:
class GetOptionRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -492,7 +492,7 @@ public:
class GetGlobalOptionRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -503,7 +503,7 @@ public:
class ChangePositionRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -514,7 +514,7 @@ public:
class ChangeUriRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -525,7 +525,7 @@ public:
class GetSessionInfoRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -536,7 +536,7 @@ public:
class ShutdownRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -547,7 +547,7 @@ public:
class GetGlobalStatRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -558,7 +558,7 @@ public:
class ForceShutdownRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -569,7 +569,7 @@ public:
class SystemMulticallRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
public:
static const char* getMethodName()
@@ -580,36 +580,36 @@ public:
class NoSuchMethodRpcMethod:public RpcMethod {
protected:
- virtual SharedHandle<ValueBase> process
+ virtual std::shared_ptr<ValueBase> process
(const RpcRequest& req, DownloadEngine* e);
};
// Helper function to store data to entryDict from ds. This function
// is used by tellStatus method.
void gatherStoppedDownload
-(const SharedHandle<Dict>& entryDict, const SharedHandle<DownloadResult>& ds,
+(const std::shared_ptr<Dict>& entryDict, const std::shared_ptr<DownloadResult>& ds,
const std::vector<std::string>& keys);
// Helper function to store data to entryDict from group. This
// function is used by tellStatus/tellActive/tellWaiting method
void gatherProgressCommon
-(const SharedHandle<Dict>& entryDict, const SharedHandle<RequestGroup>& group,
+(const std::shared_ptr<Dict>& entryDict, const std::shared_ptr<RequestGroup>& group,
const std::vector<std::string>& keys);
#ifdef ENABLE_BITTORRENT
// Helper function to store BitTorrent metadata from torrentAttrs.
void gatherBitTorrentMetadata
-(const SharedHandle<Dict>& btDict,
- const SharedHandle<TorrentAttribute>& torrentAttrs);
+(const std::shared_ptr<Dict>& btDict,
+ const std::shared_ptr<TorrentAttribute>& torrentAttrs);
#endif // ENABLE_BITTORRENT
} // namespace rpc
bool pauseRequestGroup
-(const SharedHandle<RequestGroup>& group, bool reserved, bool forcePause);
+(const std::shared_ptr<RequestGroup>& group, bool reserved, bool forcePause);
void changeOption
-(const SharedHandle<RequestGroup>& group,
+(const std::shared_ptr<RequestGroup>& group,
const Option& option,
DownloadEngine* e);
diff --git a/src/RpcRequest.cc b/src/RpcRequest.cc
index af41a4a4..1ed1c1db 100644
--- a/src/RpcRequest.cc
+++ b/src/RpcRequest.cc
@@ -43,13 +43,13 @@ RpcRequest::RpcRequest()
{}
RpcRequest::RpcRequest(const std::string& methodName,
- const SharedHandle<List>& params)
+ const std::shared_ptr<List>& params)
: methodName(methodName), params(params), jsonRpc(false)
{}
RpcRequest::RpcRequest(const std::string& methodName,
- const SharedHandle<List>& params,
- const SharedHandle<ValueBase>& id)
+ const std::shared_ptr<List>& params,
+ const std::shared_ptr<ValueBase>& id)
: methodName(methodName), params(params), id(id), jsonRpc(false)
{}
diff --git a/src/RpcRequest.h b/src/RpcRequest.h
index a6017708..85b75a50 100644
--- a/src/RpcRequest.h
+++ b/src/RpcRequest.h
@@ -47,18 +47,18 @@ namespace rpc {
struct RpcRequest {
std::string methodName;
- SharedHandle<List> params;
- SharedHandle<ValueBase> id;
+ std::shared_ptr<List> params;
+ std::shared_ptr<ValueBase> id;
bool jsonRpc;
RpcRequest();
RpcRequest(const std::string& methodName,
- const SharedHandle<List>& params);
+ const std::shared_ptr<List>& params);
RpcRequest(const std::string& methodName,
- const SharedHandle<List>& params,
- const SharedHandle<ValueBase>& id);
+ const std::shared_ptr<List>& params,
+ const std::shared_ptr<ValueBase>& id);
~RpcRequest();
diff --git a/src/RpcResponse.cc b/src/RpcResponse.cc
index ca7107d9..5f5cab1a 100644
--- a/src/RpcResponse.cc
+++ b/src/RpcResponse.cc
@@ -49,7 +49,7 @@ namespace rpc {
namespace {
template<typename OutputStream>
-void encodeValue(const SharedHandle<ValueBase>& value, OutputStream& o)
+void encodeValue(const std::shared_ptr<ValueBase>& value, OutputStream& o)
{
class XmlValueBaseVisitor:public ValueBaseVisitor {
private:
@@ -104,7 +104,7 @@ void encodeValue(const SharedHandle<ValueBase>& value, OutputStream& o)
namespace {
template<typename OutputStream>
std::string encodeAll
-(OutputStream& o, int code, const SharedHandle<ValueBase>& param)
+(OutputStream& o, int code, const std::shared_ptr<ValueBase>& param)
{
o << "<?xml version=\"1.0\"?>" << "<methodResponse>";
if(code == 0) {
@@ -123,8 +123,8 @@ std::string encodeAll
RpcResponse::RpcResponse
(int code,
- const SharedHandle<ValueBase>& param,
- const SharedHandle<ValueBase>& id)
+ const std::shared_ptr<ValueBase>& param,
+ const std::shared_ptr<ValueBase>& id)
: code(code), param(param), id(id)
{}
@@ -166,14 +166,14 @@ template<typename OutputStream>
OutputStream& encodeJsonAll
(OutputStream& o,
int code,
- const SharedHandle<ValueBase>& param,
- const SharedHandle<ValueBase>& id,
+ const std::shared_ptr<ValueBase>& param,
+ const std::shared_ptr<ValueBase>& id,
const std::string& callback = A2STR::NIL)
{
if(!callback.empty()) {
o << callback << "(";
}
- SharedHandle<Dict> dict = Dict::g();
+ std::shared_ptr<Dict> dict = Dict::g();
dict->put("jsonrpc", "2.0");
dict->put("id", id);
if(code == 0) {
diff --git a/src/RpcResponse.h b/src/RpcResponse.h
index 31f43928..aaa401ea 100644
--- a/src/RpcResponse.h
+++ b/src/RpcResponse.h
@@ -50,14 +50,14 @@ struct RpcResponse {
// 0 for success, non-zero for error
int code;
- SharedHandle<ValueBase> param;
+ std::shared_ptr<ValueBase> param;
- SharedHandle<ValueBase> id;
+ std::shared_ptr<ValueBase> id;
RpcResponse
(int code,
- const SharedHandle<ValueBase>& param,
- const SharedHandle<ValueBase>& id);
+ const std::shared_ptr<ValueBase>& param,
+ const std::shared_ptr<ValueBase>& id);
RpcResponse(const RpcResponse& c);
diff --git a/src/SeedCheckCommand.cc b/src/SeedCheckCommand.cc
index e95c5079..fc536427 100644
--- a/src/SeedCheckCommand.cc
+++ b/src/SeedCheckCommand.cc
@@ -49,7 +49,7 @@ SeedCheckCommand::SeedCheckCommand
(cuid_t cuid,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<SeedCriteria>& seedCriteria)
+ const std::shared_ptr<SeedCriteria>& seedCriteria)
: Command(cuid),
requestGroup_(requestGroup),
e_(e),
@@ -89,18 +89,18 @@ bool SeedCheckCommand::execute() {
}
void SeedCheckCommand::setSeedCriteria
-(const SharedHandle<SeedCriteria>& seedCriteria)
+(const std::shared_ptr<SeedCriteria>& seedCriteria)
{
seedCriteria_ = seedCriteria;
}
-void SeedCheckCommand::setBtRuntime(const SharedHandle<BtRuntime>& btRuntime)
+void SeedCheckCommand::setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
void SeedCheckCommand::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
diff --git a/src/SeedCheckCommand.h b/src/SeedCheckCommand.h
index bcc33bf0..127211ab 100644
--- a/src/SeedCheckCommand.h
+++ b/src/SeedCheckCommand.h
@@ -36,7 +36,8 @@
#define D_SEED_CHECK_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -51,25 +52,25 @@ class SeedCheckCommand : public Command
private:
RequestGroup* requestGroup_;
DownloadEngine* e_;
- SharedHandle<PieceStorage> pieceStorage_;
- SharedHandle<BtRuntime> btRuntime_;
- SharedHandle<SeedCriteria> seedCriteria_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
+ std::shared_ptr<BtRuntime> btRuntime_;
+ std::shared_ptr<SeedCriteria> seedCriteria_;
bool checkStarted_;
public:
SeedCheckCommand(cuid_t cuid,
RequestGroup* requestGroup,
DownloadEngine* e,
- const SharedHandle<SeedCriteria>& seedCriteria);
+ const std::shared_ptr<SeedCriteria>& seedCriteria);
virtual ~SeedCheckCommand();
virtual bool execute();
- void setSeedCriteria(const SharedHandle<SeedCriteria>& seedCriteria);
+ void setSeedCriteria(const std::shared_ptr<SeedCriteria>& seedCriteria);
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
};
} // namespace aria2
diff --git a/src/SeedCriteria.h b/src/SeedCriteria.h
index 5129de62..6c182b59 100644
--- a/src/SeedCriteria.h
+++ b/src/SeedCriteria.h
@@ -36,7 +36,6 @@
#define D_SEED_CRITERIA_H
#include "common.h"
-#include "SharedHandle.h"
namespace aria2 {
diff --git a/src/Segment.h b/src/Segment.h
index bc87cec9..dd17826c 100644
--- a/src/Segment.h
+++ b/src/Segment.h
@@ -39,8 +39,7 @@
#include <stdint.h>
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -83,7 +82,7 @@ public:
virtual void clear(WrDiskCache* diskCache) = 0;
- virtual SharedHandle<Piece> getPiece() const = 0;
+ virtual std::shared_ptr<Piece> getPiece() const = 0;
bool operator==(const Segment& segment) const
{
diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc
index e2c8947f..b872682f 100644
--- a/src/SegmentMan.cc
+++ b/src/SegmentMan.cc
@@ -58,15 +58,15 @@
namespace aria2 {
-SegmentEntry::SegmentEntry(cuid_t cuid, const SharedHandle<Segment>& segment)
+SegmentEntry::SegmentEntry(cuid_t cuid, const std::shared_ptr<Segment>& segment)
: cuid(cuid), segment(segment)
{}
SegmentEntry::~SegmentEntry() {}
SegmentMan::SegmentMan
-(const SharedHandle<DownloadContext>& downloadContext,
- const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<DownloadContext>& downloadContext,
+ const std::shared_ptr<PieceStorage>& pieceStorage)
: downloadContext_(downloadContext),
pieceStorage_(pieceStorage),
ignoreBitfield_(downloadContext->getPieceLength(),
@@ -101,20 +101,20 @@ int64_t SegmentMan::getTotalLength() const
}
}
-void SegmentMan::setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage)
+void SegmentMan::setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
void SegmentMan::setDownloadContext
-(const SharedHandle<DownloadContext>& downloadContext)
+(const std::shared_ptr<DownloadContext>& downloadContext)
{
downloadContext_ = downloadContext;
}
namespace {
void flushWrDiskCache(WrDiskCache* wrDiskCache,
- const SharedHandle<Piece>& piece)
+ const std::shared_ptr<Piece>& piece)
{
piece->flushWrCache(wrDiskCache);
if(piece->getWrDiskCacheEntry()->getError() !=
@@ -128,11 +128,11 @@ void flushWrDiskCache(WrDiskCache* wrDiskCache,
}
} // namespace
-SharedHandle<Segment> SegmentMan::checkoutSegment
-(cuid_t cuid, const SharedHandle<Piece>& piece)
+std::shared_ptr<Segment> SegmentMan::checkoutSegment
+(cuid_t cuid, const std::shared_ptr<Piece>& piece)
{
if(!piece) {
- return SharedHandle<Segment>();
+ return std::shared_ptr<Segment>();
}
A2_LOG_DEBUG(fmt("Attach segment#%lu to CUID#%" PRId64 ".",
static_cast<unsigned long>(piece->getIndex()),
@@ -148,13 +148,13 @@ SharedHandle<Segment> SegmentMan::checkoutSegment
}
piece->setUsedBySegment(true);
- SharedHandle<Segment> segment;
+ std::shared_ptr<Segment> segment;
if(piece->getLength() == 0) {
segment.reset(new GrowSegment(piece));
} else {
segment.reset(new PiecedSegment(downloadContext_->getPieceLength(), piece));
}
- SharedHandle<SegmentEntry> entry(new SegmentEntry(cuid, segment));
+ std::shared_ptr<SegmentEntry> entry(new SegmentEntry(cuid, segment));
usedSegmentEntries_.push_back(entry);
A2_LOG_DEBUG(fmt("index=%lu, length=%d, segmentLength=%d,"
" writtenLength=%d",
@@ -183,20 +183,20 @@ SharedHandle<Segment> SegmentMan::checkoutSegment
}
void SegmentMan::getInFlightSegment
-(std::vector<SharedHandle<Segment> >& segments, cuid_t cuid)
+(std::vector<std::shared_ptr<Segment> >& segments, cuid_t cuid)
{
for(SegmentEntries::const_iterator itr = usedSegmentEntries_.begin(),
eoi = usedSegmentEntries_.end(); itr != eoi; ++itr) {
- const SharedHandle<SegmentEntry>& segmentEntry = *itr;
+ const std::shared_ptr<SegmentEntry>& segmentEntry = *itr;
if(segmentEntry->cuid == cuid) {
segments.push_back(segmentEntry->segment);
}
}
}
-SharedHandle<Segment> SegmentMan::getSegment(cuid_t cuid, size_t minSplitSize)
+std::shared_ptr<Segment> SegmentMan::getSegment(cuid_t cuid, size_t minSplitSize)
{
- SharedHandle<Piece> piece =
+ std::shared_ptr<Piece> piece =
pieceStorage_->getMissingPiece
(minSplitSize,
ignoreBitfield_.getFilterBitfield(), ignoreBitfield_.getBitfieldLength(),
@@ -205,18 +205,18 @@ SharedHandle<Segment> SegmentMan::getSegment(cuid_t cuid, size_t minSplitSize)
}
void SegmentMan::getSegment
-(std::vector<SharedHandle<Segment> >& segments,
+(std::vector<std::shared_ptr<Segment> >& segments,
cuid_t cuid,
size_t minSplitSize,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<FileEntry>& fileEntry,
size_t maxSegments)
{
BitfieldMan filter(ignoreBitfield_);
filter.enableFilter();
filter.addNotFilter(fileEntry->getOffset(), fileEntry->getLength());
- std::vector<SharedHandle<Segment> > pending;
+ std::vector<std::shared_ptr<Segment> > pending;
while(segments.size() < maxSegments) {
- SharedHandle<Segment> segment =
+ std::shared_ptr<Segment> segment =
checkoutSegment(cuid,
pieceStorage_->getMissingPiece
(minSplitSize,
@@ -232,56 +232,56 @@ void SegmentMan::getSegment
segments.push_back(segment);
}
}
- for(std::vector<SharedHandle<Segment> >::const_iterator i = pending.begin(),
+ for(std::vector<std::shared_ptr<Segment> >::const_iterator i = pending.begin(),
eoi = pending.end(); i != eoi; ++i) {
cancelSegment(cuid, *i);
}
}
-SharedHandle<Segment> SegmentMan::getSegmentWithIndex
+std::shared_ptr<Segment> SegmentMan::getSegmentWithIndex
(cuid_t cuid, size_t index) {
if(index > 0 && downloadContext_->getNumPieces() <= index) {
- return SharedHandle<Segment>();
+ return std::shared_ptr<Segment>();
}
return checkoutSegment(cuid, pieceStorage_->getMissingPiece(index, cuid));
}
-SharedHandle<Segment> SegmentMan::getCleanSegmentIfOwnerIsIdle
+std::shared_ptr<Segment> SegmentMan::getCleanSegmentIfOwnerIsIdle
(cuid_t cuid, size_t index)
{
if(index > 0 && downloadContext_->getNumPieces() <= index) {
- return SharedHandle<Segment>();
+ return std::shared_ptr<Segment>();
}
for(SegmentEntries::const_iterator itr = usedSegmentEntries_.begin(),
eoi = usedSegmentEntries_.end(); itr != eoi; ++itr) {
- const SharedHandle<SegmentEntry>& segmentEntry = *itr;
+ const std::shared_ptr<SegmentEntry>& segmentEntry = *itr;
if(segmentEntry->segment->getIndex() == index) {
if(segmentEntry->segment->getWrittenLength() > 0) {
- return SharedHandle<Segment>();
+ return std::shared_ptr<Segment>();
}
if(segmentEntry->cuid == cuid) {
return segmentEntry->segment;
}
cuid_t owner = segmentEntry->cuid;
- SharedHandle<PeerStat> ps = getPeerStat(owner);
+ std::shared_ptr<PeerStat> ps = getPeerStat(owner);
if(!ps || ps->getStatus() == NetStat::IDLE) {
cancelSegment(owner);
return getSegmentWithIndex(cuid, index);
} else {
- return SharedHandle<Segment>();
+ return std::shared_ptr<Segment>();
}
}
}
- return SharedHandle<Segment>();
+ return std::shared_ptr<Segment>();
}
void SegmentMan::cancelSegmentInternal
(cuid_t cuid,
- const SharedHandle<Segment>& segment)
+ const std::shared_ptr<Segment>& segment)
{
A2_LOG_DEBUG(fmt("Canceling segment#%lu",
static_cast<unsigned long>(segment->getIndex())));
- const SharedHandle<Piece>& piece = segment->getPiece();
+ const std::shared_ptr<Piece>& piece = segment->getPiece();
// TODO In PieceStorage::cancelPiece(), WrDiskCacheEntry may be
// released. Flush first.
if(piece->getWrDiskCacheEntry()) {
@@ -316,7 +316,7 @@ void SegmentMan::cancelSegment(cuid_t cuid) {
}
void SegmentMan::cancelSegment
-(cuid_t cuid, const SharedHandle<Segment>& segment)
+(cuid_t cuid, const std::shared_ptr<Segment>& segment)
{
for(SegmentEntries::iterator itr = usedSegmentEntries_.begin(),
eoi = usedSegmentEntries_.end(); itr != eoi;) {
@@ -332,7 +332,7 @@ void SegmentMan::cancelSegment
void SegmentMan::cancelAllSegments()
{
- for(std::deque<SharedHandle<SegmentEntry> >::iterator itr =
+ for(std::deque<std::shared_ptr<SegmentEntry> >::iterator itr =
usedSegmentEntries_.begin(), eoi = usedSegmentEntries_.end();
itr != eoi; ++itr) {
cancelSegmentInternal((*itr)->cuid, (*itr)->segment);
@@ -348,11 +348,11 @@ void SegmentMan::eraseSegmentWrittenLengthMemo()
namespace {
class FindSegmentEntry {
private:
- SharedHandle<Segment> segment_;
+ std::shared_ptr<Segment> segment_;
public:
- FindSegmentEntry(const SharedHandle<Segment>& segment):segment_(segment) {}
+ FindSegmentEntry(const std::shared_ptr<Segment>& segment):segment_(segment) {}
- bool operator()(const SharedHandle<SegmentEntry>& segmentEntry) const
+ bool operator()(const std::shared_ptr<SegmentEntry>& segmentEntry) const
{
return segmentEntry->segment->getIndex() == segment_->getIndex();
}
@@ -360,7 +360,7 @@ public:
} // namespace
bool SegmentMan::completeSegment
-(cuid_t cuid, const SharedHandle<Segment>& segment) {
+(cuid_t cuid, const std::shared_ptr<Segment>& segment) {
pieceStorage_->completePiece(segment->getPiece());
pieceStorage_->advertisePiece(cuid, segment->getPiece()->getIndex());
SegmentEntries::iterator itr = std::find_if(usedSegmentEntries_.begin(),
@@ -386,31 +386,31 @@ int64_t SegmentMan::getDownloadLength() const {
}
}
-void SegmentMan::registerPeerStat(const SharedHandle<PeerStat>& peerStat)
+void SegmentMan::registerPeerStat(const std::shared_ptr<PeerStat>& peerStat)
{
peerStats_.push_back(peerStat);
}
-SharedHandle<PeerStat> SegmentMan::getPeerStat(cuid_t cuid) const
+std::shared_ptr<PeerStat> SegmentMan::getPeerStat(cuid_t cuid) const
{
- for(std::vector<SharedHandle<PeerStat> >::const_iterator i =
+ for(std::vector<std::shared_ptr<PeerStat> >::const_iterator i =
peerStats_.begin(), eoi = peerStats_.end(); i != eoi; ++i) {
if((*i)->getCuid() == cuid) {
return *i;
}
}
- return SharedHandle<PeerStat>();
+ return std::shared_ptr<PeerStat>();
}
namespace {
class PeerStatHostProtoEqual {
private:
- const SharedHandle<PeerStat>& peerStat_;
+ const std::shared_ptr<PeerStat>& peerStat_;
public:
- PeerStatHostProtoEqual(const SharedHandle<PeerStat>& peerStat):
+ PeerStatHostProtoEqual(const std::shared_ptr<PeerStat>& peerStat):
peerStat_(peerStat) {}
- bool operator()(const SharedHandle<PeerStat>& p) const
+ bool operator()(const std::shared_ptr<PeerStat>& p) const
{
return peerStat_->getHostname() == p->getHostname() &&
peerStat_->getProtocol() == p->getProtocol();
@@ -418,9 +418,9 @@ public:
};
} // namespace
-void SegmentMan::updateFastestPeerStat(const SharedHandle<PeerStat>& peerStat)
+void SegmentMan::updateFastestPeerStat(const std::shared_ptr<PeerStat>& peerStat)
{
- std::vector<SharedHandle<PeerStat> >::iterator i =
+ std::vector<std::shared_ptr<PeerStat> >::iterator i =
std::find_if(fastestPeerStats_.begin(), fastestPeerStats_.end(),
PeerStatHostProtoEqual(peerStat));
if(i == fastestPeerStats_.end()) {
@@ -446,7 +446,7 @@ size_t SegmentMan::countFreePieceFrom(size_t index) const
return downloadContext_->getNumPieces()-index;
}
-void SegmentMan::ignoreSegmentFor(const SharedHandle<FileEntry>& fileEntry)
+void SegmentMan::ignoreSegmentFor(const std::shared_ptr<FileEntry>& fileEntry)
{
A2_LOG_DEBUG(fmt("ignoring segment for path=%s, offset=%" PRId64
", length=%" PRId64 "",
@@ -456,7 +456,7 @@ void SegmentMan::ignoreSegmentFor(const SharedHandle<FileEntry>& fileEntry)
ignoreBitfield_.addFilter(fileEntry->getOffset(), fileEntry->getLength());
}
-void SegmentMan::recognizeSegmentFor(const SharedHandle<FileEntry>& fileEntry)
+void SegmentMan::recognizeSegmentFor(const std::shared_ptr<FileEntry>& fileEntry)
{
ignoreBitfield_.removeFilter(fileEntry->getOffset(), fileEntry->getLength());
}
diff --git a/src/SegmentMan.h b/src/SegmentMan.h
index 132f8f28..60dbd625 100644
--- a/src/SegmentMan.h
+++ b/src/SegmentMan.h
@@ -40,8 +40,8 @@
#include <deque>
#include <vector>
#include <map>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
#include "Command.h"
#include "BitfieldMan.h"
@@ -58,9 +58,9 @@ class FileEntry;
struct SegmentEntry {
cuid_t cuid;
- SharedHandle<Segment> segment;
+ std::shared_ptr<Segment> segment;
- SegmentEntry(cuid_t cuid, const SharedHandle<Segment>& segment);
+ SegmentEntry(cuid_t cuid, const std::shared_ptr<Segment>& segment);
~SegmentEntry();
// Don't allow copying
@@ -68,16 +68,16 @@ struct SegmentEntry {
SegmentEntry& operator=(const SegmentEntry&);
};
-typedef std::deque<SharedHandle<SegmentEntry> > SegmentEntries;
+typedef std::deque<std::shared_ptr<SegmentEntry> > SegmentEntries;
/**
* This class holds the download progress of the one download entry.
*/
class SegmentMan {
private:
- SharedHandle<DownloadContext> downloadContext_;
+ std::shared_ptr<DownloadContext> downloadContext_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
SegmentEntries usedSegmentEntries_;
@@ -86,20 +86,20 @@ private:
std::map<size_t, int32_t> segmentWrittenLengthMemo_;
// Used for calculating download speed.
- std::vector<SharedHandle<PeerStat> > peerStats_;
+ std::vector<std::shared_ptr<PeerStat> > peerStats_;
// Keep track of fastest PeerStat for each server
- std::vector<SharedHandle<PeerStat> > fastestPeerStats_;
+ std::vector<std::shared_ptr<PeerStat> > fastestPeerStats_;
BitfieldMan ignoreBitfield_;
- SharedHandle<Segment> checkoutSegment(cuid_t cuid,
- const SharedHandle<Piece>& piece);
+ std::shared_ptr<Segment> checkoutSegment(cuid_t cuid,
+ const std::shared_ptr<Piece>& piece);
- void cancelSegmentInternal(cuid_t cuid, const SharedHandle<Segment>& segment);
+ void cancelSegmentInternal(cuid_t cuid, const std::shared_ptr<Segment>& segment);
public:
- SegmentMan(const SharedHandle<DownloadContext>& downloadContext,
- const SharedHandle<PieceStorage>& pieceStorage);
+ SegmentMan(const std::shared_ptr<DownloadContext>& downloadContext,
+ const std::shared_ptr<PieceStorage>& pieceStorage);
~SegmentMan();
@@ -126,17 +126,17 @@ public:
* Fill segments which are assigned to the command whose CUID is cuid.
* This function doesn't clear passed segments.
*/
- void getInFlightSegment(std::vector<SharedHandle<Segment> >& segments,
+ void getInFlightSegment(std::vector<std::shared_ptr<Segment> >& segments,
cuid_t cuid);
- SharedHandle<Segment> getSegment(cuid_t cuid, size_t minSplitSize);
+ std::shared_ptr<Segment> getSegment(cuid_t cuid, size_t minSplitSize);
// Checkouts segments in the range of fileEntry and push back to
// segments until segments.size() < maxSegments holds false
- void getSegment(std::vector<SharedHandle<Segment> >& segments,
+ void getSegment(std::vector<std::shared_ptr<Segment> >& segments,
cuid_t cuid,
size_t minSplitSize,
- const SharedHandle<FileEntry>& fileEntry,
+ const std::shared_ptr<FileEntry>& fileEntry,
size_t maxSegments);
/**
@@ -145,13 +145,13 @@ public:
* to another cuid or has been downloaded, then returns a segment instance
* whose isNull call is true.
*/
- SharedHandle<Segment> getSegmentWithIndex(cuid_t cuid, size_t index);
+ std::shared_ptr<Segment> getSegmentWithIndex(cuid_t cuid, size_t index);
// Returns a currently used segment whose index is index and written
// length is 0. The current owner(in idle state) of segment cancels
// the segment and cuid command acquires the ownership of the
// segment. If no such segment exists, returns null.
- SharedHandle<Segment> getCleanSegmentIfOwnerIsIdle(cuid_t cuid, size_t index);
+ std::shared_ptr<Segment> getCleanSegmentIfOwnerIsIdle(cuid_t cuid, size_t index);
/**
* Updates download status.
@@ -163,7 +163,7 @@ public:
*/
void cancelSegment(cuid_t cuid);
- void cancelSegment(cuid_t cuid, const SharedHandle<Segment>& segment);
+ void cancelSegment(cuid_t cuid, const std::shared_ptr<Segment>& segment);
void cancelAllSegments();
@@ -172,17 +172,17 @@ public:
/**
* Tells SegmentMan that the segment has been downloaded successfully.
*/
- bool completeSegment(cuid_t cuid, const SharedHandle<Segment>& segment);
+ bool completeSegment(cuid_t cuid, const std::shared_ptr<Segment>& segment);
/**
* Injects PieceStorage.
*/
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
/**
* Injects DownloadContext.
*/
- void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& downloadContext);
/**
* Returns true if the segment whose index is index has been downloaded.
@@ -197,22 +197,22 @@ public:
// If there is inactive PeerStat in peerStats_, it is replaced with
// given peerStat. If no such PeerStat exist, the given peerStat is
// inserted.
- void registerPeerStat(const SharedHandle<PeerStat>& peerStat);
+ void registerPeerStat(const std::shared_ptr<PeerStat>& peerStat);
- const std::vector<SharedHandle<PeerStat> >& getPeerStats() const
+ const std::vector<std::shared_ptr<PeerStat> >& getPeerStats() const
{
return peerStats_;
}
- SharedHandle<PeerStat> getPeerStat(cuid_t cuid) const;
+ std::shared_ptr<PeerStat> getPeerStat(cuid_t cuid) const;
// If there is slower PeerStat than given peerStat for the same
// hostname and protocol in fastestPeerStats_, the former is
// replaced with latter. If there are no PeerStat with same hostname
// and protocol with given peerStat, given peerStat is inserted.
- void updateFastestPeerStat(const SharedHandle<PeerStat>& peerStat);
+ void updateFastestPeerStat(const std::shared_ptr<PeerStat>& peerStat);
- const std::vector<SharedHandle<PeerStat> >& getFastestPeerStats() const
+ const std::vector<std::shared_ptr<PeerStat> >& getFastestPeerStats() const
{
return fastestPeerStats_;
}
@@ -220,10 +220,10 @@ public:
size_t countFreePieceFrom(size_t index) const;
// Excludes segments that fileEntry covers from segment selection.
- void ignoreSegmentFor(const SharedHandle<FileEntry>& fileEntry);
+ void ignoreSegmentFor(const std::shared_ptr<FileEntry>& fileEntry);
// Includes segments that fileEntry covers in segment selection.
- void recognizeSegmentFor(const SharedHandle<FileEntry>& fileEntry);
+ void recognizeSegmentFor(const std::shared_ptr<FileEntry>& fileEntry);
bool allSegmentsIgnored() const;
};
diff --git a/src/SelectEventPoll.cc b/src/SelectEventPoll.cc
index ba0e00ca..c5682b5b 100644
--- a/src/SelectEventPoll.cc
+++ b/src/SelectEventPoll.cc
@@ -126,7 +126,7 @@ int SelectEventPoll::SocketEntry::getEvents()
#ifdef ENABLE_ASYNC_DNS
SelectEventPoll::AsyncNameResolverEntry::AsyncNameResolverEntry
-(const SharedHandle<AsyncNameResolver>& nameResolver, Command* command):
+(const std::shared_ptr<AsyncNameResolver>& nameResolver, Command* command):
nameResolver_(nameResolver), command_(command) {}
int SelectEventPoll::AsyncNameResolverEntry::getFds
@@ -183,7 +183,7 @@ void SelectEventPoll::poll(const struct timeval& tv)
for(AsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.begin(),
eoi = nameResolverEntries_.end(); itr != eoi; ++itr) {
- const SharedHandle<AsyncNameResolverEntry>& entry = *itr;
+ const std::shared_ptr<AsyncNameResolverEntry>& entry = *itr;
int fd = entry->getFds(&rfds, &wfds);
// TODO force error if fd == 0
if(fdmax_ < fd) {
@@ -280,7 +280,7 @@ void SelectEventPoll::updateFdSet()
bool SelectEventPoll::addEvents(sock_t socket, Command* command,
EventPoll::EventType events)
{
- SharedHandle<SocketEntry> socketEntry(new SocketEntry(socket));
+ std::shared_ptr<SocketEntry> socketEntry(new SocketEntry(socket));
SocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
(*i)->addCommandEvent(command, events);
@@ -295,7 +295,7 @@ bool SelectEventPoll::addEvents(sock_t socket, Command* command,
bool SelectEventPoll::deleteEvents(sock_t socket, Command* command,
EventPoll::EventType events)
{
- SharedHandle<SocketEntry> socketEntry(new SocketEntry(socket));
+ std::shared_ptr<SocketEntry> socketEntry(new SocketEntry(socket));
SocketEntrySet::iterator i = socketEntries_.find(socketEntry);
if(i == socketEntries_.end()) {
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
@@ -312,9 +312,9 @@ bool SelectEventPoll::deleteEvents(sock_t socket, Command* command,
#ifdef ENABLE_ASYNC_DNS
bool SelectEventPoll::addNameResolver
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
- SharedHandle<AsyncNameResolverEntry> entry
+ std::shared_ptr<AsyncNameResolverEntry> entry
(new AsyncNameResolverEntry(resolver, command));
AsyncNameResolverEntrySet::iterator itr =
nameResolverEntries_.lower_bound(entry);
@@ -327,9 +327,9 @@ bool SelectEventPoll::addNameResolver
}
bool SelectEventPoll::deleteNameResolver
-(const SharedHandle<AsyncNameResolver>& resolver, Command* command)
+(const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
{
- SharedHandle<AsyncNameResolverEntry> entry
+ std::shared_ptr<AsyncNameResolverEntry> entry
(new AsyncNameResolverEntry(resolver, command));
return nameResolverEntries_.erase(entry) == 1;
}
diff --git a/src/SelectEventPoll.h b/src/SelectEventPoll.h
index f4eeabe6..56623c00 100644
--- a/src/SelectEventPoll.h
+++ b/src/SelectEventPoll.h
@@ -133,12 +133,12 @@ private:
class AsyncNameResolverEntry {
private:
- SharedHandle<AsyncNameResolver> nameResolver_;
+ std::shared_ptr<AsyncNameResolver> nameResolver_;
Command* command_;
public:
- AsyncNameResolverEntry(const SharedHandle<AsyncNameResolver>& nameResolver,
+ AsyncNameResolverEntry(const std::shared_ptr<AsyncNameResolver>& nameResolver,
Command* command);
bool operator==(const AsyncNameResolverEntry& entry)
@@ -164,12 +164,12 @@ private:
fd_set wfdset_;
sock_t fdmax_;
- typedef std::set<SharedHandle<SocketEntry>,
- DerefLess<SharedHandle<SocketEntry> > > SocketEntrySet;
+ typedef std::set<std::shared_ptr<SocketEntry>,
+ DerefLess<std::shared_ptr<SocketEntry> > > SocketEntrySet;
SocketEntrySet socketEntries_;
#ifdef ENABLE_ASYNC_DNS
- typedef std::set<SharedHandle<AsyncNameResolverEntry>,
- DerefLess<SharedHandle<AsyncNameResolverEntry> > >
+ typedef std::set<std::shared_ptr<AsyncNameResolverEntry>,
+ DerefLess<std::shared_ptr<AsyncNameResolverEntry> > >
AsyncNameResolverEntrySet;
AsyncNameResolverEntrySet nameResolverEntries_;
#endif // ENABLE_ASYNC_DNS
@@ -195,10 +195,10 @@ public:
Command* command, EventPoll::EventType events);
#ifdef ENABLE_ASYNC_DNS
- virtual bool addNameResolver(const SharedHandle<AsyncNameResolver>& resolver,
+ virtual bool addNameResolver(const std::shared_ptr<AsyncNameResolver>& resolver,
Command* command);
virtual bool deleteNameResolver
- (const SharedHandle<AsyncNameResolver>& resolver, Command* command);
+ (const std::shared_ptr<AsyncNameResolver>& resolver, Command* command);
#endif // ENABLE_ASYNC_DNS
};
diff --git a/src/SequentialDispatcherCommand.h b/src/SequentialDispatcherCommand.h
index 005d226f..9e0f1e36 100644
--- a/src/SequentialDispatcherCommand.h
+++ b/src/SequentialDispatcherCommand.h
@@ -36,7 +36,9 @@
#define D_SEQUENTIAL_DISPATCHER_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "SequentialPicker.h"
#include "DownloadEngine.h"
#include "RequestGroupMan.h"
@@ -48,7 +50,7 @@ class DownloadEngine;
template<typename T>
class SequentialDispatcherCommand : public Command {
private:
- SharedHandle<SequentialPicker<T> > picker_;
+ std::shared_ptr<SequentialPicker<T> > picker_;
DownloadEngine* e_;
protected:
@@ -58,7 +60,7 @@ protected:
}
public:
SequentialDispatcherCommand(cuid_t cuid,
- const SharedHandle<SequentialPicker<T> >& picker,
+ const std::shared_ptr<SequentialPicker<T> >& picker,
DownloadEngine* e):
Command(cuid), picker_(picker), e_(e)
{
@@ -81,7 +83,7 @@ public:
}
protected:
- virtual Command* createCommand(const SharedHandle<T>& entry) = 0;
+ virtual Command* createCommand(const std::shared_ptr<T>& entry) = 0;
};
} // namespace aria2
diff --git a/src/SequentialPicker.h b/src/SequentialPicker.h
index fac4ac45..6fbb984e 100644
--- a/src/SequentialPicker.h
+++ b/src/SequentialPicker.h
@@ -38,23 +38,22 @@
#include "common.h"
#include <deque>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
template<typename T>
class SequentialPicker {
private:
- std::deque<SharedHandle<T> > entries_;
- SharedHandle<T> pickedEntry_;
+ std::deque<std::shared_ptr<T> > entries_;
+ std::shared_ptr<T> pickedEntry_;
public:
bool isPicked() const
{
- return pickedEntry_;
+ return pickedEntry_.get();
}
- const SharedHandle<T>& getPickedEntry() const
+ const std::shared_ptr<T>& getPickedEntry() const
{
return pickedEntry_;
}
@@ -69,9 +68,9 @@ public:
return !entries_.empty();
}
- SharedHandle<T> pickNext()
+ std::shared_ptr<T> pickNext()
{
- SharedHandle<T> r;
+ std::shared_ptr<T> r;
if(hasNext()) {
r = entries_.front();
entries_.pop_front();
@@ -80,7 +79,7 @@ public:
return r;
}
- void pushEntry(const SharedHandle<T>& entry)
+ void pushEntry(const std::shared_ptr<T>& entry)
{
entries_.push_back(entry);
}
diff --git a/src/ServerStat.h b/src/ServerStat.h
index 6bd33678..7ef66681 100644
--- a/src/ServerStat.h
+++ b/src/ServerStat.h
@@ -38,8 +38,8 @@
#include <string>
#include <iosfwd>
+#include <memory>
-#include "SharedHandle.h"
#include "TimeA2.h"
namespace aria2 {
@@ -170,8 +170,8 @@ private:
class ServerStatFaster {
public:
bool operator()
- (const std::pair<SharedHandle<ServerStat>, std::string> lhs,
- const std::pair<SharedHandle<ServerStat>, std::string> rhs) const
+ (const std::pair<std::shared_ptr<ServerStat>, std::string> lhs,
+ const std::pair<std::shared_ptr<ServerStat>, std::string> rhs) const
{
return lhs.first->getDownloadSpeed() > rhs.first->getDownloadSpeed();
}
diff --git a/src/ServerStatMan.cc b/src/ServerStatMan.cc
index 81ae7db5..ddeca299 100644
--- a/src/ServerStatMan.cc
+++ b/src/ServerStatMan.cc
@@ -56,19 +56,19 @@ ServerStatMan::ServerStatMan() {}
ServerStatMan::~ServerStatMan() {}
-SharedHandle<ServerStat> ServerStatMan::find(const std::string& hostname,
+std::shared_ptr<ServerStat> ServerStatMan::find(const std::string& hostname,
const std::string& protocol) const
{
- SharedHandle<ServerStat> ss(new ServerStat(hostname, protocol));
+ std::shared_ptr<ServerStat> ss(new ServerStat(hostname, protocol));
ServerStatSet::iterator i = serverStats_.find(ss);
if(i == serverStats_.end()) {
- return SharedHandle<ServerStat>();
+ return std::shared_ptr<ServerStat>();
} else {
return *i;
}
}
-bool ServerStatMan::add(const SharedHandle<ServerStat>& serverStat)
+bool ServerStatMan::add(const std::shared_ptr<ServerStat>& serverStat)
{
ServerStatSet::iterator i = serverStats_.lower_bound(serverStat);
if(i != serverStats_.end() && *(*i) == *serverStat) {
@@ -195,7 +195,7 @@ bool ServerStatMan::load(const std::string& filename)
if(m[S_HOST].empty() || m[S_PROTOCOL].empty()) {
continue;
}
- SharedHandle<ServerStat> sstat(new ServerStat(m[S_HOST], m[S_PROTOCOL]));
+ std::shared_ptr<ServerStat> sstat(new ServerStat(m[S_HOST], m[S_PROTOCOL]));
uint32_t uintval;
if(!util::parseUIntNoThrow(uintval, m[S_DL_SPEED])) {
@@ -243,7 +243,7 @@ private:
public:
FindStaleServerStat(time_t timeout):timeout_(timeout) {}
- bool operator()(const SharedHandle<ServerStat>& ss) const
+ bool operator()(const std::shared_ptr<ServerStat>& ss) const
{
return ss->getLastUpdated().difference(time_) >= timeout_;
}
diff --git a/src/ServerStatMan.h b/src/ServerStatMan.h
index 725fdc7c..93710328 100644
--- a/src/ServerStatMan.h
+++ b/src/ServerStatMan.h
@@ -38,8 +38,8 @@
#include <string>
#include <set>
+#include <memory>
-#include "SharedHandle.h"
#include "a2time.h"
#include "a2functional.h"
@@ -53,10 +53,10 @@ public:
~ServerStatMan();
- SharedHandle<ServerStat> find(const std::string& hostname,
+ std::shared_ptr<ServerStat> find(const std::string& hostname,
const std::string& protocol) const;
- bool add(const SharedHandle<ServerStat>& serverStat);
+ bool add(const std::shared_ptr<ServerStat>& serverStat);
bool load(const std::string& filename);
@@ -64,8 +64,8 @@ public:
void removeStaleServerStat(time_t timeout);
private:
- typedef std::set<SharedHandle<ServerStat>,
- DerefLess<SharedHandle<ServerStat> > > ServerStatSet;
+ typedef std::set<std::shared_ptr<ServerStat>,
+ DerefLess<std::shared_ptr<ServerStat> > > ServerStatSet;
ServerStatSet serverStats_;
};
diff --git a/src/SessionSerializer.cc b/src/SessionSerializer.cc
index a0a7613d..17bdef65 100644
--- a/src/SessionSerializer.cc
+++ b/src/SessionSerializer.cc
@@ -60,7 +60,7 @@
namespace aria2 {
SessionSerializer::SessionSerializer
-(const SharedHandle<RequestGroupMan>& requestGroupMan):
+(const std::shared_ptr<RequestGroupMan>& requestGroupMan):
rgman_(requestGroupMan),
saveError_(true),
saveInProgress_(true),
@@ -71,7 +71,7 @@ bool SessionSerializer::save(const std::string& filename) const
std::string tempFilename = filename;
tempFilename += "__temp";
{
- SharedHandle<IOFile> fp;
+ std::shared_ptr<IOFile> fp;
#if HAVE_ZLIB
if (util::endsWith(filename, ".gz")) {
fp.reset(new GZipFile(tempFilename.c_str(), IOFile::WRITE));
@@ -107,9 +107,9 @@ bool writeOptionLine(IOFile& fp, const Pref* pref,
} // namespace
namespace {
-bool writeOption(IOFile& fp, const SharedHandle<Option>& op)
+bool writeOption(IOFile& fp, const std::shared_ptr<Option>& op)
{
- const SharedHandle<OptionParser>& oparser = OptionParser::getInstance();
+ const std::shared_ptr<OptionParser>& oparser = OptionParser::getInstance();
for(size_t i = 1, len = option::countOption(); i < len; ++i) {
const Pref* pref = option::i2p(i);
const OptionHandler* h = oparser->find(pref);
@@ -191,9 +191,9 @@ namespace {
namespace {
bool writeDownloadResult
(IOFile& fp, std::set<a2_gid_t>& metainfoCache,
- const SharedHandle<DownloadResult>& dr)
+ const std::shared_ptr<DownloadResult>& dr)
{
- const SharedHandle<MetadataInfo>& mi = dr->metadataInfo;
+ const std::shared_ptr<MetadataInfo>& mi = dr->metadataInfo;
if(dr->belongsTo != 0 || (mi && mi->dataOnly())) {
return true;
}
@@ -211,7 +211,7 @@ bool writeDownloadResult
if(dr->fileEntries.empty()) {
return true;
}
- const SharedHandle<FileEntry>& file = dr->fileEntries[0];
+ const std::shared_ptr<FileEntry>& file = dr->fileEntries[0];
// Don't save download if there are no URIs.
const bool hasRemaining = !file->getRemainingUris().empty();
const bool hasSpent = !file->getSpentUris().empty();
@@ -267,7 +267,7 @@ bool SessionSerializer::save(IOFile& fp) const
const DownloadResultList& results = rgman_->getDownloadResults();
for(DownloadResultList::const_iterator itr = results.begin(),
eoi = results.end(); itr != eoi; ++itr) {
- const SharedHandle<DownloadResult>& dr = *itr;
+ const std::shared_ptr<DownloadResult>& dr = *itr;
if(dr->result == error_code::FINISHED ||
dr->result == error_code::REMOVED) {
if(dr->option->getAsBool(PREF_FORCE_SAVE)) {
@@ -297,8 +297,8 @@ bool SessionSerializer::save(IOFile& fp) const
const RequestGroupList& groups = rgman_->getRequestGroups();
for(RequestGroupList::const_iterator itr = groups.begin(),
eoi = groups.end(); itr != eoi; ++itr) {
- const SharedHandle<RequestGroup>& rg = *itr;
- SharedHandle<DownloadResult> dr = rg->createDownloadResult();
+ const std::shared_ptr<RequestGroup>& rg = *itr;
+ std::shared_ptr<DownloadResult> dr = rg->createDownloadResult();
bool stopped = dr->result == error_code::FINISHED ||
dr->result == error_code::REMOVED;
if((!stopped && saveInProgress_) ||
@@ -313,8 +313,8 @@ bool SessionSerializer::save(IOFile& fp) const
const RequestGroupList& groups = rgman_->getReservedGroups();
for(RequestGroupList::const_iterator itr = groups.begin(),
eoi = groups.end(); itr != eoi; ++itr) {
- const SharedHandle<RequestGroup>& rg = *itr;
- SharedHandle<DownloadResult> result = rg->createDownloadResult();
+ const std::shared_ptr<RequestGroup>& rg = *itr;
+ std::shared_ptr<DownloadResult> result = rg->createDownloadResult();
if(!writeDownloadResult(fp, metainfoCache, result)) {
return false;
}
diff --git a/src/SessionSerializer.h b/src/SessionSerializer.h
index 15c1e6c1..a72aafdf 100644
--- a/src/SessionSerializer.h
+++ b/src/SessionSerializer.h
@@ -39,8 +39,7 @@
#include <string>
#include <iosfwd>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -49,13 +48,13 @@ class IOFile;
class SessionSerializer {
private:
- SharedHandle<RequestGroupMan> rgman_;
+ std::shared_ptr<RequestGroupMan> rgman_;
bool saveError_;
bool saveInProgress_;
bool saveWaiting_;
bool save(IOFile& fp) const;
public:
- SessionSerializer(const SharedHandle<RequestGroupMan>& requestGroupMan);
+ SessionSerializer(const std::shared_ptr<RequestGroupMan>& requestGroupMan);
bool save(const std::string& filename) const;
};
diff --git a/src/ShareRatioSeedCriteria.cc b/src/ShareRatioSeedCriteria.cc
index 6fb81dbb..5c0ffc4e 100644
--- a/src/ShareRatioSeedCriteria.cc
+++ b/src/ShareRatioSeedCriteria.cc
@@ -40,7 +40,7 @@
namespace aria2 {
ShareRatioSeedCriteria::ShareRatioSeedCriteria
-(double ratio, const SharedHandle<DownloadContext>& downloadContext)
+(double ratio, const std::shared_ptr<DownloadContext>& downloadContext)
: ratio_(ratio),
downloadContext_(downloadContext)
{}
@@ -62,13 +62,13 @@ bool ShareRatioSeedCriteria::evaluate()
void ShareRatioSeedCriteria::setBtRuntime
-(const SharedHandle<BtRuntime>& btRuntime)
+(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
void ShareRatioSeedCriteria::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
diff --git a/src/ShareRatioSeedCriteria.h b/src/ShareRatioSeedCriteria.h
index 9084d56d..e61e2a66 100644
--- a/src/ShareRatioSeedCriteria.h
+++ b/src/ShareRatioSeedCriteria.h
@@ -37,6 +37,8 @@
#include "SeedCriteria.h"
+#include <memory>
+
namespace aria2 {
class DownloadContext;
@@ -46,12 +48,12 @@ class PieceStorage;
class ShareRatioSeedCriteria : public SeedCriteria {
private:
double ratio_;
- SharedHandle<DownloadContext> downloadContext_;
- SharedHandle<BtRuntime> btRuntime_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<DownloadContext> downloadContext_;
+ std::shared_ptr<BtRuntime> btRuntime_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
public:
ShareRatioSeedCriteria
- (double ratio, const SharedHandle<DownloadContext>& downloadContext);
+ (double ratio, const std::shared_ptr<DownloadContext>& downloadContext);
virtual ~ShareRatioSeedCriteria();
@@ -67,9 +69,9 @@ public:
return ratio_;
}
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
};
} // namespace aria2
diff --git a/src/SharedHandle.cc b/src/SharedHandle.cc
deleted file mode 100644
index 9986f2f9..00000000
--- a/src/SharedHandle.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-/* <!-- copyright */
-/*
- * aria2 - The high speed download utility
- *
- * Copyright (C) 2012 Tatsuhiro Tsujikawa
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * In addition, as a special exception, the copyright holders give
- * permission to link the code of portions of this program with the
- * OpenSSL library under certain conditions as described in each
- * individual source file, and distribute linked combinations
- * including the two.
- * You must obey the GNU General Public License in all respects
- * for all of the code used other than OpenSSL. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you
- * do not wish to do so, delete this exception statement from your
- * version. If you delete this exception statement from all source
- * files in the program, then also delete it here.
- */
-/* copyright --> */
-#include "SharedHandle.h"
-
-namespace aria2 {
-
-SharedCount::SharedCount():refCount_(new RefCount()) {}
-
-SharedCount::SharedCount(const SharedCount& s):refCount_(s.refCount_)
-{
- refCount_->addRefCount();
-}
-
-SharedCount::~SharedCount()
-{
- refCount_->releaseRefCount();
- if(refCount_->getWeakRefCount() == 0) {
- delete refCount_;
- }
-}
-
-bool SharedCount::reassign(const SharedCount& s)
-{
- s.refCount_->addRefCount();
- refCount_->releaseRefCount();
- if(refCount_->getWeakRefCount() == 0) {
- delete refCount_;
- refCount_ = s.refCount_;
- return true;
- }
- size_t thisCount = refCount_->getStrongRefCount();
- refCount_ = s.refCount_;
- return thisCount == 0;
-}
-
-void SharedCount::swap(SharedCount& r)
-{
- std::swap(refCount_, r.refCount_);
-}
-
-WeakCount::WeakCount(const WeakRef& t):refCount_(new RefCount(t)) {}
-
-WeakCount::WeakCount(const StrongRef& t):refCount_(new RefCount()) {}
-
-WeakCount::WeakCount(const WeakCount& w):refCount_(w.refCount_)
-{
- refCount_->addWeakRefCount();
-}
-
-WeakCount::WeakCount(const SharedCount& s):refCount_(s.refCount_)
-{
- refCount_->addWeakRefCount();
-}
-
-WeakCount::~WeakCount()
-{
- refCount_->releaseWeakRefCount();
- if(refCount_->getWeakRefCount() == 0) {
- delete refCount_;
- }
-}
-
-bool WeakCount::reassign(const SharedCount& s)
-{
- s.refCount_->addWeakRefCount();
- refCount_->releaseWeakRefCount();
- if(refCount_->getWeakRefCount() == 0) {
- delete refCount_;
- refCount_ = s.refCount_;
- return true;
- }
- refCount_ = s.refCount_;
- return false;
-}
-
-bool WeakCount::reassign(const WeakCount& s)
-{
- s.refCount_->addWeakRefCount();
- refCount_->releaseWeakRefCount();
- if(refCount_->getWeakRefCount() == 0) {
- delete refCount_;
- refCount_ = s.refCount_;
- return true;
- }
- refCount_ = s.refCount_;
- return false;
-}
-
-} // namespace aria2
diff --git a/src/SharedHandle.h b/src/SharedHandle.h
deleted file mode 100644
index fa18c434..00000000
--- a/src/SharedHandle.h
+++ /dev/null
@@ -1,398 +0,0 @@
-/* <!-- copyright */
-/*
- * aria2 - The high speed download utility
- *
- * Copyright (C) 2012 Tatsuhiro Tsujikawa
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * In addition, as a special exception, the copyright holders give
- * permission to link the code of portions of this program with the
- * OpenSSL library under certain conditions as described in each
- * individual source file, and distribute linked combinations
- * including the two.
- * You must obey the GNU General Public License in all respects
- * for all of the code used other than OpenSSL. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you
- * do not wish to do so, delete this exception statement from your
- * version. If you delete this exception statement from all source
- * files in the program, then also delete it here.
- */
-/* copyright --> */
-#ifndef D_SHARED_HANDLE_H
-#define D_SHARED_HANDLE_H
-
-#include <cassert>
-#include <iosfwd>
-#include <algorithm>
-
-// To Use std::tr1::shared_ptr uncomment following few lines and
-// comment out SharedHandle stuff.
-//
-// #include <tr1/memory>
-// #define SharedHandle std::tr1::shared_ptr
-// #define WeakHandle std::tr1::weak_ptr
-// using std::tr1::static_pointer_cast;
-// using std::tr1::dynamic_pointer_cast;
-
-namespace aria2 {
-
-typedef struct StrongRef {} StrongRef;
-typedef struct WeakRef {} WeakRef;
-
-class RefCount {
-private:
- size_t strongRefCount_;
- size_t weakRefCount_;
-public:
- RefCount():strongRefCount_(1), weakRefCount_(1) {}
-
- RefCount(const WeakRef&):strongRefCount_(0), weakRefCount_(1) {}
-
- inline void addRefCount() {
- ++strongRefCount_;
- ++weakRefCount_;
- }
-
- inline void addWeakRefCount() {
- ++weakRefCount_;
- }
-
- inline void releaseRefCount() {
- --strongRefCount_;
- --weakRefCount_;
- }
-
- inline void releaseWeakRefCount() {
- --weakRefCount_;
- }
-
- inline size_t getStrongRefCount() { return strongRefCount_; }
-
- inline size_t getWeakRefCount() { return weakRefCount_; }
-};
-
-class WeakCount;
-
-class SharedCount {
-private:
- friend class WeakCount;
-
- RefCount* refCount_;
-public:
- SharedCount();
-
- SharedCount(const SharedCount& s);
-
- ~SharedCount();
-
- bool reassign(const SharedCount& s);
-
- inline size_t getRefCount() const { return refCount_->getStrongRefCount(); }
-
- void swap(SharedCount& r);
-};
-
-class WeakCount {
-private:
- RefCount* refCount_;
-public:
- WeakCount(const WeakRef& t);
-
- WeakCount(const StrongRef& t);
-
- WeakCount(const WeakCount& w);
-
- WeakCount(const SharedCount& s);
-
- ~WeakCount();
-
- bool reassign(const SharedCount& s);
-
- bool reassign(const WeakCount& s);
-
- inline size_t getRefCount() const { return refCount_->getStrongRefCount(); }
-};
-
-template<typename T>
-class SharedHandle;
-
-template<typename T>
-class WeakHandle;
-
-template<typename T>
-class SharedHandle {
-private:
- template<typename T1>
- friend std::ostream& operator<<(std::ostream& o, const SharedHandle<T1>& sp);
-
- template<typename T1, typename T2>
- friend bool operator==(const SharedHandle<T1>& t1,
- const SharedHandle<T2>& t2);
-
- template<typename T1, typename T2>
- friend bool operator!=(const SharedHandle<T1>& t1,
- const SharedHandle<T2>& t2);
-
- template<typename T1, typename T2>
- friend bool operator<(const SharedHandle<T1>& t1, const SharedHandle<T2>& t2);
-
- template<typename S> friend class SharedHandle;
-
- template<typename S> friend class WeakHandle;
-
- T* obj_;
-
- SharedCount ucount_;
-
-public:
- SharedHandle():obj_(0), ucount_() {}
-
- explicit SharedHandle(T* obj):obj_(obj), ucount_() {}
-
- SharedHandle(const SharedHandle& t):obj_(t.obj_), ucount_(t.ucount_) {}
-
- template<typename S>
- SharedHandle(const SharedHandle<S>& t):obj_(t.obj_), ucount_(t.ucount_) {}
-
- template<typename S>
- SharedHandle(const SharedHandle<S>& t, T* p):
- obj_(p), ucount_(t.ucount_) {}
-
- ~SharedHandle() {
- if(ucount_.getRefCount() == 1) {
- delete obj_;
- }
- }
-
- SharedHandle& operator=(const SharedHandle& t) {
- if(ucount_.reassign(t.ucount_)) {
- delete obj_;
- }
- obj_ = t.obj_;
- return *this;
- }
-
- template<typename S>
- SharedHandle& operator=(const SharedHandle<S>& t) {
- if(ucount_.reassign(t.ucount_)) {
- delete obj_;
- }
- obj_ = t.obj_;
- return *this;
- }
-
-private:
- typedef T* SharedHandle::*unspecified_bool_type;
-public:
- operator unspecified_bool_type() const {
- return obj_ == 0 ? 0 : &SharedHandle::obj_;
- }
-
- T* operator->() const { return obj_; }
-
- T& operator*() const {
- assert(obj_);
- return *obj_;
- }
-
- T* get() const {
- return obj_;
- }
-
- size_t getRefCount() const {
- return ucount_.getRefCount();
- }
-
- void reset() {
- *this = SharedHandle();
- }
-
- void reset(T* t) {
- *this = SharedHandle(t);
- }
-
- void swap(SharedHandle& other)
- {
- std::swap(obj_, other.obj_);
- ucount_.swap(other.ucount_);
- }
-};
-
-template<typename T>
-void swap(SharedHandle<T>& a, SharedHandle<T>& b)
-{
- a.swap(b);
-}
-
-template<typename T, typename S>
-SharedHandle<T>
-dynamic_pointer_cast(const SharedHandle<S>& t) {
- if(T* p = dynamic_cast<T*>(t.get())) {
- return SharedHandle<T>(t, p);
- } else {
- return SharedHandle<T>();
- }
-}
-
-template<typename T, typename S>
-SharedHandle<T>
-static_pointer_cast(const SharedHandle<S>& t) {
- return SharedHandle<T>(t, static_cast<T*>(t.get()));
-}
-
-// Intentionally renamed obj_ as obj_x to cause error
-template<typename T>
-std::ostream& operator<<(std::ostream& o, const SharedHandle<T>& sp) {
- o << *sp.obj_x;
- return o;
-}
-
-template<typename T1, typename T2>
-bool operator==(const SharedHandle<T1>& t1, const SharedHandle<T2>& t2) {
- return *t1.obj_x == *t2.obj_;
-}
-
-template<typename T1, typename T2>
-bool operator!=(const SharedHandle<T1>& t1, const SharedHandle<T2>& t2) {
- return *t1.obj_x != *t2.obj_;
-}
-
-template<typename T1, typename T2>
-bool operator<(const SharedHandle<T1>& t1, const SharedHandle<T2>& t2) {
- return *t1.obj_x < *t2.obj_;
-}
-
-template<typename T>
-class WeakHandle {
-private:
- template<typename T1>
- friend std::ostream& operator<<(std::ostream& o, const WeakHandle<T1>& sp);
-
- template<typename T1, typename T2>
- friend bool operator==(const WeakHandle<T1>& t1,
- const WeakHandle<T2>& t2);
-
- template<typename T1, typename T2>
- friend bool operator!=(const WeakHandle<T1>& t1,
- const WeakHandle<T2>& t2);
-
- template<typename T1, typename T2>
- friend bool operator<(const WeakHandle<T1>& t1, const WeakHandle<T2>& t2);
-
- template<typename S> friend class WeakHandle;
-
- T* obj_;
-
- WeakCount ucount_;
-
-public:
- WeakHandle():obj_(0), ucount_(WeakRef()) {}
-
- explicit WeakHandle(T* obj):obj_(obj), ucount_(StrongRef()) {}
-
- WeakHandle(const WeakHandle& t):obj_(t.obj_), ucount_(t.ucount_) {}
-
- template<typename S>
- WeakHandle(const SharedHandle<S>& t):obj_(t.obj_), ucount_(t.ucount_) {}
-
- template<typename S>
- WeakHandle(const WeakHandle<S>& t, T* p):
- obj_(p), ucount_(t.ucount_) {}
-
- ~WeakHandle() {}
-
- WeakHandle& operator=(const WeakHandle& t) {
- ucount_.reassign(t.ucount_);
- obj_ = t.obj_;
- return *this;
- }
-
- template<typename S>
- WeakHandle& operator=(const SharedHandle<S>& t) {
- ucount_.reassign(t.ucount_);
- obj_ = t.obj_;
- return *this;
- }
-
- template<typename S>
- WeakHandle& operator=(const WeakHandle<S>& t) {
- ucount_.reassign(t.ucount_);
- obj_ = t.obj_;
- return *this;
- }
-
- T* operator->() { return obj_; }
-
- T* operator->() const { return obj_; }
-
- T& operator*() const {
- assert(obj_);
- return *obj_;
- }
-
- T* get() const {
- if(ucount_.getRefCount() == 0 || obj_ == 0) {
- return 0;
- } else {
- return obj_;
- }
- }
-
- size_t getRefCount() const {
- return ucount_.getRefCount();
- }
-
- void reset() {
- *this = WeakHandle();
- }
-};
-
-// Intentionally renamed obj_ as obj_x to cause error
-template<typename T>
-std::ostream& operator<<(std::ostream& o, const WeakHandle<T>& sp) {
- o << *sp.obj_x;
- return o;
-}
-
-template<typename T1, typename T2>
-bool operator==(const WeakHandle<T1>& t1, const WeakHandle<T2>& t2) {
- return *t1.obj_x == *t2.obj_;
-}
-
-template<typename T1, typename T2>
-bool operator!=(const WeakHandle<T1>& t1, const WeakHandle<T2>& t2) {
- return *t1.obj_x != *t2.obj_;
-}
-
-template<typename T1, typename T2>
-bool operator<(const WeakHandle<T1>& t1, const WeakHandle<T2>& t2) {
- return *t1.obj_x < *t2.obj_;
-}
-
-template<typename T, typename S>
-WeakHandle<T>
-dynamic_pointer_cast(const WeakHandle<S>& t) {
- if(T* p = dynamic_cast<T*>(t.get())) {
- return WeakHandle<T>(t, p);
- } else {
- return WeakHandle<T>();
- }
-}
-
-} // namespace aria2
-
-#endif // D_SHARED_HANDLE_H
diff --git a/src/Signature.h b/src/Signature.h
index 71803af0..940f89e5 100644
--- a/src/Signature.h
+++ b/src/Signature.h
@@ -39,8 +39,6 @@
#include <string>
-#include "SharedHandle.h"
-
namespace aria2 {
class Signature {
diff --git a/src/SimpleRandomizer.cc b/src/SimpleRandomizer.cc
index 9f23ea77..ed27d586 100644
--- a/src/SimpleRandomizer.cc
+++ b/src/SimpleRandomizer.cc
@@ -42,9 +42,9 @@
namespace aria2 {
-SharedHandle<SimpleRandomizer> SimpleRandomizer::randomizer_;
+std::shared_ptr<SimpleRandomizer> SimpleRandomizer::randomizer_;
-const SharedHandle<SimpleRandomizer>& SimpleRandomizer::getInstance()
+const std::shared_ptr<SimpleRandomizer>& SimpleRandomizer::getInstance()
{
if(!randomizer_) {
randomizer_.reset(new SimpleRandomizer());
diff --git a/src/SimpleRandomizer.h b/src/SimpleRandomizer.h
index abbd2d46..63309fb0 100644
--- a/src/SimpleRandomizer.h
+++ b/src/SimpleRandomizer.h
@@ -37,17 +37,17 @@
#include "Randomizer.h"
+#include <memory>
+
#ifdef __MINGW32__
# include <wincrypt.h>
#endif // __MINGW32__
-#include "SharedHandle.h"
-
namespace aria2 {
class SimpleRandomizer : public Randomizer {
private:
- static SharedHandle<SimpleRandomizer> randomizer_;
+ static std::shared_ptr<SimpleRandomizer> randomizer_;
#ifdef __MINGW32__
HCRYPTPROV cryProvider_;
@@ -56,7 +56,7 @@ private:
SimpleRandomizer();
public:
- static const SharedHandle<SimpleRandomizer>& getInstance();
+ static const std::shared_ptr<SimpleRandomizer>& getInstance();
static void init();
diff --git a/src/SingletonHolder.h b/src/SingletonHolder.h
index dcfe9e33..323773aa 100644
--- a/src/SingletonHolder.h
+++ b/src/SingletonHolder.h
@@ -35,25 +35,27 @@
#ifndef D_SINGLETON_HOLDER_H
#define D_SINGLETON_HOLDER_H
-#include "SharedHandle.h"
+#include "common.h"
+
+#include <memory>
namespace aria2 {
template<typename T>
class SingletonHolder {
private:
- static SharedHandle<T> instance_;
+ static std::shared_ptr<T> instance_;
SingletonHolder() {}
public:
~SingletonHolder() {}
- static const SharedHandle<T>& instance()
+ static const std::shared_ptr<T>& instance()
{
return instance_;
}
- static void instance(const SharedHandle<T>& instance)
+ static void instance(const std::shared_ptr<T>& instance)
{
instance_ = instance;
}
@@ -65,7 +67,7 @@ public:
};
template<typename T>
-SharedHandle<T> SingletonHolder<T>::instance_;
+std::shared_ptr<T> SingletonHolder<T>::instance_;
} // namespace aria2
diff --git a/src/SinkStreamFilter.cc b/src/SinkStreamFilter.cc
index e7f296ea..452caae4 100644
--- a/src/SinkStreamFilter.cc
+++ b/src/SinkStreamFilter.cc
@@ -35,6 +35,7 @@
#include "SinkStreamFilter.h"
#include <cstring>
+#include <cassert>
#include "BinaryStream.h"
#include "Segment.h"
@@ -51,8 +52,8 @@ SinkStreamFilter::SinkStreamFilter(WrDiskCache* wrDiskCache, bool hashUpdate):
bytesProcessed_(0) {}
ssize_t SinkStreamFilter::transform
-(const SharedHandle<BinaryStream>& out,
- const SharedHandle<Segment>& segment,
+(const std::shared_ptr<BinaryStream>& out,
+ const std::shared_ptr<Segment>& segment,
const unsigned char* inbuf, size_t inlen)
{
size_t wlen;
@@ -66,7 +67,7 @@ ssize_t SinkStreamFilter::transform
} else {
wlen = inlen;
}
- const SharedHandle<Piece>& piece = segment->getPiece();
+ const std::shared_ptr<Piece>& piece = segment->getPiece();
if(piece->getWrDiskCacheEntry()) {
assert(wrDiskCache_);
// If we receive small data (e.g., 1 or 2 bytes), cache entry
diff --git a/src/SinkStreamFilter.h b/src/SinkStreamFilter.h
index 908489a9..6fe85cd6 100644
--- a/src/SinkStreamFilter.h
+++ b/src/SinkStreamFilter.h
@@ -52,8 +52,8 @@ public:
virtual void init() {}
virtual ssize_t transform
- (const SharedHandle<BinaryStream>& out,
- const SharedHandle<Segment>& segment,
+ (const std::shared_ptr<BinaryStream>& out,
+ const std::shared_ptr<Segment>& segment,
const unsigned char* inbuf, size_t inlen);
virtual bool finished()
@@ -75,7 +75,7 @@ public:
return bytesProcessed_;
}
- virtual bool installDelegate(const SharedHandle<StreamFilter>& filter)
+ virtual bool installDelegate(const std::shared_ptr<StreamFilter>& filter)
{
return false;
}
diff --git a/src/SocketBuffer.cc b/src/SocketBuffer.cc
index 85bc8250..eefce402 100644
--- a/src/SocketBuffer.cc
+++ b/src/SocketBuffer.cc
@@ -56,7 +56,7 @@ SocketBuffer::ByteArrayBufEntry::~ByteArrayBufEntry()
}
ssize_t SocketBuffer::ByteArrayBufEntry::send
-(const SharedHandle<SocketCore>& socket, size_t offset)
+(const std::shared_ptr<SocketCore>& socket, size_t offset)
{
return socket->writeData(bytes_+offset, length_-offset);
}
@@ -84,7 +84,7 @@ SocketBuffer::StringBufEntry::StringBufEntry(const std::string& s,
// SocketBuffer::StringBufEntry::StringBufEntry() {}
ssize_t SocketBuffer::StringBufEntry::send
-(const SharedHandle<SocketCore>& socket, size_t offset)
+(const std::shared_ptr<SocketCore>& socket, size_t offset)
{
return socket->writeData(str_.data()+offset, str_.size()-offset);
}
@@ -109,7 +109,7 @@ void SocketBuffer::StringBufEntry::swap(std::string& s)
str_.swap(s);
}
-SocketBuffer::SocketBuffer(const SharedHandle<SocketCore>& socket):
+SocketBuffer::SocketBuffer(const std::shared_ptr<SocketCore>& socket):
socket_(socket), offset_(0) {}
SocketBuffer::~SocketBuffer() {}
@@ -118,7 +118,7 @@ void SocketBuffer::pushBytes(unsigned char* bytes, size_t len,
ProgressUpdate* progressUpdate)
{
if(len > 0) {
- bufq_.push_back(SharedHandle<BufEntry>
+ bufq_.push_back(std::shared_ptr<BufEntry>
(new ByteArrayBufEntry(bytes, len, progressUpdate)));
}
}
@@ -127,7 +127,7 @@ void SocketBuffer::pushStr(const std::string& data,
ProgressUpdate* progressUpdate)
{
if(data.size() > 0) {
- bufq_.push_back(SharedHandle<BufEntry>
+ bufq_.push_back(std::shared_ptr<BufEntry>
(new StringBufEntry(data, progressUpdate)));
}
}
@@ -147,7 +147,7 @@ ssize_t SocketBuffer::send()
iov[0].A2IOVEC_LEN = firstlen;
for(num = 1; num < A2_IOV_MAX && num < bufq_.size() && amount > 0; ++num) {
- const SharedHandle<BufEntry>& buf = bufq_[num];
+ const std::shared_ptr<BufEntry>& buf = bufq_[num];
ssize_t len = buf->getLength();
if(amount >= len) {
amount -= len;
@@ -176,7 +176,7 @@ ssize_t SocketBuffer::send()
bufq_.pop_front();
offset_ = 0;
for(size_t i = 1; i < num; ++i) {
- const SharedHandle<BufEntry>& buf = bufq_[0];
+ const std::shared_ptr<BufEntry>& buf = bufq_[0];
ssize_t len = buf->getLength();
if(len > slen) {
offset_ = slen;
diff --git a/src/SocketBuffer.h b/src/SocketBuffer.h
index a8b13235..67855180 100644
--- a/src/SocketBuffer.h
+++ b/src/SocketBuffer.h
@@ -39,8 +39,7 @@
#include <string>
#include <deque>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -62,7 +61,7 @@ private:
delete progressUpdate_;
}
virtual ssize_t send
- (const SharedHandle<SocketCore>& socket, size_t offset) = 0;
+ (const std::shared_ptr<SocketCore>& socket, size_t offset) = 0;
virtual bool final(size_t offset) const = 0;
virtual size_t getLength() const = 0;
virtual const unsigned char* getData() const = 0;
@@ -82,7 +81,7 @@ private:
ProgressUpdate* progressUpdate);
virtual ~ByteArrayBufEntry();
virtual ssize_t send
- (const SharedHandle<SocketCore>& socket, size_t offset);
+ (const std::shared_ptr<SocketCore>& socket, size_t offset);
virtual bool final(size_t offset) const;
virtual size_t getLength() const;
virtual const unsigned char* getData() const;
@@ -97,7 +96,7 @@ private:
ProgressUpdate* progressUpdate);
StringBufEntry();
virtual ssize_t send
- (const SharedHandle<SocketCore>& socket, size_t offset);
+ (const std::shared_ptr<SocketCore>& socket, size_t offset);
virtual bool final(size_t offset) const;
virtual size_t getLength() const;
virtual const unsigned char* getData() const;
@@ -106,16 +105,16 @@ private:
std::string str_;
};
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<SocketCore> socket_;
- std::deque<SharedHandle<BufEntry> > bufq_;
+ std::deque<std::shared_ptr<BufEntry> > bufq_;
// Offset of data in bufq_[0]. SocketBuffer tries to send bufq_[0],
// but it cannot always send whole data. In this case, offset points
// to the data to be sent in the next send() call.
size_t offset_;
public:
- SocketBuffer(const SharedHandle<SocketCore>& socket);
+ SocketBuffer(const std::shared_ptr<SocketCore>& socket);
~SocketBuffer();
diff --git a/src/SocketCore.cc b/src/SocketCore.cc
index be8be55f..a3f24306 100644
--- a/src/SocketCore.cc
+++ b/src/SocketCore.cc
@@ -134,17 +134,17 @@ std::vector<std::pair<sockaddr_union, socklen_t> >
SocketCore::bindAddrs_;
#ifdef ENABLE_SSL
-SharedHandle<TLSContext> SocketCore::clTlsContext_;
-SharedHandle<TLSContext> SocketCore::svTlsContext_;
+std::shared_ptr<TLSContext> SocketCore::clTlsContext_;
+std::shared_ptr<TLSContext> SocketCore::svTlsContext_;
void SocketCore::setClientTLSContext
-(const SharedHandle<TLSContext>& tlsContext)
+(const std::shared_ptr<TLSContext>& tlsContext)
{
clTlsContext_ = tlsContext;
}
void SocketCore::setServerTLSContext
-(const SharedHandle<TLSContext>& tlsContext)
+(const std::shared_ptr<TLSContext>& tlsContext)
{
svTlsContext_ = tlsContext;
}
@@ -344,7 +344,7 @@ void SocketCore::beginListen()
setNonBlockingMode();
}
-SharedHandle<SocketCore> SocketCore::acceptConnection() const
+std::shared_ptr<SocketCore> SocketCore::acceptConnection() const
{
sockaddr_union sockaddr;
socklen_t len = sizeof(sockaddr);
@@ -355,7 +355,7 @@ SharedHandle<SocketCore> SocketCore::acceptConnection() const
if(fd == (sock_t) -1) {
throw DL_ABORT_EX(fmt(EX_SOCKET_ACCEPT, errorMsg(errNum).c_str()));
}
- SharedHandle<SocketCore> sock(new SocketCore(fd, sockType_));
+ std::shared_ptr<SocketCore> sock(new SocketCore(fd, sockType_));
sock->setNonBlockingMode();
return sock;
}
diff --git a/src/SocketCore.h b/src/SocketCore.h
index 5d27fe2e..de7065d4 100644
--- a/src/SocketCore.h
+++ b/src/SocketCore.h
@@ -41,9 +41,9 @@
#include <cstdlib>
#include <utility>
#include <vector>
+#include <memory>
#include "a2netcompat.h"
-#include "SharedHandle.h"
#include "a2io.h"
#include "a2netcompat.h"
#include "a2time.h"
@@ -77,11 +77,11 @@ private:
#if ENABLE_SSL
// TLS context for client side
- static SharedHandle<TLSContext> clTlsContext_;
+ static std::shared_ptr<TLSContext> clTlsContext_;
// TLS context for server side
- static SharedHandle<TLSContext> svTlsContext_;
+ static std::shared_ptr<TLSContext> svTlsContext_;
- SharedHandle<TLSSession> tlsSession_;
+ std::shared_ptr<TLSSession> tlsSession_;
/**
* Makes this socket secure. The connection must be established
@@ -177,7 +177,7 @@ public:
* You must call beginListen() before calling this method.
* @return accepted socket.
*/
- SharedHandle<SocketCore> acceptConnection() const;
+ std::shared_ptr<SocketCore> acceptConnection() const;
/**
* Connects to the server named host and the destination port is port.
@@ -307,8 +307,8 @@ public:
bool wantWrite() const;
#ifdef ENABLE_SSL
- static void setClientTLSContext(const SharedHandle<TLSContext>& tlsContext);
- static void setServerTLSContext(const SharedHandle<TLSContext>& tlsContext);
+ static void setClientTLSContext(const std::shared_ptr<TLSContext>& tlsContext);
+ static void setServerTLSContext(const std::shared_ptr<TLSContext>& tlsContext);
#endif // ENABLE_SSL
static void setProtocolFamily(int protocolFamily)
diff --git a/src/SocketRecvBuffer.cc b/src/SocketRecvBuffer.cc
index 2c5a1cdf..690e660d 100644
--- a/src/SocketRecvBuffer.cc
+++ b/src/SocketRecvBuffer.cc
@@ -35,6 +35,7 @@
#include "SocketRecvBuffer.h"
#include <cstring>
+#include <cassert>
#include "SocketCore.h"
#include "LogFactory.h"
@@ -42,7 +43,7 @@
namespace aria2 {
SocketRecvBuffer::SocketRecvBuffer
-(const SharedHandle<SocketCore>& socket,
+(const std::shared_ptr<SocketCore>& socket,
size_t capacity)
: socket_(socket),
capacity_(capacity),
diff --git a/src/SocketRecvBuffer.h b/src/SocketRecvBuffer.h
index 693dd2c0..29c8e0dd 100644
--- a/src/SocketRecvBuffer.h
+++ b/src/SocketRecvBuffer.h
@@ -36,7 +36,8 @@
#define D_SOCKET_RECV_BUFFER_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -45,7 +46,7 @@ class SocketCore;
class SocketRecvBuffer {
public:
SocketRecvBuffer
- (const SharedHandle<SocketCore>& socket,
+ (const std::shared_ptr<SocketCore>& socket,
size_t capacity = 16*1024);
~SocketRecvBuffer();
// Reads data from socket as much as capacity allows. Returns the
@@ -60,7 +61,7 @@ public:
bufLen_ = 0;
}
- const SharedHandle<SocketCore>& getSocket() const
+ const std::shared_ptr<SocketCore>& getSocket() const
{
return socket_;
}
@@ -82,7 +83,7 @@ public:
void pushBuffer(const unsigned char* data, size_t len);
private:
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<SocketCore> socket_;
size_t capacity_;
unsigned char* buf_;
size_t bufLen_;
diff --git a/src/StatCalc.h b/src/StatCalc.h
index 209ada99..6c0ed47a 100644
--- a/src/StatCalc.h
+++ b/src/StatCalc.h
@@ -36,7 +36,6 @@
#define D_STAT_CALC_H
#include "common.h"
-#include "SharedHandle.h"
namespace aria2 {
diff --git a/src/StreamCheckIntegrityEntry.cc b/src/StreamCheckIntegrityEntry.cc
index aeaf5e8c..e267df73 100644
--- a/src/StreamCheckIntegrityEntry.cc
+++ b/src/StreamCheckIntegrityEntry.cc
@@ -52,12 +52,12 @@ StreamCheckIntegrityEntry::~StreamCheckIntegrityEntry() {}
void StreamCheckIntegrityEntry::onDownloadIncomplete
(std::vector<Command*>& commands, DownloadEngine* e)
{
- const SharedHandle<PieceStorage>& ps = getRequestGroup()->getPieceStorage();
+ const std::shared_ptr<PieceStorage>& ps = getRequestGroup()->getPieceStorage();
ps->onDownloadIncomplete();
if(getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY)) {
return;
}
- SharedHandle<FileAllocationEntry> entry
+ std::shared_ptr<FileAllocationEntry> entry
(new StreamFileAllocationEntry(getRequestGroup(), popNextCommand()));
proceedFileAllocation(commands, entry, e);
}
diff --git a/src/StreamFileAllocationEntry.cc b/src/StreamFileAllocationEntry.cc
index b93df899..9afa6f29 100644
--- a/src/StreamFileAllocationEntry.cc
+++ b/src/StreamFileAllocationEntry.cc
@@ -69,17 +69,17 @@ void StreamFileAllocationEntry::prepareForNextAction
if(getNextCommand()) {
// Reset download start time of PeerStat because it is started
// before file allocation begins.
- const SharedHandle<DownloadContext>& dctx =
+ const std::shared_ptr<DownloadContext>& dctx =
getRequestGroup()->getDownloadContext();
- const std::vector<SharedHandle<FileEntry> >& fileEntries =
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
dctx->getFileEntries();
- for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
const FileEntry::InFlightRequestSet& reqs =
(*i)->getInFlightRequests();
for(FileEntry::InFlightRequestSet::iterator j =
reqs.begin(), eoj = reqs.end(); j != eoj; ++j) {
- const SharedHandle<PeerStat>& peerStat = (*j)->getPeerStat();
+ const std::shared_ptr<PeerStat>& peerStat = (*j)->getPeerStat();
if(peerStat) {
peerStat->downloadStart();
}
diff --git a/src/StreamFilter.cc b/src/StreamFilter.cc
index 5ab31d47..f48f182b 100644
--- a/src/StreamFilter.cc
+++ b/src/StreamFilter.cc
@@ -37,12 +37,12 @@
namespace aria2 {
StreamFilter::StreamFilter
-(const SharedHandle<StreamFilter>& delegate):
+(const std::shared_ptr<StreamFilter>& delegate):
delegate_(delegate) {}
StreamFilter::~StreamFilter() {}
-bool StreamFilter::installDelegate(const SharedHandle<StreamFilter>& filter)
+bool StreamFilter::installDelegate(const std::shared_ptr<StreamFilter>& filter)
{
if(!delegate_) {
delegate_ = filter;
diff --git a/src/StreamFilter.h b/src/StreamFilter.h
index e5cf84f9..141e864d 100644
--- a/src/StreamFilter.h
+++ b/src/StreamFilter.h
@@ -36,8 +36,9 @@
#define D_STREAM_FILTER_H
#include "common.h"
+
#include <string>
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -47,10 +48,10 @@ class Segment;
// Interface for basic decoding functionality.
class StreamFilter {
private:
- SharedHandle<StreamFilter> delegate_;
+ std::shared_ptr<StreamFilter> delegate_;
public:
StreamFilter
- (const SharedHandle<StreamFilter>& delegate = SharedHandle<StreamFilter>());
+ (const std::shared_ptr<StreamFilter>& delegate = std::shared_ptr<StreamFilter>());
virtual ~StreamFilter();
@@ -58,8 +59,8 @@ public:
virtual void init() = 0;
// Returns the number of bytes written to sink
- virtual ssize_t transform(const SharedHandle<BinaryStream>& out,
- const SharedHandle<Segment>& segment,
+ virtual ssize_t transform(const std::shared_ptr<BinaryStream>& out,
+ const std::shared_ptr<Segment>& segment,
const unsigned char* inbuf, size_t inlen) = 0;
virtual bool finished() = 0;
@@ -74,9 +75,9 @@ public:
// tranfrom() invocation.
virtual size_t getBytesProcessed() const = 0;
- virtual bool installDelegate(const SharedHandle<StreamFilter>& filter);
+ virtual bool installDelegate(const std::shared_ptr<StreamFilter>& filter);
- SharedHandle<StreamFilter> getDelegate() const
+ std::shared_ptr<StreamFilter> getDelegate() const
{
return delegate_;
}
diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc
index 06d7fc3e..4c95236e 100644
--- a/src/TrackerWatcherCommand.cc
+++ b/src/TrackerWatcherCommand.cc
@@ -70,7 +70,7 @@
namespace aria2 {
-HTTPAnnRequest::HTTPAnnRequest(const SharedHandle<RequestGroup>& rg)
+HTTPAnnRequest::HTTPAnnRequest(const std::shared_ptr<RequestGroup>& rg)
: rg_(rg)
{}
@@ -110,7 +110,7 @@ bool HTTPAnnRequest::issue(DownloadEngine* e)
}
bool HTTPAnnRequest::processResponse
-(const SharedHandle<BtAnnounce>& btAnnounce)
+(const std::shared_ptr<BtAnnounce>& btAnnounce)
{
try {
std::stringstream strm;
@@ -134,7 +134,7 @@ bool HTTPAnnRequest::processResponse
}
}
-UDPAnnRequest::UDPAnnRequest(const SharedHandle<UDPTrackerRequest>& req)
+UDPAnnRequest::UDPAnnRequest(const std::shared_ptr<UDPTrackerRequest>& req)
: req_(req)
{}
@@ -173,7 +173,7 @@ bool UDPAnnRequest::issue(DownloadEngine* e)
}
bool UDPAnnRequest::processResponse
-(const SharedHandle<BtAnnounce>& btAnnounce)
+(const std::shared_ptr<BtAnnounce>& btAnnounce)
{
if(req_) {
btAnnounce->processUDPTrackerResponse(req_);
@@ -264,7 +264,7 @@ void TrackerWatcherCommand::addConnection()
break;
}
cuid_t ncuid = e_->newCUID();
- SharedHandle<Peer> peer = peerStorage_->checkoutPeer(ncuid);
+ std::shared_ptr<Peer> peer = peerStorage_->checkoutPeer(ncuid);
// sanity check
if(!peer) {
break;
@@ -280,10 +280,10 @@ void TrackerWatcherCommand::addConnection()
}
}
-SharedHandle<AnnRequest>
+std::shared_ptr<AnnRequest>
TrackerWatcherCommand::createAnnounce(DownloadEngine* e)
{
- SharedHandle<AnnRequest> treq;
+ std::shared_ptr<AnnRequest> treq;
while(!btAnnounce_->isAllAnnounceFailed() &&
btAnnounce_->isAnnounceReady()) {
std::string uri = btAnnounce_->getAnnounceUrl();
@@ -314,21 +314,21 @@ TrackerWatcherCommand::createAnnounce(DownloadEngine* e)
return treq;
}
-SharedHandle<AnnRequest>
+std::shared_ptr<AnnRequest>
TrackerWatcherCommand::createUDPAnnRequest(const std::string& host,
uint16_t port,
uint16_t localPort)
{
- SharedHandle<UDPTrackerRequest> req =
+ std::shared_ptr<UDPTrackerRequest> req =
btAnnounce_->createUDPTrackerRequest(host, port, localPort);
- return SharedHandle<AnnRequest>(new UDPAnnRequest(req));
+ return std::shared_ptr<AnnRequest>(new UDPAnnRequest(req));
}
namespace {
bool backupTrackerIsAvailable
-(const SharedHandle<DownloadContext>& context)
+(const std::shared_ptr<DownloadContext>& context)
{
- SharedHandle<TorrentAttribute> torrentAttrs =
+ std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(context);
if(torrentAttrs->announceList.size() >= 2) {
return true;
@@ -344,13 +344,13 @@ bool backupTrackerIsAvailable
}
} // namespace
-SharedHandle<AnnRequest>
+std::shared_ptr<AnnRequest>
TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri)
{
std::vector<std::string> uris;
uris.push_back(uri);
- SharedHandle<Option> option = util::copy(getOption());
- SharedHandle<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
+ std::shared_ptr<Option> option = util::copy(getOption());
+ std::shared_ptr<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
if(backupTrackerIsAvailable(requestGroup_->getDownloadContext())) {
A2_LOG_DEBUG("This is multi-tracker announce.");
} else {
@@ -369,13 +369,13 @@ TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri)
option->get(PREF_BT_TRACKER_CONNECT_TIMEOUT));
option->put(PREF_REUSE_URI, A2_V_FALSE);
option->put(PREF_SELECT_LEAST_USED_HOST, A2_V_FALSE);
- SharedHandle<DownloadContext> dctx
+ std::shared_ptr<DownloadContext> dctx
(new DownloadContext(option->getAsInt(PREF_PIECE_LENGTH),
0,
"[tracker.announce]"));
dctx->getFileEntries().front()->setUris(uris);
rg->setDownloadContext(dctx);
- SharedHandle<DiskWriterFactory> dwf(new ByteArrayDiskWriterFactory());
+ std::shared_ptr<DiskWriterFactory> dwf(new ByteArrayDiskWriterFactory());
rg->setDiskWriterFactory(dwf);
rg->setFileAllocationEnabled(false);
rg->setPreLocalFileCheckEnabled(false);
@@ -386,34 +386,34 @@ TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri)
dctx->setAcceptMetalink(false);
A2_LOG_INFO(fmt("Creating tracker request group GID#%s",
GroupId::toHex(rg->getGID()).c_str()));
- return SharedHandle<AnnRequest>(new HTTPAnnRequest(rg));
+ return std::shared_ptr<AnnRequest>(new HTTPAnnRequest(rg));
}
void TrackerWatcherCommand::setBtRuntime
-(const SharedHandle<BtRuntime>& btRuntime)
+(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
void TrackerWatcherCommand::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
void TrackerWatcherCommand::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
void TrackerWatcherCommand::setBtAnnounce
-(const SharedHandle<BtAnnounce>& btAnnounce)
+(const std::shared_ptr<BtAnnounce>& btAnnounce)
{
btAnnounce_ = btAnnounce;
}
-const SharedHandle<Option>& TrackerWatcherCommand::getOption() const
+const std::shared_ptr<Option>& TrackerWatcherCommand::getOption() const
{
return requestGroup_->getOption();
}
diff --git a/src/TrackerWatcherCommand.h b/src/TrackerWatcherCommand.h
index 06b81fa1..63fa3cf9 100644
--- a/src/TrackerWatcherCommand.h
+++ b/src/TrackerWatcherCommand.h
@@ -38,8 +38,7 @@
#include "Command.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -66,33 +65,33 @@ public:
// Stop this request.
virtual void stop(DownloadEngine* e) = 0;
// Returns true if processing tracker response is successful.
- virtual bool processResponse(const SharedHandle<BtAnnounce>& btAnnounce) = 0;
+ virtual bool processResponse(const std::shared_ptr<BtAnnounce>& btAnnounce) = 0;
};
class HTTPAnnRequest:public AnnRequest {
public:
- HTTPAnnRequest(const SharedHandle<RequestGroup>& rg);
+ HTTPAnnRequest(const std::shared_ptr<RequestGroup>& rg);
virtual ~HTTPAnnRequest();
virtual bool stopped() const;
virtual bool success() const;
virtual bool issue(DownloadEngine* e);
virtual void stop(DownloadEngine* e);
- virtual bool processResponse(const SharedHandle<BtAnnounce>& btAnnounce);
+ virtual bool processResponse(const std::shared_ptr<BtAnnounce>& btAnnounce);
private:
- SharedHandle<RequestGroup> rg_;
+ std::shared_ptr<RequestGroup> rg_;
};
class UDPAnnRequest:public AnnRequest {
public:
- UDPAnnRequest(const SharedHandle<UDPTrackerRequest>& req);
+ UDPAnnRequest(const std::shared_ptr<UDPTrackerRequest>& req);
virtual ~UDPAnnRequest();
virtual bool stopped() const;
virtual bool success() const;
virtual bool issue(DownloadEngine* e);
virtual void stop(DownloadEngine* e);
- virtual bool processResponse(const SharedHandle<BtAnnounce>& btAnnounce);
+ virtual bool processResponse(const std::shared_ptr<BtAnnounce>& btAnnounce);
private:
- SharedHandle<UDPTrackerRequest> req_;
+ std::shared_ptr<UDPTrackerRequest> req_;
};
class TrackerWatcherCommand : public Command
@@ -102,32 +101,32 @@ private:
DownloadEngine* e_;
- SharedHandle<UDPTrackerClient> udpTrackerClient_;
+ std::shared_ptr<UDPTrackerClient> udpTrackerClient_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
- SharedHandle<BtRuntime> btRuntime_;
+ std::shared_ptr<BtRuntime> btRuntime_;
- SharedHandle<BtAnnounce> btAnnounce_;
+ std::shared_ptr<BtAnnounce> btAnnounce_;
- SharedHandle<AnnRequest> trackerRequest_;
+ std::shared_ptr<AnnRequest> trackerRequest_;
/**
* Returns a command for announce request. Returns 0 if no announce request
* is needed.
*/
- SharedHandle<AnnRequest>
+ std::shared_ptr<AnnRequest>
createHTTPAnnRequest(const std::string& uri);
- SharedHandle<AnnRequest>
+ std::shared_ptr<AnnRequest>
createUDPAnnRequest(const std::string& host, uint16_t port,
uint16_t localPort);
void addConnection();
- const SharedHandle<Option>& getOption() const;
+ const std::shared_ptr<Option>& getOption() const;
public:
TrackerWatcherCommand(cuid_t cuid,
RequestGroup* requestGroup,
@@ -135,17 +134,17 @@ public:
virtual ~TrackerWatcherCommand();
- SharedHandle<AnnRequest> createAnnounce(DownloadEngine* e);
+ std::shared_ptr<AnnRequest> createAnnounce(DownloadEngine* e);
virtual bool execute();
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
- void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
+ void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
- void setBtAnnounce(const SharedHandle<BtAnnounce>& btAnnounce);
+ void setBtAnnounce(const std::shared_ptr<BtAnnounce>& btAnnounce);
};
} // namespace aria2
diff --git a/src/UDPTrackerClient.cc b/src/UDPTrackerClient.cc
index 0ea2052e..024776f8 100644
--- a/src/UDPTrackerClient.cc
+++ b/src/UDPTrackerClient.cc
@@ -109,7 +109,7 @@ UDPTrackerClient::~UDPTrackerClient()
namespace {
struct CollectAddrPortMatch {
- bool operator()(const SharedHandle<UDPTrackerRequest>& req) const
+ bool operator()(const std::shared_ptr<UDPTrackerRequest>& req) const
{
if(req->remoteAddr == remoteAddr && req->remotePort == remotePort) {
dest.push_back(req);
@@ -118,10 +118,10 @@ struct CollectAddrPortMatch {
return false;
}
}
- std::vector<SharedHandle<UDPTrackerRequest> >& dest;
+ std::vector<std::shared_ptr<UDPTrackerRequest> >& dest;
std::string remoteAddr;
uint16_t remotePort;
- CollectAddrPortMatch(std::vector<SharedHandle<UDPTrackerRequest> >& dest,
+ CollectAddrPortMatch(std::vector<std::shared_ptr<UDPTrackerRequest> >& dest,
const std::string& remoteAddr, uint16_t remotePort)
: dest(dest), remoteAddr(remoteAddr), remotePort(remotePort)
{}
@@ -140,7 +140,7 @@ int UDPTrackerClient::receiveReply
return -1;
}
int32_t transactionId = bittorrent::getIntParam(data, 4);
- SharedHandle<UDPTrackerRequest> req =
+ std::shared_ptr<UDPTrackerRequest> req =
findInflightRequest(remoteAddr, remotePort, transactionId, true);
if(!req) {
logInvalidTransaction(remoteAddr, remotePort, action, transactionId);
@@ -150,13 +150,13 @@ int UDPTrackerClient::receiveReply
int64_t connectionId = bittorrent::getLLIntParam(data, 8);
A2_LOG_INFO(fmt("UDPT received CONNECT reply from %s:%u transaction_id=%u,"
- "connection_id=%"PRId64, remoteAddr.c_str(), remotePort,
+ "connection_id=%" PRId64, remoteAddr.c_str(), remotePort,
transactionId, connectionId));
UDPTrackerConnection c(UDPT_CST_CONNECTED, connectionId, now);
connectionIdCache_[std::make_pair(remoteAddr, remotePort)] = c;
// Now we have connecion ID, push requests which are waiting for
// it.
- std::vector<SharedHandle<UDPTrackerRequest> > reqs;
+ std::vector<std::shared_ptr<UDPTrackerRequest> > reqs;
connectRequests_.erase(std::remove_if
(connectRequests_.begin(), connectRequests_.end(),
CollectAddrPortMatch(reqs, remoteAddr, remotePort)),
@@ -171,7 +171,7 @@ int UDPTrackerClient::receiveReply
return - 1;
}
int32_t transactionId = bittorrent::getIntParam(data, 4);
- SharedHandle<UDPTrackerRequest> req =
+ std::shared_ptr<UDPTrackerRequest> req =
findInflightRequest(remoteAddr, remotePort, transactionId, true);
if(!req) {
logInvalidTransaction(remoteAddr, remotePort, action, transactionId);
@@ -197,7 +197,7 @@ int UDPTrackerClient::receiveReply
}
A2_LOG_INFO(fmt("UDPT received ANNOUNCE reply from %s:%u transaction_id=%u,"
- "connection_id=%"PRId64", event=%s, infohash=%s, "
+ "connection_id=%" PRId64 ", event=%s, infohash=%s, "
"interval=%d, leechers=%d, "
"seeders=%d, num_peers=%d", remoteAddr.c_str(), remotePort,
transactionId, req->connectionId,
@@ -213,7 +213,7 @@ int UDPTrackerClient::receiveReply
return -1;
}
int32_t transactionId = bittorrent::getIntParam(data, 4);
- SharedHandle<UDPTrackerRequest> req =
+ std::shared_ptr<UDPTrackerRequest> req =
findInflightRequest(remoteAddr, remotePort, transactionId, true);
if(!req) {
logInvalidTransaction(remoteAddr, remotePort, action, transactionId);
@@ -226,7 +226,7 @@ int UDPTrackerClient::receiveReply
req->error = UDPT_ERR_TRACKER;
A2_LOG_INFO(fmt("UDPT received ERROR reply from %s:%u transaction_id=%u,"
- "connection_id=%"PRId64", action=%d, error_string=%s",
+ "connection_id=%" PRId64 ", action=%d, error_string=%s",
remoteAddr.c_str(),
remotePort, transactionId, req->connectionId, action,
errorString.c_str()));
@@ -255,7 +255,7 @@ ssize_t UDPTrackerClient::createRequest
return -1;
}
while(!pendingRequests_.empty()) {
- const SharedHandle<UDPTrackerRequest>& req = pendingRequests_.front();
+ const std::shared_ptr<UDPTrackerRequest>& req = pendingRequests_.front();
if(req->action == UDPT_ACT_CONNECT) {
ssize_t rv;
rv = createUDPTrackerConnect(data, length, remoteAddr, remotePort, req);
@@ -265,7 +265,7 @@ ssize_t UDPTrackerClient::createRequest
req->remotePort,
now);
if(!c) {
- SharedHandle<UDPTrackerRequest> creq(new UDPTrackerRequest());
+ std::shared_ptr<UDPTrackerRequest> creq(new UDPTrackerRequest());
creq->action = UDPT_ACT_CONNECT;
creq->remoteAddr = req->remoteAddr;
creq->remotePort = req->remotePort;
@@ -295,7 +295,7 @@ void UDPTrackerClient::requestSent(const Timer& now)
A2_LOG_WARN("pendingRequests_ is empty");
return;
}
- const SharedHandle<UDPTrackerRequest>& req = pendingRequests_.front();
+ const std::shared_ptr<UDPTrackerRequest>& req = pendingRequests_.front();
switch(req->action) {
case UDPT_ACT_CONNECT:
A2_LOG_INFO(fmt("UDPT sent CONNECT to %s:%u transaction_id=%u",
@@ -304,7 +304,7 @@ void UDPTrackerClient::requestSent(const Timer& now)
break;
case UDPT_ACT_ANNOUNCE:
A2_LOG_INFO(fmt("UDPT sent ANNOUNCE to %s:%u transaction_id=%u, "
- "connection_id=%"PRId64", event=%s, infohash=%s",
+ "connection_id=%" PRId64 ", event=%s, infohash=%s",
req->remoteAddr.c_str(), req->remotePort,
req->transactionId, req->connectionId,
getUDPTrackerEventStr(req->event),
@@ -332,7 +332,7 @@ void UDPTrackerClient::requestFail(int error)
A2_LOG_WARN("pendingRequests_ is empty");
return;
}
- const SharedHandle<UDPTrackerRequest>& req = pendingRequests_.front();
+ const std::shared_ptr<UDPTrackerRequest>& req = pendingRequests_.front();
switch(req->action) {
case UDPT_ACT_CONNECT:
A2_LOG_INFO(fmt("UDPT fail CONNECT to %s:%u transaction_id=%u",
@@ -342,7 +342,7 @@ void UDPTrackerClient::requestFail(int error)
break;
case UDPT_ACT_ANNOUNCE:
A2_LOG_INFO(fmt("UDPT fail ANNOUNCE to %s:%u transaction_id=%u, "
- "connection_id=%"PRId64", event=%s, infohash=%s",
+ "connection_id=%" PRId64 ", event=%s, infohash=%s",
req->remoteAddr.c_str(), req->remotePort,
req->transactionId, req->connectionId,
getUDPTrackerEventStr(req->event),
@@ -357,7 +357,7 @@ void UDPTrackerClient::requestFail(int error)
pendingRequests_.pop_front();
}
-void UDPTrackerClient::addRequest(const SharedHandle<UDPTrackerRequest>& req)
+void UDPTrackerClient::addRequest(const std::shared_ptr<UDPTrackerRequest>& req)
{
req->state = UDPT_STA_PENDING;
req->error = UDPT_ERR_SUCCESS;
@@ -366,7 +366,7 @@ void UDPTrackerClient::addRequest(const SharedHandle<UDPTrackerRequest>& req)
namespace {
struct TimeoutCheck {
- bool operator()(const SharedHandle<UDPTrackerRequest>& req) const
+ bool operator()(const std::shared_ptr<UDPTrackerRequest>& req) const
{
int t = req->dispatched.difference(now);
if(req->failCount == 0) {
@@ -379,7 +379,7 @@ struct TimeoutCheck {
break;
case UDPT_ACT_ANNOUNCE:
A2_LOG_INFO(fmt("UDPT resend ANNOUNCE to %s:%u transaction_id=%u, "
- "connection_id=%"PRId64", event=%s, infohash=%s",
+ "connection_id=%" PRId64 ", event=%s, infohash=%s",
req->remoteAddr.c_str(), req->remotePort,
req->transactionId, req->connectionId,
getUDPTrackerEventStr(req->event),
@@ -407,7 +407,7 @@ struct TimeoutCheck {
break;
case UDPT_ACT_ANNOUNCE:
A2_LOG_INFO(fmt("UDPT timeout ANNOUNCE to %s:%u transaction_id=%u, "
- "connection_id=%"PRId64", event=%s, infohash=%s",
+ "connection_id=%" PRId64 ", event=%s, infohash=%s",
req->remoteAddr.c_str(), req->remotePort,
req->transactionId, req->connectionId,
getUDPTrackerEventStr(req->event),
@@ -426,10 +426,10 @@ struct TimeoutCheck {
}
}
}
- std::vector<SharedHandle<UDPTrackerRequest> >& dest;
+ std::vector<std::shared_ptr<UDPTrackerRequest> >& dest;
UDPTrackerClient* client;
const Timer& now;
- TimeoutCheck(std::vector<SharedHandle<UDPTrackerRequest> >& dest,
+ TimeoutCheck(std::vector<std::shared_ptr<UDPTrackerRequest> >& dest,
UDPTrackerClient* client,
const Timer& now)
: dest(dest), client(client), now(now)
@@ -439,7 +439,7 @@ struct TimeoutCheck {
void UDPTrackerClient::handleTimeout(const Timer& now)
{
- std::vector<SharedHandle<UDPTrackerRequest> > dest;
+ std::vector<std::shared_ptr<UDPTrackerRequest> > dest;
inflightRequests_.erase(std::remove_if(inflightRequests_.begin(),
inflightRequests_.end(),
TimeoutCheck(dest, this, now)),
@@ -447,12 +447,12 @@ void UDPTrackerClient::handleTimeout(const Timer& now)
pendingRequests_.insert(pendingRequests_.begin(), dest.begin(), dest.end());
}
-SharedHandle<UDPTrackerRequest> UDPTrackerClient::findInflightRequest
+std::shared_ptr<UDPTrackerRequest> UDPTrackerClient::findInflightRequest
(const std::string& remoteAddr, uint16_t remotePort, int32_t transactionId,
bool remove)
{
- SharedHandle<UDPTrackerRequest> res;
- for(std::deque<SharedHandle<UDPTrackerRequest> >::iterator i =
+ std::shared_ptr<UDPTrackerRequest> res;
+ for(std::deque<std::shared_ptr<UDPTrackerRequest> >::iterator i =
inflightRequests_.begin(), eoi = inflightRequests_.end(); i != eoi;
++i) {
if((*i)->remoteAddr == remoteAddr && (*i)->remotePort == remotePort &&
@@ -487,7 +487,7 @@ UDPTrackerConnection* UDPTrackerClient::getConnectionId
namespace {
struct FailConnectDelete {
- bool operator()(const SharedHandle<UDPTrackerRequest>& req) const
+ bool operator()(const std::shared_ptr<UDPTrackerRequest>& req) const
{
if(req->action == UDPT_ACT_ANNOUNCE &&
req->remoteAddr == remoteAddr && req->remotePort == remotePort) {
@@ -548,7 +548,7 @@ void UDPTrackerClient::decreaseWatchers()
ssize_t createUDPTrackerConnect
(unsigned char* data, size_t length,
std::string& remoteAddr, uint16_t& remotePort,
- const SharedHandle<UDPTrackerRequest>& req)
+ const std::shared_ptr<UDPTrackerRequest>& req)
{
assert(length >= 16);
remoteAddr = req->remoteAddr;
@@ -562,7 +562,7 @@ ssize_t createUDPTrackerConnect
ssize_t createUDPTrackerAnnounce
(unsigned char* data, size_t length,
std::string& remoteAddr, uint16_t& remotePort,
- const SharedHandle<UDPTrackerRequest>& req)
+ const std::shared_ptr<UDPTrackerRequest>& req)
{
assert(length >= 100);
remoteAddr = req->remoteAddr;
diff --git a/src/UDPTrackerClient.h b/src/UDPTrackerClient.h
index f2a8df82..fccac0bd 100644
--- a/src/UDPTrackerClient.h
+++ b/src/UDPTrackerClient.h
@@ -40,8 +40,8 @@
#include <string>
#include <deque>
#include <map>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
namespace aria2 {
@@ -96,22 +96,22 @@ public:
// successfully sent. The |error| should indicate error situation.
void requestFail(int error);
- void addRequest(const SharedHandle<UDPTrackerRequest>& req);
+ void addRequest(const std::shared_ptr<UDPTrackerRequest>& req);
// Handles timeout for inflight requests.
void handleTimeout(const Timer& now);
- const std::deque<SharedHandle<UDPTrackerRequest> >&
+ const std::deque<std::shared_ptr<UDPTrackerRequest> >&
getPendingRequests() const
{
return pendingRequests_;
}
- const std::deque<SharedHandle<UDPTrackerRequest> >&
+ const std::deque<std::shared_ptr<UDPTrackerRequest> >&
getConnectRequests() const
{
return connectRequests_;
}
- const std::deque<SharedHandle<UDPTrackerRequest> >&
+ const std::deque<std::shared_ptr<UDPTrackerRequest> >&
getInflightRequests() const
{
return inflightRequests_;
@@ -139,7 +139,7 @@ public:
void failConnect(const std::string& remoteAddr, uint16_t remotePort,
int error);
private:
- SharedHandle<UDPTrackerRequest> findInflightRequest
+ std::shared_ptr<UDPTrackerRequest> findInflightRequest
(const std::string& remoteAddr, uint16_t remotePort, int32_t transactionId,
bool remove);
@@ -148,19 +148,19 @@ private:
std::map<std::pair<std::string, uint16_t>,
UDPTrackerConnection> connectionIdCache_;
- std::deque<SharedHandle<UDPTrackerRequest> > inflightRequests_;
- std::deque<SharedHandle<UDPTrackerRequest> > pendingRequests_;
- std::deque<SharedHandle<UDPTrackerRequest> > connectRequests_;
+ std::deque<std::shared_ptr<UDPTrackerRequest> > inflightRequests_;
+ std::deque<std::shared_ptr<UDPTrackerRequest> > pendingRequests_;
+ std::deque<std::shared_ptr<UDPTrackerRequest> > connectRequests_;
int numWatchers_;
};
ssize_t createUDPTrackerConnect
(unsigned char* data, size_t length, std::string& remoteAddr,
- uint16_t& remotePort, const SharedHandle<UDPTrackerRequest>& req);
+ uint16_t& remotePort, const std::shared_ptr<UDPTrackerRequest>& req);
ssize_t createUDPTrackerAnnounce
(unsigned char* data, size_t length, std::string& remoteAddr,
- uint16_t& remotePort, const SharedHandle<UDPTrackerRequest>& req);
+ uint16_t& remotePort, const std::shared_ptr<UDPTrackerRequest>& req);
const char* getUDPTrackerActionStr(int action);
diff --git a/src/UDPTrackerRequest.h b/src/UDPTrackerRequest.h
index 8012b182..b7e9ab23 100644
--- a/src/UDPTrackerRequest.h
+++ b/src/UDPTrackerRequest.h
@@ -39,8 +39,8 @@
#include <string>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "TimerA2.h"
namespace aria2 {
@@ -103,7 +103,7 @@ struct UDPTrackerRequest {
int error;
Timer dispatched;
int failCount;
- SharedHandle<UDPTrackerReply> reply;
+ std::shared_ptr<UDPTrackerReply> reply;
UDPTrackerRequest();
};
diff --git a/src/UTMetadataDataExtensionMessage.cc b/src/UTMetadataDataExtensionMessage.cc
index 72ac6964..88d78d71 100644
--- a/src/UTMetadataDataExtensionMessage.cc
+++ b/src/UTMetadataDataExtensionMessage.cc
@@ -115,13 +115,13 @@ void UTMetadataDataExtensionMessage::setData(const std::string& data)
}
void UTMetadataDataExtensionMessage::setPieceStorage
-(const SharedHandle<PieceStorage>& pieceStorage)
+(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
void UTMetadataDataExtensionMessage::setDownloadContext
-(const SharedHandle<DownloadContext>& dctx)
+(const std::shared_ptr<DownloadContext>& dctx)
{
dctx_ = dctx;
}
diff --git a/src/UTMetadataDataExtensionMessage.h b/src/UTMetadataDataExtensionMessage.h
index 75720412..ca8ff59e 100644
--- a/src/UTMetadataDataExtensionMessage.h
+++ b/src/UTMetadataDataExtensionMessage.h
@@ -36,7 +36,8 @@
#define D_UT_METADATA_DATA_EXTENSION_MESSAGE_H
#include "UTMetadataExtensionMessage.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -50,9 +51,9 @@ private:
std::string data_;
- SharedHandle<DownloadContext> dctx_;
+ std::shared_ptr<DownloadContext> dctx_;
- SharedHandle<PieceStorage> pieceStorage_;
+ std::shared_ptr<PieceStorage> pieceStorage_;
UTMetadataRequestTracker* tracker_;
public:
@@ -89,14 +90,14 @@ public:
return data_;
}
- void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
+ void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
void setUTMetadataRequestTracker(UTMetadataRequestTracker* tracker)
{
tracker_ = tracker;
}
- void setDownloadContext(const SharedHandle<DownloadContext>& dctx);
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& dctx);
};
} // namespace aria2
diff --git a/src/UTMetadataPostDownloadHandler.cc b/src/UTMetadataPostDownloadHandler.cc
index 0557a1b1..da9f1a4a 100644
--- a/src/UTMetadataPostDownloadHandler.cc
+++ b/src/UTMetadataPostDownloadHandler.cc
@@ -56,10 +56,10 @@ namespace aria2 {
bool UTMetadataPostDownloadHandler::Criteria::match
(const RequestGroup* requestGroup) const
{
- const SharedHandle<DownloadContext>& dctx =
+ const std::shared_ptr<DownloadContext>& dctx =
requestGroup->getDownloadContext();
if(dctx->hasAttribute(CTX_ATTR_BT)) {
- SharedHandle<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx);
+ std::shared_ptr<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx);
if(attrs->metadata.empty()) {
return true;
}
@@ -69,15 +69,15 @@ bool UTMetadataPostDownloadHandler::Criteria::match
UTMetadataPostDownloadHandler::UTMetadataPostDownloadHandler()
{
- SharedHandle<Criteria> cri(new Criteria());
+ std::shared_ptr<Criteria> cri(new Criteria());
setCriteria(cri);
}
void UTMetadataPostDownloadHandler::getNextRequestGroups
-(std::vector<SharedHandle<RequestGroup> >& groups, RequestGroup* requestGroup)
+(std::vector<std::shared_ptr<RequestGroup> >& groups, RequestGroup* requestGroup)
{
- const SharedHandle<DownloadContext>& dctx =requestGroup->getDownloadContext();
- SharedHandle<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx);
+ const std::shared_ptr<DownloadContext>& dctx =requestGroup->getDownloadContext();
+ std::shared_ptr<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx);
std::string metadata =
util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
std::string torrent = bittorrent::metadata2Torrent(metadata, attrs);
@@ -93,7 +93,7 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups
}
}
if(!requestGroup->getOption()->getAsBool(PREF_BT_METADATA_ONLY)) {
- std::vector<SharedHandle<RequestGroup> > newRgs;
+ std::vector<std::shared_ptr<RequestGroup> > newRgs;
// Don't adjust announce URI because it has been done when
// RequestGroup is created with magnet URI.
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
diff --git a/src/UTMetadataPostDownloadHandler.h b/src/UTMetadataPostDownloadHandler.h
index 19364304..54c40c9e 100644
--- a/src/UTMetadataPostDownloadHandler.h
+++ b/src/UTMetadataPostDownloadHandler.h
@@ -52,7 +52,7 @@ public:
UTMetadataPostDownloadHandler();
virtual void
- getNextRequestGroups(std::vector<SharedHandle<RequestGroup> >& groups,
+ getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
RequestGroup* requestGroup);
};
diff --git a/src/UTMetadataRequestExtensionMessage.cc b/src/UTMetadataRequestExtensionMessage.cc
index a12d088a..f4444123 100644
--- a/src/UTMetadataRequestExtensionMessage.cc
+++ b/src/UTMetadataRequestExtensionMessage.cc
@@ -76,17 +76,17 @@ std::string UTMetadataRequestExtensionMessage::toString() const
void UTMetadataRequestExtensionMessage::doReceivedAction()
{
- SharedHandle<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx_);
+ std::shared_ptr<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx_);
uint8_t id = peer_->getExtensionMessageID
(ExtensionMessageRegistry::UT_METADATA);
if(attrs->metadata.empty()) {
- SharedHandle<UTMetadataRejectExtensionMessage> m
+ std::shared_ptr<UTMetadataRejectExtensionMessage> m
(new UTMetadataRejectExtensionMessage(id));
m->setIndex(getIndex());
- SharedHandle<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
+ std::shared_ptr<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
dispatcher_->addMessageToQueue(msg);
}else if(getIndex()*METADATA_PIECE_SIZE < attrs->metadataSize) {
- SharedHandle<UTMetadataDataExtensionMessage> m
+ std::shared_ptr<UTMetadataDataExtensionMessage> m
(new UTMetadataDataExtensionMessage(id));
m->setIndex(getIndex());
m->setTotalSize(attrs->metadataSize);
@@ -97,7 +97,7 @@ void UTMetadataRequestExtensionMessage::doReceivedAction()
attrs->metadata.begin()+(getIndex()+1)*METADATA_PIECE_SIZE:
attrs->metadata.end();
m->setData(begin, end);
- SharedHandle<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
+ std::shared_ptr<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
dispatcher_->addMessageToQueue(msg);
} else {
throw DL_ABORT_EX
@@ -107,12 +107,12 @@ void UTMetadataRequestExtensionMessage::doReceivedAction()
}
void UTMetadataRequestExtensionMessage::setDownloadContext
-(const SharedHandle<DownloadContext>& dctx)
+(const std::shared_ptr<DownloadContext>& dctx)
{
dctx_ = dctx;
}
-void UTMetadataRequestExtensionMessage::setPeer(const SharedHandle<Peer>& peer)
+void UTMetadataRequestExtensionMessage::setPeer(const std::shared_ptr<Peer>& peer)
{
peer_ = peer;
}
diff --git a/src/UTMetadataRequestExtensionMessage.h b/src/UTMetadataRequestExtensionMessage.h
index 5c5e3f7f..f7896f13 100644
--- a/src/UTMetadataRequestExtensionMessage.h
+++ b/src/UTMetadataRequestExtensionMessage.h
@@ -36,7 +36,8 @@
#define D_UT_METADATA_REQUEST_EXTENSION_MESSAGE_H
#include "UTMetadataExtensionMessage.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -47,9 +48,9 @@ class Peer;
class UTMetadataRequestExtensionMessage:public UTMetadataExtensionMessage {
private:
- SharedHandle<DownloadContext> dctx_;
+ std::shared_ptr<DownloadContext> dctx_;
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
BtMessageDispatcher* dispatcher_;
@@ -65,7 +66,7 @@ public:
virtual void doReceivedAction();
- void setDownloadContext(const SharedHandle<DownloadContext>& dctx);
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& dctx);
void setBtMessageDispatcher(BtMessageDispatcher* disp)
{
@@ -77,7 +78,7 @@ public:
messageFactory_ = factory;
}
- void setPeer(const SharedHandle<Peer>& peer);
+ void setPeer(const std::shared_ptr<Peer>& peer);
};
} // namespace aria2
diff --git a/src/UTMetadataRequestFactory.cc b/src/UTMetadataRequestFactory.cc
index cfe26998..06e13dad 100644
--- a/src/UTMetadataRequestFactory.cc
+++ b/src/UTMetadataRequestFactory.cc
@@ -56,12 +56,12 @@ UTMetadataRequestFactory::UTMetadataRequestFactory()
{}
void UTMetadataRequestFactory::create
-(std::vector<SharedHandle<BtMessage> >& msgs, size_t num,
- const SharedHandle<PieceStorage>& pieceStorage)
+(std::vector<std::shared_ptr<BtMessage> >& msgs, size_t num,
+ const std::shared_ptr<PieceStorage>& pieceStorage)
{
while(num) {
std::vector<size_t> metadataRequests = tracker_->getAllTrackedIndex();
- SharedHandle<Piece> p =
+ std::shared_ptr<Piece> p =
pieceStorage->getMissingPiece(peer_, metadataRequests, cuid_);
if(!p) {
A2_LOG_DEBUG("No ut_metadata piece is available to download.");
@@ -70,7 +70,7 @@ void UTMetadataRequestFactory::create
--num;
A2_LOG_DEBUG(fmt("Creating ut_metadata request index=%lu",
static_cast<unsigned long>(p->getIndex())));
- SharedHandle<UTMetadataRequestExtensionMessage> m
+ std::shared_ptr<UTMetadataRequestExtensionMessage> m
(new UTMetadataRequestExtensionMessage
(peer_->getExtensionMessageID(ExtensionMessageRegistry::UT_METADATA)));
m->setIndex(p->getIndex());
@@ -79,7 +79,7 @@ void UTMetadataRequestFactory::create
m->setBtMessageFactory(messageFactory_);
m->setPeer(peer_);
- SharedHandle<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
+ std::shared_ptr<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
msgs.push_back(msg);
tracker_->add(p->getIndex());
}
diff --git a/src/UTMetadataRequestFactory.h b/src/UTMetadataRequestFactory.h
index 7af3e8da..8839cfe4 100644
--- a/src/UTMetadataRequestFactory.h
+++ b/src/UTMetadataRequestFactory.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "Command.h"
namespace aria2 {
@@ -54,9 +54,9 @@ class BtMessage;
class UTMetadataRequestFactory {
private:
- SharedHandle<DownloadContext> dctx_;
+ std::shared_ptr<DownloadContext> dctx_;
- SharedHandle<Peer> peer_;
+ std::shared_ptr<Peer> peer_;
BtMessageDispatcher* dispatcher_;
@@ -69,10 +69,10 @@ public:
// Creates at most num of ut_metadata request message and appends
// them to msgs. pieceStorage is used to identify missing piece.
- void create(std::vector<SharedHandle<BtMessage> >& msgs, size_t num,
- const SharedHandle<PieceStorage>& pieceStorage);
+ void create(std::vector<std::shared_ptr<BtMessage> >& msgs, size_t num,
+ const std::shared_ptr<PieceStorage>& pieceStorage);
- void setDownloadContext(const SharedHandle<DownloadContext>& dctx)
+ void setDownloadContext(const std::shared_ptr<DownloadContext>& dctx)
{
dctx_ = dctx;
}
@@ -87,7 +87,7 @@ public:
messageFactory_ = factory;
}
- void setPeer(const SharedHandle<Peer>& peer)
+ void setPeer(const std::shared_ptr<Peer>& peer)
{
peer_ = peer;
}
diff --git a/src/UTPexExtensionMessage.cc b/src/UTPexExtensionMessage.cc
index a5245772..4def037f 100644
--- a/src/UTPexExtensionMessage.cc
+++ b/src/UTPexExtensionMessage.cc
@@ -96,13 +96,13 @@ std::string UTPexExtensionMessage::getPayload()
std::pair<std::pair<std::string, std::string>,
std::pair<std::string, std::string> >
UTPexExtensionMessage::createCompactPeerListAndFlag
-(const std::vector<SharedHandle<Peer> >& peers)
+(const std::vector<std::shared_ptr<Peer> >& peers)
{
std::string addrstring;
std::string flagstring;
std::string addrstring6;
std::string flagstring6;
- for(std::vector<SharedHandle<Peer> >::const_iterator itr = peers.begin(),
+ for(std::vector<std::shared_ptr<Peer> >::const_iterator itr = peers.begin(),
eoi = peers.end(); itr != eoi; ++itr) {
unsigned char compact[COMPACT_LEN_IPV6];
int compactlen = bittorrent::packcompact
@@ -132,7 +132,7 @@ void UTPexExtensionMessage::doReceivedAction()
peerStorage_->addPeer(droppedPeers_);
}
-bool UTPexExtensionMessage::addFreshPeer(const SharedHandle<Peer>& peer)
+bool UTPexExtensionMessage::addFreshPeer(const std::shared_ptr<Peer>& peer)
{
if(!peer->isIncomingPeer() &&
peer->getFirstContactTime().difference(global::wallclock()) < interval_) {
@@ -148,7 +148,7 @@ bool UTPexExtensionMessage::freshPeersAreFull() const
return freshPeers_.size() >= maxFreshPeer_;
}
-bool UTPexExtensionMessage::addDroppedPeer(const SharedHandle<Peer>& peer)
+bool UTPexExtensionMessage::addDroppedPeer(const std::shared_ptr<Peer>& peer)
{
if(!peer->isIncomingPeer() &&
peer->getDropStartTime().difference(global::wallclock()) < interval_) {
@@ -175,7 +175,7 @@ void UTPexExtensionMessage::setMaxDroppedPeer(size_t maxDroppedPeer)
}
void UTPexExtensionMessage::setPeerStorage
-(const SharedHandle<PeerStorage>& peerStorage)
+(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
@@ -190,7 +190,7 @@ UTPexExtensionMessage::create(const unsigned char* data, size_t len)
}
UTPexExtensionMessage* msg(new UTPexExtensionMessage(*data));
- SharedHandle<ValueBase> decoded = bencode2::decode(data+1, len - 1);
+ std::shared_ptr<ValueBase> decoded = bencode2::decode(data+1, len - 1);
const Dict* dict = downcast<Dict>(decoded);
if(dict) {
const String* added = downcast<String>(dict->get("added"));
diff --git a/src/UTPexExtensionMessage.h b/src/UTPexExtensionMessage.h
index 3f273bf6..8ae7bee2 100644
--- a/src/UTPexExtensionMessage.h
+++ b/src/UTPexExtensionMessage.h
@@ -39,9 +39,9 @@
#include <utility>
#include <vector>
+#include <memory>
#include "a2time.h"
-#include "SharedHandle.h"
namespace aria2 {
@@ -52,11 +52,11 @@ class UTPexExtensionMessage:public ExtensionMessage {
private:
uint8_t extensionMessageID_;
- std::vector<SharedHandle<Peer> > freshPeers_;
+ std::vector<std::shared_ptr<Peer> > freshPeers_;
- std::vector<SharedHandle<Peer> > droppedPeers_;
+ std::vector<std::shared_ptr<Peer> > droppedPeers_;
- SharedHandle<PeerStorage> peerStorage_;
+ std::shared_ptr<PeerStorage> peerStorage_;
time_t interval_;
@@ -66,7 +66,7 @@ private:
std::pair<std::pair<std::string, std::string>,
std::pair<std::string, std::string> >
- createCompactPeerListAndFlag(const std::vector<SharedHandle<Peer> >& peers);
+ createCompactPeerListAndFlag(const std::vector<std::shared_ptr<Peer> >& peers);
public:
UTPexExtensionMessage(uint8_t extensionMessageID);
@@ -91,25 +91,25 @@ public:
virtual void doReceivedAction();
- bool addFreshPeer(const SharedHandle<Peer>& peer);
+ bool addFreshPeer(const std::shared_ptr<Peer>& peer);
- const std::vector<SharedHandle<Peer> >& getFreshPeers() const
+ const std::vector<std::shared_ptr<Peer> >& getFreshPeers() const
{
return freshPeers_;
}
bool freshPeersAreFull() const;
- bool addDroppedPeer(const SharedHandle<Peer>& peer);
+ bool addDroppedPeer(const std::shared_ptr<Peer>& peer);
- const std::vector<SharedHandle<Peer> >& getDroppedPeers() const
+ const std::vector<std::shared_ptr<Peer> >& getDroppedPeers() const
{
return droppedPeers_;
}
bool droppedPeersAreFull() const;
- void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
+ void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
static UTPexExtensionMessage*
create(const unsigned char* data, size_t len);
diff --git a/src/UnionSeedCriteria.cc b/src/UnionSeedCriteria.cc
index d2785b71..f06eca0b 100644
--- a/src/UnionSeedCriteria.cc
+++ b/src/UnionSeedCriteria.cc
@@ -41,7 +41,7 @@ namespace aria2 {
namespace {
class Reset {
public:
- void operator()(const SharedHandle<SeedCriteria>& cri)
+ void operator()(const std::shared_ptr<SeedCriteria>& cri)
{
cri->reset();
}
@@ -51,7 +51,7 @@ public:
namespace {
class Eval {
public:
- bool operator()(const SharedHandle<SeedCriteria>& cri)
+ bool operator()(const std::shared_ptr<SeedCriteria>& cri)
{
return cri->evaluate();
}
@@ -68,12 +68,12 @@ void UnionSeedCriteria::reset()
bool UnionSeedCriteria::evaluate()
{
- std::vector<SharedHandle<SeedCriteria> >::iterator itr =
+ std::vector<std::shared_ptr<SeedCriteria> >::iterator itr =
std::find_if(criterion_.begin(), criterion_.end(), Eval());
return itr != criterion_.end();
}
-void UnionSeedCriteria::addSeedCriteria(const SharedHandle<SeedCriteria>& cri)
+void UnionSeedCriteria::addSeedCriteria(const std::shared_ptr<SeedCriteria>& cri)
{
criterion_.push_back(cri);
}
diff --git a/src/UnionSeedCriteria.h b/src/UnionSeedCriteria.h
index 44e2ee3b..1e50e913 100644
--- a/src/UnionSeedCriteria.h
+++ b/src/UnionSeedCriteria.h
@@ -38,12 +38,13 @@
#include "SeedCriteria.h"
#include <vector>
+#include <memory>
namespace aria2 {
class UnionSeedCriteria : public SeedCriteria {
private:
- std::vector<SharedHandle<SeedCriteria> > criterion_;
+ std::vector<std::shared_ptr<SeedCriteria> > criterion_;
public:
UnionSeedCriteria();
virtual ~UnionSeedCriteria();
@@ -52,9 +53,9 @@ public:
virtual bool evaluate();
- void addSeedCriteria(const SharedHandle<SeedCriteria>& cri);
+ void addSeedCriteria(const std::shared_ptr<SeedCriteria>& cri);
- const std::vector<SharedHandle<SeedCriteria> >& getSeedCriterion() const
+ const std::vector<std::shared_ptr<SeedCriteria> >& getSeedCriterion() const
{
return criterion_;
}
diff --git a/src/UnknownLengthPieceStorage.cc b/src/UnknownLengthPieceStorage.cc
index 43f26b23..d111723c 100644
--- a/src/UnknownLengthPieceStorage.cc
+++ b/src/UnknownLengthPieceStorage.cc
@@ -47,7 +47,7 @@
namespace aria2 {
UnknownLengthPieceStorage::UnknownLengthPieceStorage
-(const SharedHandle<DownloadContext>& downloadContext)
+(const std::shared_ptr<DownloadContext>& downloadContext)
: downloadContext_(downloadContext),
diskWriterFactory_(new DefaultDiskWriterFactory()),
totalLength_(0),
@@ -62,7 +62,7 @@ void UnknownLengthPieceStorage::initStorage()
directDiskAdaptor->setFileEntries(downloadContext_->getFileEntries().begin(),
downloadContext_->getFileEntries().end());
- SharedHandle<DiskWriter> writer =
+ std::shared_ptr<DiskWriter> writer =
diskWriterFactory_->newDiskWriter(directDiskAdaptor->getFilePath());
directDiskAdaptor->setDiskWriter(writer);
@@ -71,24 +71,24 @@ void UnknownLengthPieceStorage::initStorage()
#ifdef ENABLE_BITTORRENT
-bool UnknownLengthPieceStorage::hasMissingPiece(const SharedHandle<Peer>& peer)
+bool UnknownLengthPieceStorage::hasMissingPiece(const std::shared_ptr<Peer>& peer)
{
abort();
}
void UnknownLengthPieceStorage::getMissingPiece
-(std::vector<SharedHandle<Piece> >& pieces,
+(std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
cuid_t cuid)
{
abort();
}
void UnknownLengthPieceStorage::getMissingPiece
-(std::vector<SharedHandle<Piece> >& pieces,
+(std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid)
{
@@ -96,33 +96,33 @@ void UnknownLengthPieceStorage::getMissingPiece
}
void UnknownLengthPieceStorage::getMissingFastPiece
-(std::vector<SharedHandle<Piece> >& pieces,
+(std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
cuid_t cuid)
{
abort();
}
void UnknownLengthPieceStorage::getMissingFastPiece
-(std::vector<SharedHandle<Piece> >& pieces,
+(std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid)
{
abort();
}
-SharedHandle<Piece> UnknownLengthPieceStorage::getMissingPiece
-(const SharedHandle<Peer>& peer,
+std::shared_ptr<Piece> UnknownLengthPieceStorage::getMissingPiece
+(const std::shared_ptr<Peer>& peer,
cuid_t cuid)
{
abort();
}
-SharedHandle<Piece> UnknownLengthPieceStorage::getMissingPiece
-(const SharedHandle<Peer>& peer,
+std::shared_ptr<Piece> UnknownLengthPieceStorage::getMissingPiece
+(const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid)
{
@@ -135,48 +135,48 @@ bool UnknownLengthPieceStorage::hasMissingUnusedPiece()
abort();
}
-SharedHandle<Piece> UnknownLengthPieceStorage::getMissingPiece
+std::shared_ptr<Piece> UnknownLengthPieceStorage::getMissingPiece
(size_t minSplitSize,
const unsigned char* ignoreBitfield,
size_t length,
cuid_t cuid)
{
if(downloadFinished_) {
- return SharedHandle<Piece>();
+ return std::shared_ptr<Piece>();
}
if(!piece_) {
piece_.reset(new Piece());
return piece_;
} else {
- return SharedHandle<Piece>();
+ return std::shared_ptr<Piece>();
}
}
-SharedHandle<Piece> UnknownLengthPieceStorage::getMissingPiece
+std::shared_ptr<Piece> UnknownLengthPieceStorage::getMissingPiece
(size_t index,
cuid_t cuid)
{
if(index == 0) {
return getMissingPiece(0, 0, 0, cuid);
} else {
- return SharedHandle<Piece>();
+ return std::shared_ptr<Piece>();
}
}
-SharedHandle<Piece> UnknownLengthPieceStorage::getPiece(size_t index)
+std::shared_ptr<Piece> UnknownLengthPieceStorage::getPiece(size_t index)
{
if(index == 0) {
if(!piece_) {
- return SharedHandle<Piece>(new Piece());
+ return std::shared_ptr<Piece>(new Piece());
} else {
return piece_;
}
} else {
- return SharedHandle<Piece>();
+ return std::shared_ptr<Piece>();
}
}
-void UnknownLengthPieceStorage::completePiece(const SharedHandle<Piece>& piece)
+void UnknownLengthPieceStorage::completePiece(const std::shared_ptr<Piece>& piece)
{
if(*piece_ == *piece) {
downloadFinished_ = true;
@@ -187,7 +187,7 @@ void UnknownLengthPieceStorage::completePiece(const SharedHandle<Piece>& piece)
}
void UnknownLengthPieceStorage::cancelPiece
-(const SharedHandle<Piece>& piece,
+(const std::shared_ptr<Piece>& piece,
cuid_t cuid)
{
if(*piece_ == *piece) {
@@ -213,7 +213,7 @@ bool UnknownLengthPieceStorage::isPieceUsed(size_t index)
}
}
-SharedHandle<DiskAdaptor> UnknownLengthPieceStorage::getDiskAdaptor()
+std::shared_ptr<DiskAdaptor> UnknownLengthPieceStorage::getDiskAdaptor()
{
return diskAdaptor_;
}
@@ -249,11 +249,11 @@ void UnknownLengthPieceStorage::markPieceMissing(size_t index)
}
void UnknownLengthPieceStorage::getInFlightPieces
-(std::vector<SharedHandle<Piece> >& pieces)
+(std::vector<std::shared_ptr<Piece> >& pieces)
{}
void UnknownLengthPieceStorage::setDiskWriterFactory
-(const SharedHandle<DiskWriterFactory>& diskWriterFactory)
+(const std::shared_ptr<DiskWriterFactory>& diskWriterFactory)
{
diskWriterFactory_ = diskWriterFactory;
}
diff --git a/src/UnknownLengthPieceStorage.h b/src/UnknownLengthPieceStorage.h
index 68caa8fd..c7d232ed 100644
--- a/src/UnknownLengthPieceStorage.h
+++ b/src/UnknownLengthPieceStorage.h
@@ -46,19 +46,19 @@ class DirectDiskAdaptor;
class UnknownLengthPieceStorage:public PieceStorage {
private:
- SharedHandle<DownloadContext> downloadContext_;
+ std::shared_ptr<DownloadContext> downloadContext_;
- SharedHandle<DirectDiskAdaptor> diskAdaptor_;
+ std::shared_ptr<DirectDiskAdaptor> diskAdaptor_;
- SharedHandle<DiskWriterFactory> diskWriterFactory_;
+ std::shared_ptr<DiskWriterFactory> diskWriterFactory_;
int64_t totalLength_;
bool downloadFinished_;
- SharedHandle<Piece> piece_;
+ std::shared_ptr<Piece> piece_;
public:
- UnknownLengthPieceStorage(const SharedHandle<DownloadContext>& downloadContext);
+ UnknownLengthPieceStorage(const std::shared_ptr<DownloadContext>& downloadContext);
virtual ~UnknownLengthPieceStorage();
@@ -68,40 +68,40 @@ public:
* Returns true if the peer has a piece that localhost doesn't have.
* Otherwise returns false.
*/
- virtual bool hasMissingPiece(const SharedHandle<Peer>& peer);
+ virtual bool hasMissingPiece(const std::shared_ptr<Peer>& peer);
virtual void getMissingPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
cuid_t cuid);
virtual void getMissingPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid);
virtual void getMissingFastPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
cuid_t cuid);
virtual void getMissingFastPiece
- (std::vector<SharedHandle<Piece> >& pieces,
+ (std::vector<std::shared_ptr<Piece> >& pieces,
size_t minMissingBlocks,
- const SharedHandle<Peer>& peer,
+ const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid);
- virtual SharedHandle<Piece> getMissingPiece
- (const SharedHandle<Peer>& peer,
+ virtual std::shared_ptr<Piece> getMissingPiece
+ (const std::shared_ptr<Peer>& peer,
cuid_t cuid);
- virtual SharedHandle<Piece> getMissingPiece
- (const SharedHandle<Peer>& peer,
+ virtual std::shared_ptr<Piece> getMissingPiece
+ (const std::shared_ptr<Peer>& peer,
const std::vector<size_t>& excludedIndexes,
cuid_t cuid);
#endif // ENABLE_BITTORRENT
@@ -111,7 +111,7 @@ public:
/**
* Returns a missing piece if available. Otherwise returns 0;
*/
- virtual SharedHandle<Piece> getMissingPiece
+ virtual std::shared_ptr<Piece> getMissingPiece
(size_t minSplitSize,
const unsigned char* ignoreBitfield,
size_t length,
@@ -123,23 +123,23 @@ public:
* then returns 0.
* Also returns 0 if any of missing piece is not available.
*/
- virtual SharedHandle<Piece> getMissingPiece(size_t index, cuid_t cuid);
+ virtual std::shared_ptr<Piece> getMissingPiece(size_t index, cuid_t cuid);
/**
* Returns the piece denoted by index.
* No status of the piece is changed in this method.
*/
- virtual SharedHandle<Piece> getPiece(size_t index);
+ virtual std::shared_ptr<Piece> getPiece(size_t index);
/**
* Tells that the download of the specfied piece completes.
*/
- virtual void completePiece(const SharedHandle<Piece>& piece);
+ virtual void completePiece(const std::shared_ptr<Piece>& piece);
/**
* Tells that the download of the specified piece is canceled.
*/
- virtual void cancelPiece(const SharedHandle<Piece>& piece, cuid_t cuid);
+ virtual void cancelPiece(const std::shared_ptr<Piece>& piece, cuid_t cuid);
/**
* Returns true if the specified piece is already downloaded.
@@ -226,7 +226,7 @@ public:
virtual void setEndGamePieceNum(size_t num) {}
- virtual SharedHandle<DiskAdaptor> getDiskAdaptor();
+ virtual std::shared_ptr<DiskAdaptor> getDiskAdaptor();
virtual WrDiskCache* getWrDiskCache() { return 0; }
@@ -269,14 +269,14 @@ public:
* class.
*/
virtual void addInFlightPiece
- (const std::vector<SharedHandle<Piece> >& pieces) {}
+ (const std::vector<std::shared_ptr<Piece> >& pieces) {}
virtual size_t countInFlightPiece()
{
return 0;
}
- virtual void getInFlightPieces(std::vector<SharedHandle<Piece> >& pieces);
+ virtual void getInFlightPieces(std::vector<std::shared_ptr<Piece> >& pieces);
virtual void addPieceStats(size_t index) {}
@@ -292,7 +292,7 @@ public:
virtual size_t getNextUsedIndex(size_t index) { return 0; }
- void setDiskWriterFactory(const SharedHandle<DiskWriterFactory>& diskWriterFactory);
+ void setDiskWriterFactory(const std::shared_ptr<DiskWriterFactory>& diskWriterFactory);
virtual void onDownloadIncomplete() {}
};
diff --git a/src/UnknownOptionException.cc b/src/UnknownOptionException.cc
index 6eaec2b5..33e87fd8 100644
--- a/src/UnknownOptionException.cc
+++ b/src/UnknownOptionException.cc
@@ -59,9 +59,9 @@ UnknownOptionException::UnknownOptionException
UnknownOptionException::~UnknownOptionException() throw() {}
-SharedHandle<Exception> UnknownOptionException::copy() const
+std::shared_ptr<Exception> UnknownOptionException::copy() const
{
- SharedHandle<Exception> e(new UnknownOptionException(*this));
+ std::shared_ptr<Exception> e(new UnknownOptionException(*this));
return e;
}
diff --git a/src/UnknownOptionException.h b/src/UnknownOptionException.h
index 0371b724..b6dd2e88 100644
--- a/src/UnknownOptionException.h
+++ b/src/UnknownOptionException.h
@@ -42,7 +42,7 @@ class UnknownOptionException:public RecoverableException {
private:
std::string unknownOption_;
protected:
- virtual SharedHandle<Exception> copy() const;
+ virtual std::shared_ptr<Exception> copy() const;
public:
UnknownOptionException(const char* file, int line,
const std::string& unknownOption);
diff --git a/src/UriListParser.cc b/src/UriListParser.cc
index 3261beb9..f0e41a4d 100644
--- a/src/UriListParser.cc
+++ b/src/UriListParser.cc
@@ -63,7 +63,7 @@ UriListParser::~UriListParser() {}
void UriListParser::parseNext(std::vector<std::string>& uris, Option& op)
{
- const SharedHandle<OptionParser>& optparser = OptionParser::getInstance();
+ const std::shared_ptr<OptionParser>& optparser = OptionParser::getInstance();
while(1) {
if(!line_.empty() && line_[0] != '#') {
util::split(line_.begin(), line_.end(), std::back_inserter(uris),
diff --git a/src/UriListParser.h b/src/UriListParser.h
index ce456120..c340ad41 100644
--- a/src/UriListParser.h
+++ b/src/UriListParser.h
@@ -40,16 +40,16 @@
#include <string>
#include <deque>
#include <iosfwd>
+#include <memory>
#include "Option.h"
#include "IOFile.h"
-#include "SharedHandle.h"
namespace aria2 {
class UriListParser {
private:
- SharedHandle<IOFile> fp_;
+ std::shared_ptr<IOFile> fp_;
std::string line_;
public:
diff --git a/src/ValueBase.cc b/src/ValueBase.cc
index 7165f886..b8c4e6db 100644
--- a/src/ValueBase.cc
+++ b/src/ValueBase.cc
@@ -36,7 +36,7 @@
namespace aria2 {
-const SharedHandle<ValueBase> ValueBase::none;
+const std::shared_ptr<ValueBase> ValueBase::none;
String::String(const ValueType& string):str_(string) {}
@@ -61,14 +61,14 @@ const unsigned char* String::uc() const
return reinterpret_cast<const unsigned char*>(str_.data());
}
-SharedHandle<String> String::g(const ValueType& string)
+std::shared_ptr<String> String::g(const ValueType& string)
{
- return SharedHandle<String>(new String(string));
+ return std::shared_ptr<String>(new String(string));
}
-SharedHandle<String> String::g(const unsigned char* data, size_t length)
+std::shared_ptr<String> String::g(const unsigned char* data, size_t length)
{
- return SharedHandle<String>(new String(data, length));
+ return std::shared_ptr<String>(new String(data, length));
}
void String::accept(ValueBaseVisitor& v) const
@@ -87,9 +87,9 @@ Integer::ValueType Integer::i() const
return integer_;
}
-SharedHandle<Integer> Integer::g(ValueType integer)
+std::shared_ptr<Integer> Integer::g(ValueType integer)
{
- return SharedHandle<Integer>(new Integer(integer));
+ return std::shared_ptr<Integer>(new Integer(integer));
}
void Integer::accept(ValueBaseVisitor& v) const
@@ -97,15 +97,15 @@ void Integer::accept(ValueBaseVisitor& v) const
v.visit(*this);
}
-const SharedHandle<Bool> Bool::trueValue_(new Bool(true));
-const SharedHandle<Bool> Bool::falseValue_(new Bool(false));
+const std::shared_ptr<Bool> Bool::trueValue_(new Bool(true));
+const std::shared_ptr<Bool> Bool::falseValue_(new Bool(false));
-SharedHandle<Bool> Bool::gTrue()
+std::shared_ptr<Bool> Bool::gTrue()
{
return trueValue_;
}
-SharedHandle<Bool> Bool::gFalse()
+std::shared_ptr<Bool> Bool::gFalse()
{
return falseValue_;
}
@@ -122,9 +122,9 @@ void Bool::accept(ValueBaseVisitor& v) const
Bool::Bool(bool val):val_(val) {}
-const SharedHandle<Null> Null::nullValue_(new Null());
+const std::shared_ptr<Null> Null::nullValue_(new Null());
-SharedHandle<Null> Null::g()
+std::shared_ptr<Null> Null::g()
{
return nullValue_;
}
@@ -140,17 +140,17 @@ List::List() {}
List::~List() {}
-const SharedHandle<ValueBase>& List::get(size_t index) const
+const std::shared_ptr<ValueBase>& List::get(size_t index) const
{
return list_[index];
}
-void List::set(size_t index, const SharedHandle<ValueBase>& v)
+void List::set(size_t index, const std::shared_ptr<ValueBase>& v)
{
list_[index] = v;
}
-void List::append(const SharedHandle<ValueBase>& v)
+void List::append(const std::shared_ptr<ValueBase>& v)
{
list_.push_back(v);
}
@@ -160,13 +160,13 @@ void List::append(const String::ValueType& string)
list_.push_back(String::g(string));
}
-List& List::operator<<(const SharedHandle<ValueBase>& v)
+List& List::operator<<(const std::shared_ptr<ValueBase>& v)
{
list_.push_back(v);
return *this;
}
-const SharedHandle<ValueBase>& List::operator[](size_t index) const
+const std::shared_ptr<ValueBase>& List::operator[](size_t index) const
{
return list_[index];
}
@@ -201,9 +201,9 @@ bool List::empty() const
return list_.empty();
}
-SharedHandle<List> List::g()
+std::shared_ptr<List> List::g()
{
- return SharedHandle<List>(new List());
+ return std::shared_ptr<List>(new List());
}
void List::accept(ValueBaseVisitor& v) const
@@ -215,7 +215,7 @@ Dict::Dict() {}
Dict::~Dict() {}
-void Dict::put(const std::string& key, const SharedHandle<ValueBase>& vlb)
+void Dict::put(const std::string& key, const std::shared_ptr<ValueBase>& vlb)
{
ValueType::value_type p = std::make_pair(key, vlb);
std::pair<ValueType::iterator, bool> r = dict_.insert(p);
@@ -229,7 +229,7 @@ void Dict::put(const std::string& key, const String::ValueType& string)
put(key, String::g(string));
}
-const SharedHandle<ValueBase>& Dict::get(const std::string& key) const
+const std::shared_ptr<ValueBase>& Dict::get(const std::string& key) const
{
ValueType::const_iterator itr = dict_.find(key);
if(itr == dict_.end()) {
@@ -239,7 +239,7 @@ const SharedHandle<ValueBase>& Dict::get(const std::string& key) const
}
}
-SharedHandle<ValueBase>& Dict::get(const std::string& key)
+std::shared_ptr<ValueBase>& Dict::get(const std::string& key)
{
ValueType::iterator itr = dict_.find(key);
if(itr == dict_.end()) {
@@ -249,12 +249,12 @@ SharedHandle<ValueBase>& Dict::get(const std::string& key)
}
}
-SharedHandle<ValueBase>& Dict::operator[](const std::string& key)
+std::shared_ptr<ValueBase>& Dict::operator[](const std::string& key)
{
return get(key);
}
-const SharedHandle<ValueBase>& Dict::operator[](const std::string& key) const
+const std::shared_ptr<ValueBase>& Dict::operator[](const std::string& key) const
{
return get(key);
}
@@ -299,9 +299,9 @@ bool Dict::empty() const
return dict_.empty();
}
-SharedHandle<Dict> Dict::g()
+std::shared_ptr<Dict> Dict::g()
{
- return SharedHandle<Dict>(new Dict());
+ return std::shared_ptr<Dict>(new Dict());
}
void Dict::accept(ValueBaseVisitor& v) const
{
diff --git a/src/ValueBase.h b/src/ValueBase.h
index f3d90af0..c7986acf 100644
--- a/src/ValueBase.h
+++ b/src/ValueBase.h
@@ -40,8 +40,7 @@
#include <string>
#include <vector>
#include <map>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -53,7 +52,7 @@ public:
virtual void accept(ValueBaseVisitor& visitor) const = 0;
- static const SharedHandle<ValueBase> none;
+ static const std::shared_ptr<ValueBase> none;
};
class String;
@@ -105,14 +104,14 @@ public:
// Use s().size() to get length.
const unsigned char* uc() const;
- static SharedHandle<String> g(const ValueType& string);
+ static std::shared_ptr<String> g(const ValueType& string);
- static SharedHandle<String> g(const unsigned char* data, size_t length);
+ static std::shared_ptr<String> g(const unsigned char* data, size_t length);
template<typename InputIterator>
- static SharedHandle<String> g(InputIterator first, InputIterator last)
+ static std::shared_ptr<String> g(InputIterator first, InputIterator last)
{
- return SharedHandle<String>(new String(first, last));
+ return std::shared_ptr<String>(new String(first, last));
}
virtual void accept(ValueBaseVisitor& visitor) const;
@@ -137,7 +136,7 @@ public:
// Returns Integer.
ValueType i() const;
- static SharedHandle<Integer> g(ValueType integer);
+ static std::shared_ptr<Integer> g(ValueType integer);
virtual void accept(ValueBaseVisitor& visitor) const;
private:
@@ -146,8 +145,8 @@ private:
class Bool:public ValueBase {
public:
- static SharedHandle<Bool> gTrue();
- static SharedHandle<Bool> gFalse();
+ static std::shared_ptr<Bool> gTrue();
+ static std::shared_ptr<Bool> gFalse();
bool val() const;
virtual void accept(ValueBaseVisitor& visitor) const;
private:
@@ -156,25 +155,25 @@ private:
Bool(const Bool&);
Bool& operator=(const Bool&);
bool val_;
- static const SharedHandle<Bool> trueValue_;
- static const SharedHandle<Bool> falseValue_;
+ static const std::shared_ptr<Bool> trueValue_;
+ static const std::shared_ptr<Bool> falseValue_;
};
class Null:public ValueBase {
public:
- static SharedHandle<Null> g();
+ static std::shared_ptr<Null> g();
virtual void accept(ValueBaseVisitor& visitor) const;
private:
Null();
// Don't allow copying
Null(const Null&);
Null& operator=(const Null&);
- static const SharedHandle<Null> nullValue_;
+ static const std::shared_ptr<Null> nullValue_;
};
class List:public ValueBase {
public:
- typedef std::vector<SharedHandle<ValueBase> > ValueType;
+ typedef std::vector<std::shared_ptr<ValueBase> > ValueType;
List();
@@ -185,22 +184,22 @@ public:
List& operator=(const List&);
// Appends given v to list.
- void append(const SharedHandle<ValueBase>& v);
+ void append(const std::shared_ptr<ValueBase>& v);
// Appeding string is so common that we provide shortcut function.
void append(const String::ValueType& string);
// Alias for append()
- List& operator<<(const SharedHandle<ValueBase>& v);
+ List& operator<<(const std::shared_ptr<ValueBase>& v);
// Returns the object at given index.
- const SharedHandle<ValueBase>& get(size_t index) const;
+ const std::shared_ptr<ValueBase>& get(size_t index) const;
// Set the object at given index.
- void set(size_t index, const SharedHandle<ValueBase>& v);
+ void set(size_t index, const std::shared_ptr<ValueBase>& v);
// Returns the const reference of the object at the given index.
- const SharedHandle<ValueBase>& operator[](size_t index) const;
+ const std::shared_ptr<ValueBase>& operator[](size_t index) const;
// Returns a read/write iterator that points to the first object in
// list.
@@ -224,7 +223,7 @@ public:
// Returns true if size of list is 0.
bool empty() const;
- static SharedHandle<List> g();
+ static std::shared_ptr<List> g();
virtual void accept(ValueBaseVisitor& visitor) const;
private:
@@ -233,7 +232,7 @@ private:
class Dict:public ValueBase {
public:
- typedef std::map<std::string, SharedHandle<ValueBase> > ValueType;
+ typedef std::map<std::string, std::shared_ptr<ValueBase> > ValueType;
Dict();
@@ -243,24 +242,24 @@ public:
Dict(const Dict&);
Dict& operator=(const Dict&);
- void put(const std::string& key, const SharedHandle<ValueBase>& vlb);
+ void put(const std::string& key, const std::shared_ptr<ValueBase>& vlb);
// Putting string is so common that we provide shortcut function.
void put(const std::string& key, const String::ValueType& string);
- const SharedHandle<ValueBase>& get(const std::string& key) const;
+ const std::shared_ptr<ValueBase>& get(const std::string& key) const;
- SharedHandle<ValueBase>& get(const std::string& key);
+ std::shared_ptr<ValueBase>& get(const std::string& key);
// Returns the reference to object associated with given key. If
// the key is not found, new pair with that key is created using
// default values, which is then returned. In other words, this is
// the same behavior of std::map's operator[].
- SharedHandle<ValueBase>& operator[](const std::string& key);
+ std::shared_ptr<ValueBase>& operator[](const std::string& key);
// Returns the const reference to ojbect associated with given key.
// If the key is not found, ValueBase::none is returned.
- const SharedHandle<ValueBase>& operator[](const std::string& key) const;
+ const std::shared_ptr<ValueBase>& operator[](const std::string& key) const;
// Returns true if the given key is found in dict.
bool containsKey(const std::string& key) const;
@@ -290,7 +289,7 @@ public:
// Returns true if size of Dict is 0.
bool empty() const;
- static SharedHandle<Dict> g();
+ static std::shared_ptr<Dict> g();
virtual void accept(ValueBaseVisitor& visitor) const;
private:
diff --git a/src/ValueBaseDiskWriter.h b/src/ValueBaseDiskWriter.h
index 3f326c96..5c26ca83 100644
--- a/src/ValueBaseDiskWriter.h
+++ b/src/ValueBaseDiskWriter.h
@@ -92,7 +92,7 @@ public:
return parser_.parseFinal(0, 0);
}
- SharedHandle<ValueBase> getResult() const
+ std::shared_ptr<ValueBase> getResult() const
{
return psm_.getResult();
}
diff --git a/src/ValueBaseStructParserStateImpl.cc b/src/ValueBaseStructParserStateImpl.cc
index 4d62426e..8118675b 100644
--- a/src/ValueBaseStructParserStateImpl.cc
+++ b/src/ValueBaseStructParserStateImpl.cc
@@ -33,6 +33,9 @@
*/
/* copyright --> */
#include "ValueBaseStructParserStateImpl.h"
+
+#include <cassert>
+
#include "ValueBaseStructParserStateMachine.h"
#include "ValueBase.h"
diff --git a/src/ValueBaseStructParserStateMachine.cc b/src/ValueBaseStructParserStateMachine.cc
index 04d1033c..4f63ed14 100644
--- a/src/ValueBaseStructParserStateMachine.cc
+++ b/src/ValueBaseStructParserStateMachine.cc
@@ -65,7 +65,7 @@ NullValueBaseStructParserState* nullState =
new NullValueBaseStructParserState();
} // namespace
-const SharedHandle<ValueBase>&
+const std::shared_ptr<ValueBase>&
ValueBaseStructParserStateMachine::noResult()
{
return ValueBase::none;
@@ -102,7 +102,7 @@ void ValueBaseStructParserStateMachine::endElement(int elementType)
stateStack_.pop();
}
-SharedHandle<ValueBase>
+std::shared_ptr<ValueBase>
ValueBaseStructParserStateMachine::getResult() const
{
return getCurrentFrameValue();
@@ -159,12 +159,12 @@ void ValueBaseStructParserStateMachine::pushFrame()
}
void ValueBaseStructParserStateMachine::setCurrentFrameValue
-(const SharedHandle<ValueBase>& value)
+(const std::shared_ptr<ValueBase>& value)
{
ctrl_->setCurrentFrameValue(value);
}
-const SharedHandle<ValueBase>&
+const std::shared_ptr<ValueBase>&
ValueBaseStructParserStateMachine::getCurrentFrameValue() const
{
return ctrl_->getCurrentFrameValue();
diff --git a/src/ValueBaseStructParserStateMachine.h b/src/ValueBaseStructParserStateMachine.h
index 5b5efa56..a0f0e6a5 100644
--- a/src/ValueBaseStructParserStateMachine.h
+++ b/src/ValueBaseStructParserStateMachine.h
@@ -39,8 +39,7 @@
#include <string>
#include <stack>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -56,8 +55,8 @@ class ValueBaseStructParserState;
// value holder.
class ValueBaseStructParserStateMachine : public StructParserStateMachine {
public:
- typedef SharedHandle<ValueBase> ResultType;
- static const SharedHandle<ValueBase>& noResult();
+ typedef std::shared_ptr<ValueBase> ResultType;
+ static const std::shared_ptr<ValueBase>& noResult();
struct NumberData {
int64_t number;
@@ -81,7 +80,7 @@ public:
virtual void numberCallback(int64_t number, int frac, int exp);
virtual void boolCallback(bool bval);
- SharedHandle<ValueBase> getResult() const;
+ std::shared_ptr<ValueBase> getResult() const;
virtual void reset();
@@ -92,8 +91,8 @@ public:
void popArrayFrame();
void popDictFrame();
void pushFrame();
- void setCurrentFrameValue(const SharedHandle<ValueBase>& value);
- const SharedHandle<ValueBase>& getCurrentFrameValue() const;
+ void setCurrentFrameValue(const std::shared_ptr<ValueBase>& value);
+ const std::shared_ptr<ValueBase>& getCurrentFrameValue() const;
void setCurrentFrameName(const std::string& name);
void pushDictState();
diff --git a/src/WebSocketInteractionCommand.cc b/src/WebSocketInteractionCommand.cc
index a21db84d..a1eaf3af 100644
--- a/src/WebSocketInteractionCommand.cc
+++ b/src/WebSocketInteractionCommand.cc
@@ -50,9 +50,9 @@ namespace rpc {
WebSocketInteractionCommand::WebSocketInteractionCommand
(cuid_t cuid,
- const SharedHandle<WebSocketSession>& wsSession,
+ const std::shared_ptr<WebSocketSession>& wsSession,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket)
+ const std::shared_ptr<SocketCore>& socket)
: Command(cuid),
e_(e),
socket_(socket),
@@ -92,10 +92,10 @@ bool WebSocketInteractionCommand::execute()
}
if(wsSession_->onReadEvent() == -1 || wsSession_->onWriteEvent() == -1) {
if(wsSession_->closeSent() || wsSession_->closeReceived()) {
- A2_LOG_INFO(fmt("CUID#%"PRId64" - WebSocket session terminated.",
+ A2_LOG_INFO(fmt("CUID#%" PRId64 " - WebSocket session terminated.",
getCuid()));
} else {
- A2_LOG_INFO(fmt("CUID#%"PRId64" - WebSocket session terminated"
+ A2_LOG_INFO(fmt("CUID#%" PRId64 " - WebSocket session terminated"
" (Possibly due to EOF).", getCuid()));
}
return true;
diff --git a/src/WebSocketInteractionCommand.h b/src/WebSocketInteractionCommand.h
index c27bf90e..4b1acf73 100644
--- a/src/WebSocketInteractionCommand.h
+++ b/src/WebSocketInteractionCommand.h
@@ -36,7 +36,8 @@
#define D_WEB_SOCKET_INTERACTION_COMMAND_H
#include "Command.h"
-#include "SharedHandle.h"
+
+#include <memory>
namespace aria2 {
@@ -50,14 +51,14 @@ class WebSocketSession;
class WebSocketInteractionCommand : public Command {
private:
DownloadEngine* e_;
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<SocketCore> socket_;
bool writeCheck_;
- SharedHandle<WebSocketSession> wsSession_;
+ std::shared_ptr<WebSocketSession> wsSession_;
public:
WebSocketInteractionCommand(cuid_t cuid,
- const SharedHandle<WebSocketSession>& wsSession,
+ const std::shared_ptr<WebSocketSession>& wsSession,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket);
+ const std::shared_ptr<SocketCore>& socket);
virtual ~WebSocketInteractionCommand();
diff --git a/src/WebSocketResponseCommand.cc b/src/WebSocketResponseCommand.cc
index ba6add52..245c14d7 100644
--- a/src/WebSocketResponseCommand.cc
+++ b/src/WebSocketResponseCommand.cc
@@ -45,9 +45,9 @@ namespace rpc {
WebSocketResponseCommand::WebSocketResponseCommand
(cuid_t cuid,
- const SharedHandle<HttpServer>& httpServer,
+ const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket)
+ const std::shared_ptr<SocketCore>& socket)
: AbstractHttpServerResponseCommand(cuid, httpServer, e, socket)
{}
@@ -55,10 +55,10 @@ WebSocketResponseCommand::~WebSocketResponseCommand()
{}
void WebSocketResponseCommand::afterSend
-(const SharedHandle<HttpServer>& httpServer,
+(const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e)
{
- SharedHandle<WebSocketSession> wsSession
+ std::shared_ptr<WebSocketSession> wsSession
(new WebSocketSession(httpServer->getSocket(), getDownloadEngine()));
WebSocketInteractionCommand* command =
new WebSocketInteractionCommand(getCuid(), wsSession, e,
diff --git a/src/WebSocketResponseCommand.h b/src/WebSocketResponseCommand.h
index 1c3cc642..b570a5d0 100644
--- a/src/WebSocketResponseCommand.h
+++ b/src/WebSocketResponseCommand.h
@@ -43,13 +43,13 @@ namespace rpc {
class WebSocketResponseCommand : public AbstractHttpServerResponseCommand {
protected:
- virtual void afterSend(const SharedHandle<HttpServer>& httpServer,
+ virtual void afterSend(const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e);
public:
WebSocketResponseCommand(cuid_t cuid,
- const SharedHandle<HttpServer>& httpServer,
+ const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
- const SharedHandle<SocketCore>& socket);
+ const std::shared_ptr<SocketCore>& socket);
virtual ~WebSocketResponseCommand();
};
diff --git a/src/WebSocketSession.cc b/src/WebSocketSession.cc
index 638876cf..6baa70bd 100644
--- a/src/WebSocketSession.cc
+++ b/src/WebSocketSession.cc
@@ -36,6 +36,7 @@
#include <cerrno>
#include <cstring>
+#include <cassert>
#include "SocketCore.h"
#include "LogFactory.h"
@@ -58,7 +59,7 @@ ssize_t sendCallback(wslay_event_context_ptr wsctx,
void* userData)
{
WebSocketSession* session = reinterpret_cast<WebSocketSession*>(userData);
- const SharedHandle<SocketCore>& socket = session->getSocket();
+ const std::shared_ptr<SocketCore>& socket = session->getSocket();
try {
ssize_t r = socket->writeData(data, len);
if(r == 0) {
@@ -84,7 +85,7 @@ ssize_t recvCallback(wslay_event_context_ptr wsctx,
void* userData)
{
WebSocketSession* session = reinterpret_cast<WebSocketSession*>(userData);
- const SharedHandle<SocketCore>& socket = session->getSocket();
+ const std::shared_ptr<SocketCore>& socket = session->getSocket();
try {
ssize_t r;
socket->readData(buf, len);
@@ -159,7 +160,7 @@ void onMsgRecvCallback(wslay_event_context_ptr wsctx,
if(!wslay_is_ctrl_frame(arg->opcode)) {
// TODO Only process text frame
ssize_t error = 0;
- SharedHandle<ValueBase> json = wsSession->parseFinal(0, 0, error);
+ std::shared_ptr<ValueBase> json = wsSession->parseFinal(0, 0, error);
if(error < 0) {
A2_LOG_INFO("Failed to parse JSON-RPC request");
RpcResponse res
@@ -201,7 +202,7 @@ void onMsgRecvCallback(wslay_event_context_ptr wsctx,
}
} // namespace
-WebSocketSession::WebSocketSession(const SharedHandle<SocketCore>& socket,
+WebSocketSession::WebSocketSession(const std::shared_ptr<SocketCore>& socket,
DownloadEngine* e)
: socket_(socket),
e_(e),
@@ -291,10 +292,10 @@ ssize_t WebSocketSession::parseUpdate(const uint8_t* data, size_t len)
return parser_.parseUpdate(reinterpret_cast<const char*>(data), len);
}
-SharedHandle<ValueBase> WebSocketSession::parseFinal
+std::shared_ptr<ValueBase> WebSocketSession::parseFinal
(const uint8_t* data, size_t len, ssize_t& error)
{
- SharedHandle<ValueBase> res =
+ std::shared_ptr<ValueBase> res =
parser_.parseFinal(reinterpret_cast<const char*>(data), len, error);
receivedLength_ = 0;
return res;
diff --git a/src/WebSocketSession.h b/src/WebSocketSession.h
index 71bba67a..4cd21fb9 100644
--- a/src/WebSocketSession.h
+++ b/src/WebSocketSession.h
@@ -37,9 +37,10 @@
#include "common.h"
+#include <memory>
+
#include <wslay/wslay.h>
-#include "SharedHandle.h"
#include "ValueBaseJsonParser.h"
namespace aria2 {
@@ -53,7 +54,7 @@ class WebSocketInteractionCommand;
class WebSocketSession {
public:
- WebSocketSession(const SharedHandle<SocketCore>& socket,
+ WebSocketSession(const std::shared_ptr<SocketCore>& socket,
DownloadEngine* e);
~WebSocketSession();
// Returns true if this session object wants to read data from the
@@ -85,10 +86,10 @@ public:
// |error| will be the number of bytes processed if this function
// succeeds, or negative error code. Whether success or failure,
// this function resets parser state and receivedLength_.
- SharedHandle<ValueBase> parseFinal(const uint8_t* data, size_t len,
+ std::shared_ptr<ValueBase> parseFinal(const uint8_t* data, size_t len,
ssize_t& error);
- const SharedHandle<SocketCore>& getSocket() const
+ const std::shared_ptr<SocketCore>& getSocket() const
{
return socket_;
}
@@ -118,7 +119,7 @@ public:
ignorePayload_ = flag;
}
private:
- SharedHandle<SocketCore> socket_;
+ std::shared_ptr<SocketCore> socket_;
DownloadEngine* e_;
wslay_event_context_ptr wsctx_;
bool ignorePayload_;
diff --git a/src/WebSocketSessionMan.cc b/src/WebSocketSessionMan.cc
index 54c96fac..edc961f0 100644
--- a/src/WebSocketSessionMan.cc
+++ b/src/WebSocketSessionMan.cc
@@ -33,6 +33,9 @@
*/
/* copyright --> */
#include "WebSocketSessionMan.h"
+
+#include <cassert>
+
#include "WebSocketSession.h"
#include "RequestGroup.h"
#include "json.h"
@@ -49,14 +52,14 @@ WebSocketSessionMan::WebSocketSessionMan() {}
WebSocketSessionMan::~WebSocketSessionMan() {}
void WebSocketSessionMan::addSession
-(const SharedHandle<WebSocketSession>& wsSession)
+(const std::shared_ptr<WebSocketSession>& wsSession)
{
A2_LOG_DEBUG("WebSocket session added.");
sessions_.insert(wsSession);
}
void WebSocketSessionMan::removeSession
-(const SharedHandle<WebSocketSession>& wsSession)
+(const std::shared_ptr<WebSocketSession>& wsSession)
{
A2_LOG_DEBUG("WebSocket session removed.");
sessions_.erase(wsSession);
@@ -65,12 +68,12 @@ void WebSocketSessionMan::removeSession
void WebSocketSessionMan::addNotification
(const std::string& method, const RequestGroup* group)
{
- SharedHandle<Dict> dict = Dict::g();
+ std::shared_ptr<Dict> dict = Dict::g();
dict->put("jsonrpc", "2.0");
dict->put("method", method);
- SharedHandle<Dict> eventSpec = Dict::g();
+ std::shared_ptr<Dict> eventSpec = Dict::g();
eventSpec->put("gid", GroupId::toHex((group->getGID())));
- SharedHandle<List> params = List::g();
+ std::shared_ptr<List> params = List::g();
params->append(eventSpec);
dict->put("params", params);
std::string msg = json::encode(dict);
diff --git a/src/WebSocketSessionMan.h b/src/WebSocketSessionMan.h
index 4b2b5acc..d32654c0 100644
--- a/src/WebSocketSessionMan.h
+++ b/src/WebSocketSessionMan.h
@@ -39,8 +39,8 @@
#include <set>
#include <string>
+#include <memory>
-#include "SharedHandle.h"
#include "a2functional.h"
namespace aria2 {
@@ -53,12 +53,12 @@ class WebSocketSession;
class WebSocketSessionMan : public DownloadEventListener {
public:
- typedef std::set<SharedHandle<WebSocketSession>,
+ typedef std::set<std::shared_ptr<WebSocketSession>,
RefLess<WebSocketSession> > WebSocketSessions;
WebSocketSessionMan();
~WebSocketSessionMan();
- void addSession(const SharedHandle<WebSocketSession>& wsSession);
- void removeSession(const SharedHandle<WebSocketSession>& wsSession);
+ void addSession(const std::shared_ptr<WebSocketSession>& wsSession);
+ void removeSession(const std::shared_ptr<WebSocketSession>& wsSession);
void addNotification(const std::string& method, const RequestGroup* group);
virtual void onEvent(DownloadEvent event, const RequestGroup* group);
private:
diff --git a/src/WrDiskCache.cc b/src/WrDiskCache.cc
index cd204ea6..3238a35f 100644
--- a/src/WrDiskCache.cc
+++ b/src/WrDiskCache.cc
@@ -33,6 +33,9 @@
*/
/* copyright --> */
#include "WrDiskCache.h"
+
+#include <cassert>
+
#include "WrDiskCacheEntry.h"
#include "LogFactory.h"
#include "fmt.h"
@@ -63,8 +66,8 @@ bool WrDiskCache::add(WrDiskCacheEntry* ent)
ensureLimit();
return true;
} else {
- A2_LOG_WARN(fmt("Found duplicate cache entry a.{size=%lu,clock=%"PRId64
- "} b{size=%lu,clock=%"PRId64"}",
+ A2_LOG_WARN(fmt("Found duplicate cache entry a.{size=%lu,clock=%" PRId64
+ "} b{size=%lu,clock=%" PRId64 "}",
static_cast<unsigned long>((*rv.first)->getSize()),
(*rv.first)->getLastUpdate(),
static_cast<unsigned long>(ent->getSize()),
@@ -76,7 +79,7 @@ bool WrDiskCache::add(WrDiskCacheEntry* ent)
bool WrDiskCache::remove(WrDiskCacheEntry* ent)
{
if(set_.erase(ent)) {
- A2_LOG_DEBUG(fmt("Removed cache entry size=%lu, clock=%"PRId64,
+ A2_LOG_DEBUG(fmt("Removed cache entry size=%lu, clock=%" PRId64,
static_cast<unsigned long>(ent->getSize()),
ent->getLastUpdate()));
total_ -= ent->getSize();
@@ -91,7 +94,7 @@ bool WrDiskCache::update(WrDiskCacheEntry* ent, ssize_t delta)
if(!set_.erase(ent)) {
return false;
}
- A2_LOG_DEBUG(fmt("Update cache entry size=%lu, delta=%ld, clock=%"PRId64,
+ A2_LOG_DEBUG(fmt("Update cache entry size=%lu, delta=%ld, clock=%" PRId64,
static_cast<unsigned long>(ent->getSize()),
static_cast<long>(delta),
ent->getLastUpdate()));
@@ -113,7 +116,7 @@ void WrDiskCache::ensureLimit()
while(total_ > limit_) {
EntrySet::iterator i = set_.begin();
WrDiskCacheEntry* ent = *i;
- A2_LOG_DEBUG(fmt("Force flush cache entry size=%lu, clock=%"PRId64,
+ A2_LOG_DEBUG(fmt("Force flush cache entry size=%lu, clock=%" PRId64,
static_cast<unsigned long>(ent->getSizeKey()),
ent->getLastUpdate()));
total_ -= ent->getSize();
diff --git a/src/WrDiskCacheEntry.cc b/src/WrDiskCacheEntry.cc
index 9bdd2de8..5039a6c3 100644
--- a/src/WrDiskCacheEntry.cc
+++ b/src/WrDiskCacheEntry.cc
@@ -45,7 +45,7 @@
namespace aria2 {
WrDiskCacheEntry::WrDiskCacheEntry
-(const SharedHandle<DiskAdaptor>& diskAdaptor)
+(const std::shared_ptr<DiskAdaptor>& diskAdaptor)
: sizeKey_(0),
lastUpdate_(0),
size_(0),
@@ -93,7 +93,7 @@ void WrDiskCacheEntry::clear()
bool WrDiskCacheEntry::cacheData(DataCell* dataCell)
{
- A2_LOG_DEBUG(fmt("WrDiskCacheEntry cache goff=%"PRId64", len=%lu",
+ A2_LOG_DEBUG(fmt("WrDiskCacheEntry cache goff=%" PRId64 ", len=%lu",
dataCell->goff, static_cast<unsigned long>(dataCell->len)));
if(set_.insert(dataCell).second) {
size_ += dataCell->len;
diff --git a/src/WrDiskCacheEntry.h b/src/WrDiskCacheEntry.h
index cb0036ed..ba87e3e0 100644
--- a/src/WrDiskCacheEntry.h
+++ b/src/WrDiskCacheEntry.h
@@ -38,8 +38,8 @@
#include "common.h"
#include <set>
+#include <memory>
-#include "SharedHandle.h"
#include "a2functional.h"
#include "error_code.h"
@@ -68,7 +68,7 @@ public:
typedef std::set<DataCell*, DerefLess<DataCell*> > DataCellSet;
- WrDiskCacheEntry(const SharedHandle<DiskAdaptor>& diskAdaptor);
+ WrDiskCacheEntry(const std::shared_ptr<DiskAdaptor>& diskAdaptor);
~WrDiskCacheEntry();
// Flushes the cached data to the disk and deletes them.
@@ -140,7 +140,7 @@ private:
int error_;
error_code::Value errorCode_;
- SharedHandle<DiskAdaptor> diskAdaptor_;
+ std::shared_ptr<DiskAdaptor> diskAdaptor_;
};
} // namespace aria2
diff --git a/src/XmlRpcDiskWriter.cc b/src/XmlRpcDiskWriter.cc
index 45b090c7..9aabd3cc 100644
--- a/src/XmlRpcDiskWriter.cc
+++ b/src/XmlRpcDiskWriter.cc
@@ -67,9 +67,9 @@ int XmlRpcDiskWriter::finalize()
RpcRequest XmlRpcDiskWriter::getResult() const
{
- SharedHandle<List> params;
+ std::shared_ptr<List> params;
if(downcast<List>(psm_.getCurrentFrameValue())) {
- params = static_pointer_cast<List>(psm_.getCurrentFrameValue());
+ params = std::static_pointer_cast<List>(psm_.getCurrentFrameValue());
} else {
params = List::g();
}
diff --git a/src/XmlRpcRequestParserController.cc b/src/XmlRpcRequestParserController.cc
index cf01aace..3401a4cd 100644
--- a/src/XmlRpcRequestParserController.cc
+++ b/src/XmlRpcRequestParserController.cc
@@ -75,7 +75,7 @@ void XmlRpcRequestParserController::popArrayFrame()
}
void XmlRpcRequestParserController::setCurrentFrameValue
-(const SharedHandle<ValueBase>& value)
+(const std::shared_ptr<ValueBase>& value)
{
currentFrame_.value_ = value;
}
@@ -86,7 +86,7 @@ void XmlRpcRequestParserController::setCurrentFrameName
currentFrame_.name_ = name;
}
-const SharedHandle<ValueBase>&
+const std::shared_ptr<ValueBase>&
XmlRpcRequestParserController::getCurrentFrameValue() const
{
return currentFrame_.value_;
diff --git a/src/XmlRpcRequestParserController.h b/src/XmlRpcRequestParserController.h
index f6499e87..36fa86f0 100644
--- a/src/XmlRpcRequestParserController.h
+++ b/src/XmlRpcRequestParserController.h
@@ -50,7 +50,7 @@ class XmlRpcRequestParserController {
private:
struct StateFrame {
- SharedHandle<ValueBase> value_;
+ std::shared_ptr<ValueBase> value_;
std::string name_;
bool validMember() const
@@ -81,11 +81,11 @@ public:
// to p and currentFrame_ = p;
void popArrayFrame();
- void setCurrentFrameValue(const SharedHandle<ValueBase>& value);
+ void setCurrentFrameValue(const std::shared_ptr<ValueBase>& value);
void setCurrentFrameName(const std::string& name);
- const SharedHandle<ValueBase>& getCurrentFrameValue() const;
+ const std::shared_ptr<ValueBase>& getCurrentFrameValue() const;
void setMethodName(const std::string& methodName)
{
diff --git a/src/XmlRpcRequestParserStateMachine.cc b/src/XmlRpcRequestParserStateMachine.cc
index 78fbf028..22b90246 100644
--- a/src/XmlRpcRequestParserStateMachine.cc
+++ b/src/XmlRpcRequestParserStateMachine.cc
@@ -166,12 +166,12 @@ void XmlRpcRequestParserStateMachine::pushFrame()
}
void XmlRpcRequestParserStateMachine::setCurrentFrameValue
-(const SharedHandle<ValueBase>& value)
+(const std::shared_ptr<ValueBase>& value)
{
controller_->setCurrentFrameValue(value);
}
-const SharedHandle<ValueBase>&
+const std::shared_ptr<ValueBase>&
XmlRpcRequestParserStateMachine::getCurrentFrameValue() const
{
return controller_->getCurrentFrameValue();
diff --git a/src/XmlRpcRequestParserStateMachine.h b/src/XmlRpcRequestParserStateMachine.h
index 93be50d5..7116df9f 100644
--- a/src/XmlRpcRequestParserStateMachine.h
+++ b/src/XmlRpcRequestParserStateMachine.h
@@ -39,8 +39,7 @@
#include <string>
#include <stack>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -78,8 +77,8 @@ public:
void popArrayFrame();
void popStructFrame();
void pushFrame();
- void setCurrentFrameValue(const SharedHandle<ValueBase>& value);
- const SharedHandle<ValueBase>& getCurrentFrameValue() const;
+ void setCurrentFrameValue(const std::shared_ptr<ValueBase>& value);
+ const std::shared_ptr<ValueBase>& getCurrentFrameValue() const;
void setCurrentFrameName(const std::string& name);
void pushUnknownElementState();
diff --git a/src/a2functional.h b/src/a2functional.h
index c73bd567..a1cd9749 100644
--- a/src/a2functional.h
+++ b/src/a2functional.h
@@ -40,15 +40,15 @@
#include <functional>
#include <string>
#include <algorithm>
+#include <memory>
-#include "SharedHandle.h"
#include "A2STR.h"
namespace aria2 {
// mem_fun_t for SharedHandle
template <class ReturnType, typename ClassType>
-class mem_fun_sh_t:public std::unary_function< SharedHandle<ClassType>, ReturnType>
+class mem_fun_sh_t:public std::unary_function< std::shared_ptr<ClassType>, ReturnType>
{
private:
ReturnType (ClassType::*f)();
@@ -56,7 +56,7 @@ private:
public:
mem_fun_sh_t(ReturnType (ClassType::*f)()):f(f) {}
- ReturnType operator()(const SharedHandle<ClassType>& x) const
+ ReturnType operator()(const std::shared_ptr<ClassType>& x) const
{
return (x.get()->*f)();
}
@@ -64,7 +64,7 @@ public:
// const_mem_fun_t for SharedHandle
template <class ReturnType, typename ClassType>
-class const_mem_fun_sh_t:public std::unary_function< SharedHandle<ClassType>, ReturnType>
+class const_mem_fun_sh_t:public std::unary_function< std::shared_ptr<ClassType>, ReturnType>
{
private:
ReturnType (ClassType::*f)() const;
@@ -72,7 +72,7 @@ private:
public:
const_mem_fun_sh_t(ReturnType (ClassType::*f)() const):f(f) {}
- ReturnType operator()(const SharedHandle<ClassType>& x) const
+ ReturnType operator()(const std::shared_ptr<ClassType>& x) const
{
return (x.get()->*f)();
}
@@ -94,7 +94,7 @@ mem_fun_sh(ReturnType (ClassType::*f)() const)
// mem_fun1_t for SharedHandle
template<typename ReturnType, typename ClassType, typename ArgType>
-class mem_fun1_sh_t:public std::binary_function<SharedHandle<ClassType>,
+class mem_fun1_sh_t:public std::binary_function<std::shared_ptr<ClassType>,
ArgType,
ReturnType>
{
@@ -104,7 +104,7 @@ private:
public:
mem_fun1_sh_t(ReturnType (ClassType::*f)(ArgType)):f(f) {}
- ReturnType operator()(const SharedHandle<ClassType>& x, ArgType a) const
+ ReturnType operator()(const std::shared_ptr<ClassType>& x, ArgType a) const
{
return (x.get()->*f)(a);
}
@@ -271,8 +271,8 @@ std::string strjoin(InputIterator first, InputIterator last,
template<typename T>
class LeastRecentAccess:public std::binary_function<T, T, bool> {
public:
- bool operator()(const SharedHandle<T>& lhs,
- const SharedHandle<T>& rhs) const
+ bool operator()(const std::shared_ptr<T>& lhs,
+ const std::shared_ptr<T>& rhs) const
{
return lhs->getLastAccessTime() < rhs->getLastAccessTime();
}
@@ -324,7 +324,7 @@ struct DerefEqual<T> derefEqual(const T& t)
template<typename T>
struct RefLess {
- bool operator()(const SharedHandle<T>& lhs, const SharedHandle<T>& rhs) const
+ bool operator()(const std::shared_ptr<T>& lhs, const std::shared_ptr<T>& rhs) const
{
return lhs.get() < rhs.get();
}
diff --git a/src/aria2api.cc b/src/aria2api.cc
index ff7beb65..bb5f6967 100644
--- a/src/aria2api.cc
+++ b/src/aria2api.cc
@@ -123,7 +123,7 @@ Session* sessionNew(const KeyVals& options, const SessionConfig& config)
delete session;
return 0;
}
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
if(config.keepRunning) {
e->getRequestGroupMan()->setKeepRunning(true);
@@ -131,7 +131,7 @@ Session* sessionNew(const KeyVals& options, const SessionConfig& config)
e->addCommand(new KeepRunningCommand(e->newCUID(), e.get()));
}
if(config.downloadEventCallback) {
- SharedHandle<DownloadEventListener> listener
+ std::shared_ptr<DownloadEventListener> listener
(new ApiCallbackDownloadEventListener(session,
config.downloadEventCallback,
config.userData));
@@ -154,14 +154,14 @@ int sessionFinal(Session* session)
int run(Session* session, RUN_MODE mode)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
return e->run(mode == RUN_ONCE);
}
int shutdown(Session* session, bool force)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
if(force) {
e->requestForceHalt();
@@ -200,7 +200,7 @@ void apiGatherOption
(InputIterator first, InputIterator last,
Pred pred,
Option* option,
- const SharedHandle<OptionParser>& optionParser)
+ const std::shared_ptr<OptionParser>& optionParser)
{
for(; first != last; ++first) {
const std::string& optionName = (*first).first;
@@ -217,7 +217,7 @@ void apiGatherOption
namespace {
void apiGatherRequestOption(Option* option, const KeyVals& options,
- const SharedHandle<OptionParser>& optionParser)
+ const std::shared_ptr<OptionParser>& optionParser)
{
apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getInitialOption),
@@ -227,7 +227,7 @@ void apiGatherRequestOption(Option* option, const KeyVals& options,
namespace {
void apiGatherChangeableOption(Option* option, const KeyVals& options,
- const SharedHandle<OptionParser>& optionParser)
+ const std::shared_ptr<OptionParser>& optionParser)
{
apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getChangeOption),
@@ -238,7 +238,7 @@ void apiGatherChangeableOption(Option* option, const KeyVals& options,
namespace {
void apiGatherChangeableOptionForReserved
(Option* option, const KeyVals& options,
- const SharedHandle<OptionParser>& optionParser)
+ const std::shared_ptr<OptionParser>& optionParser)
{
apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getChangeOptionForReserved),
@@ -249,7 +249,7 @@ void apiGatherChangeableOptionForReserved
namespace {
void apiGatherChangeableGlobalOption
(Option* option, const KeyVals& options,
- const SharedHandle<OptionParser>& optionParser)
+ const std::shared_ptr<OptionParser>& optionParser)
{
apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getChangeGlobalOption),
@@ -258,8 +258,8 @@ void apiGatherChangeableGlobalOption
} // namespace
namespace {
-void addRequestGroup(const SharedHandle<RequestGroup>& group,
- const SharedHandle<DownloadEngine>& e,
+void addRequestGroup(const std::shared_ptr<RequestGroup>& group,
+ const std::shared_ptr<DownloadEngine>& e,
int position)
{
if(position >= 0) {
@@ -276,9 +276,9 @@ int addUri(Session* session,
const KeyVals& options,
int position)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
- SharedHandle<Option> requestOption(new Option(*e->getOption()));
+ std::shared_ptr<Option> requestOption(new Option(*e->getOption()));
try {
apiGatherRequestOption(requestOption.get(), options,
OptionParser::getInstance());
@@ -286,7 +286,7 @@ int addUri(Session* session,
A2_LOG_INFO_EX(EX_EXCEPTION_CAUGHT, e);
return -1;
}
- std::vector<SharedHandle<RequestGroup> > result;
+ std::vector<std::shared_ptr<RequestGroup> > result;
createRequestGroupForUri(result, requestOption, uris,
/* ignoreForceSeq = */ true,
/* ignoreLocalPath = */ true);
@@ -306,10 +306,10 @@ int addMetalink(Session* session,
int position)
{
#ifdef ENABLE_METALINK
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
- SharedHandle<Option> requestOption(new Option(*e->getOption()));
- std::vector<SharedHandle<RequestGroup> > result;
+ std::shared_ptr<Option> requestOption(new Option(*e->getOption()));
+ std::vector<std::shared_ptr<RequestGroup> > result;
try {
apiGatherRequestOption(requestOption.get(), options,
OptionParser::getInstance());
@@ -326,7 +326,7 @@ int addMetalink(Session* session,
e->getRequestGroupMan()->addReservedGroup(result);
}
if(gids) {
- for(std::vector<SharedHandle<RequestGroup> >::const_iterator i =
+ for(std::vector<std::shared_ptr<RequestGroup> >::const_iterator i =
result.begin(), eoi = result.end(); i != eoi; ++i) {
(*gids).push_back((*i)->getGID());
}
@@ -346,10 +346,10 @@ int addTorrent(Session* session,
int position)
{
#ifdef ENABLE_BITTORRENT
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
- SharedHandle<Option> requestOption(new Option(*e->getOption()));
- std::vector<SharedHandle<RequestGroup> > result;
+ std::shared_ptr<Option> requestOption(new Option(*e->getOption()));
+ std::vector<std::shared_ptr<RequestGroup> > result;
try {
apiGatherRequestOption(requestOption.get(), options,
OptionParser::getInstance());
@@ -384,9 +384,9 @@ int addTorrent(Session* session,
int removeDownload(Session* session, A2Gid gid, bool force)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(group) {
if(group->getState() == RequestGroup::STATE_ACTIVE) {
if(force) {
@@ -410,9 +410,9 @@ int removeDownload(Session* session, A2Gid gid, bool force)
int pauseDownload(Session* session, A2Gid gid, bool force)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(group) {
bool reserved = group->getState() == RequestGroup::STATE_WAITING;
if(pauseRequestGroup(group, reserved, force)) {
@@ -425,9 +425,9 @@ int pauseDownload(Session* session, A2Gid gid, bool force)
int unpauseDownload(Session* session, A2Gid gid)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(!group ||
group->getState() != RequestGroup::STATE_WAITING ||
!group->isPauseRequested()) {
@@ -441,7 +441,7 @@ int unpauseDownload(Session* session, A2Gid gid)
int changePosition(Session* session, A2Gid gid, int pos, OffsetMode how)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
try {
return e->getRequestGroupMan()->changeReservedGroupPosition(gid, pos, how);
@@ -453,9 +453,9 @@ int changePosition(Session* session, A2Gid gid, int pos, OffsetMode how)
int changeOption(Session* session, A2Gid gid, const KeyVals& options)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
- SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
+ std::shared_ptr<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
if(group) {
Option option;
try {
@@ -479,7 +479,7 @@ int changeOption(Session* session, A2Gid gid, const KeyVals& options)
const std::string& getGlobalOption(Session* session, const std::string& name)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
const Pref* pref = option::k2p(name);
if(OptionParser::getInstance()->find(pref)) {
@@ -491,9 +491,9 @@ const std::string& getGlobalOption(Session* session, const std::string& name)
KeyVals getGlobalOptions(Session* session)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
- const SharedHandle<OptionParser>& optionParser = OptionParser::getInstance();
+ const std::shared_ptr<OptionParser>& optionParser = OptionParser::getInstance();
const Option* option = e->getOption();
KeyVals options;
for(size_t i = 1, len = option::countOption(); i < len; ++i) {
@@ -507,7 +507,7 @@ KeyVals getGlobalOptions(Session* session)
int changeGlobalOption(Session* session, const KeyVals& options)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
Option option;
try {
@@ -523,9 +523,9 @@ int changeGlobalOption(Session* session, const KeyVals& options)
GlobalStat getGlobalStat(Session* session)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
- const SharedHandle<RequestGroupMan>& rgman = e->getRequestGroupMan();
+ const std::shared_ptr<RequestGroupMan>& rgman = e->getRequestGroupMan();
TransferStat ts = rgman->calculateStat();
GlobalStat res;
res.downloadSpeed = ts.downloadSpeed;
@@ -538,7 +538,7 @@ GlobalStat getGlobalStat(Session* session)
std::vector<A2Gid> getActiveDownload(Session* session)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
const RequestGroupList& groups = e->getRequestGroupMan()->getRequestGroups();
std::vector<A2Gid> res;
@@ -568,7 +568,7 @@ void createUriEntry
namespace {
template<typename OutputIterator>
void createUriEntry
-(OutputIterator out, const SharedHandle<FileEntry>& file)
+(OutputIterator out, const std::shared_ptr<FileEntry>& file)
{
createUriEntry(out,
file->getSpentUris().begin(),
@@ -583,7 +583,7 @@ void createUriEntry
namespace {
FileData createFileData
-(const SharedHandle<FileEntry>& fe, int index, const BitfieldMan* bf)
+(const std::shared_ptr<FileEntry>& fe, int index, const BitfieldMan* bf)
{
FileData file;
file.index = index;
@@ -634,7 +634,7 @@ void createFileEntry
InputIterator first, InputIterator last,
int64_t totalLength,
int32_t pieceLength,
- const SharedHandle<PieceStorage>& ps)
+ const std::shared_ptr<PieceStorage>& ps)
{
BitfieldMan bf(pieceLength, totalLength);
if(ps) {
@@ -648,8 +648,8 @@ namespace {
template<typename OutputIterator>
void pushRequestOption
(OutputIterator out,
- const SharedHandle<Option>& option,
- const SharedHandle<OptionParser>& oparser)
+ const std::shared_ptr<Option>& option,
+ const std::shared_ptr<OptionParser>& oparser)
{
for(size_t i = 1, len = option::countOption(); i < len; ++i) {
const Pref* pref = option::i2p(i);
@@ -662,7 +662,7 @@ void pushRequestOption
} // namespace
namespace {
-const std::string& getRequestOption(const SharedHandle<Option>& option,
+const std::string& getRequestOption(const std::shared_ptr<Option>& option,
const std::string& name)
{
const Pref* pref = option::k2p(name);
@@ -675,7 +675,7 @@ const std::string& getRequestOption(const SharedHandle<Option>& option,
} // namespace
namespace {
-KeyVals getRequestOptions(const SharedHandle<Option>& option)
+KeyVals getRequestOptions(const std::shared_ptr<Option>& option)
{
KeyVals res;
pushRequestOption(std::back_inserter(res), option,
@@ -686,7 +686,7 @@ KeyVals getRequestOptions(const SharedHandle<Option>& option)
namespace {
struct RequestGroupDH : public DownloadHandle {
- RequestGroupDH(const SharedHandle<RequestGroup>& group)
+ RequestGroupDH(const std::shared_ptr<RequestGroup>& group)
: group(group),
ts(group->calculateStat())
{}
@@ -717,7 +717,7 @@ struct RequestGroupDH : public DownloadHandle {
}
virtual std::string getBitfield()
{
- const SharedHandle<PieceStorage>& ps = group->getPieceStorage();
+ const std::shared_ptr<PieceStorage>& ps = group->getPieceStorage();
if(ps) {
return std::string(reinterpret_cast<const char*>(ps->getBitfield()),
ps->getBitfieldLength());
@@ -737,7 +737,7 @@ struct RequestGroupDH : public DownloadHandle {
{
#ifdef ENABLE_BITTORRENT
if(group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
- SharedHandle<TorrentAttribute> torrentAttrs =
+ std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(group->getDownloadContext());
return torrentAttrs->infoHash;
}
@@ -746,7 +746,7 @@ struct RequestGroupDH : public DownloadHandle {
}
virtual size_t getPieceLength()
{
- const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
+ const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
return dctx->getPieceLength();
}
virtual int getNumPieces()
@@ -776,7 +776,7 @@ struct RequestGroupDH : public DownloadHandle {
virtual std::vector<FileData> getFiles()
{
std::vector<FileData> res;
- const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
+ const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
createFileEntry(std::back_inserter(res),
dctx->getFileEntries().begin(),
dctx->getFileEntries().end(),
@@ -786,14 +786,14 @@ struct RequestGroupDH : public DownloadHandle {
}
virtual int getNumFiles()
{
- const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
+ const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
return dctx->getFileEntries().size();
}
virtual FileData getFile(int index)
{
- const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
+ const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
BitfieldMan bf(dctx->getPieceLength(), dctx->getTotalLength());
- const SharedHandle<PieceStorage>& ps = group->getPieceStorage();
+ const std::shared_ptr<PieceStorage>& ps = group->getPieceStorage();
if(ps) {
bf.setBitfield(ps->getBitfield(), ps->getBitfieldLength());
}
@@ -804,7 +804,7 @@ struct RequestGroupDH : public DownloadHandle {
BtMetaInfoData res;
#ifdef ENABLE_BITTORRENT
if(group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
- SharedHandle<TorrentAttribute> torrentAttrs =
+ std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(group->getDownloadContext());
res.announceList = torrentAttrs->announceList;
res.comment = torrentAttrs->comment;
@@ -829,14 +829,14 @@ struct RequestGroupDH : public DownloadHandle {
{
return getRequestOptions(group->getOption());
}
- SharedHandle<RequestGroup> group;
+ std::shared_ptr<RequestGroup> group;
TransferStat ts;
};
} // namespace
namespace {
struct DownloadResultDH : public DownloadHandle {
- DownloadResultDH(const SharedHandle<DownloadResult>& dr)
+ DownloadResultDH(const std::shared_ptr<DownloadResult>& dr)
: dr(dr)
{}
virtual ~DownloadResultDH() {}
@@ -938,20 +938,20 @@ struct DownloadResultDH : public DownloadHandle {
{
return getRequestOptions(dr->option);
}
- SharedHandle<DownloadResult> dr;
+ std::shared_ptr<DownloadResult> dr;
};
} // namespace
DownloadHandle* getDownloadHandle(Session* session, A2Gid gid)
{
- const SharedHandle<DownloadEngine>& e =
+ const std::shared_ptr<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
- const SharedHandle<RequestGroupMan>& rgman = e->getRequestGroupMan();
- SharedHandle<RequestGroup> group = rgman->findGroup(gid);
+ const std::shared_ptr<RequestGroupMan>& rgman = e->getRequestGroupMan();
+ std::shared_ptr<RequestGroup> group = rgman->findGroup(gid);
if(group) {
return new RequestGroupDH(group);
} else {
- SharedHandle<DownloadResult> ds = rgman->findDownloadResult(gid);
+ std::shared_ptr<DownloadResult> ds = rgman->findDownloadResult(gid);
if(ds) {
return new DownloadResultDH(ds);
}
diff --git a/src/aria2api.h b/src/aria2api.h
index 29fe529e..59985dca 100644
--- a/src/aria2api.h
+++ b/src/aria2api.h
@@ -37,8 +37,9 @@
#include "common.h"
+#include <memory>
+
#include <aria2/aria2.h>
-#include "SharedHandle.h"
namespace aria2 {
@@ -47,7 +48,7 @@ struct Context;
struct Session {
Session(const KeyVals& options);
~Session();
- SharedHandle<Context> context;
+ std::shared_ptr<Context> context;
};
} // namespace aria2
diff --git a/src/bencode2.cc b/src/bencode2.cc
index 2e5b2e6a..00bb2a78 100644
--- a/src/bencode2.cc
+++ b/src/bencode2.cc
@@ -47,25 +47,25 @@ namespace aria2 {
namespace bencode2 {
-SharedHandle<ValueBase> decode(const unsigned char* data, size_t len)
+std::shared_ptr<ValueBase> decode(const unsigned char* data, size_t len)
{
size_t end;
return decode(data, len, end);
}
-SharedHandle<ValueBase> decode(const std::string& data)
+std::shared_ptr<ValueBase> decode(const std::string& data)
{
size_t end;
return decode(reinterpret_cast<const unsigned char*>(data.c_str()),
data.size(), end);
}
-SharedHandle<ValueBase> decode(const unsigned char* data, size_t len,
+std::shared_ptr<ValueBase> decode(const unsigned char* data, size_t len,
size_t& end)
{
ssize_t error;
bittorrent::ValueBaseBencodeParser parser;
- SharedHandle<ValueBase> res =
+ std::shared_ptr<ValueBase> res =
parser.parseFinal(reinterpret_cast<const char*>(data), len, error);
if(error < 0) {
throw DL_ABORT_EX2(fmt("Bencode decoding failed: error=%d",
@@ -130,7 +130,7 @@ std::string encode(const ValueBase* vlb)
return visitor.getResult();
}
-std::string encode(const SharedHandle<ValueBase>& vlb)
+std::string encode(const std::shared_ptr<ValueBase>& vlb)
{
return encode(vlb.get());
}
diff --git a/src/bencode2.h b/src/bencode2.h
index 7da4c2fd..e3896a3e 100644
--- a/src/bencode2.h
+++ b/src/bencode2.h
@@ -46,20 +46,20 @@ namespace aria2 {
namespace bencode2 {
// Decode the data whose length is len.
-SharedHandle<ValueBase> decode(const unsigned char* data, size_t len);
+std::shared_ptr<ValueBase> decode(const unsigned char* data, size_t len);
-SharedHandle<ValueBase> decode(const std::string& data);
+std::shared_ptr<ValueBase> decode(const std::string& data);
// Decode the data whose length is len. After decode is done
// successfully, return the bencoded string length in end.
-SharedHandle<ValueBase> decode(const unsigned char* data, size_t len,
+std::shared_ptr<ValueBase> decode(const unsigned char* data, size_t len,
size_t& end);
-SharedHandle<ValueBase> decodeFromFile(const std::string& filename);
+std::shared_ptr<ValueBase> decodeFromFile(const std::string& filename);
std::string encode(const ValueBase* vlb);
-std::string encode(const SharedHandle<ValueBase>& vlb);
+std::string encode(const std::shared_ptr<ValueBase>& vlb);
} // namespace bencode2
diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc
index 7b85f64d..4850ea56 100644
--- a/src/bittorrent_helper.cc
+++ b/src/bittorrent_helper.cc
@@ -112,7 +112,7 @@ const std::string MULTI("multi");
const std::string SINGLE("single");
namespace {
-void extractPieceHash(const SharedHandle<DownloadContext>& ctx,
+void extractPieceHash(const std::shared_ptr<DownloadContext>& ctx,
const std::string& hashData,
size_t hashLength,
size_t numPieces)
@@ -129,17 +129,17 @@ void extractPieceHash(const SharedHandle<DownloadContext>& ctx,
namespace {
void extractUrlList
-(const SharedHandle<TorrentAttribute>& torrent, std::vector<std::string>& uris,
+(const std::shared_ptr<TorrentAttribute>& torrent, std::vector<std::string>& uris,
const ValueBase* v)
{
class UrlListVisitor:public ValueBaseVisitor {
private:
std::vector<std::string>& uris_;
- const SharedHandle<TorrentAttribute>& torrent_;
+ const std::shared_ptr<TorrentAttribute>& torrent_;
public:
UrlListVisitor
(std::vector<std::string>& uris,
- const SharedHandle<TorrentAttribute>& torrent):
+ const std::shared_ptr<TorrentAttribute>& torrent):
uris_(uris), torrent_(torrent) {}
virtual void visit(const String& v)
@@ -194,10 +194,10 @@ OutputIterator createUri
namespace {
void extractFileEntries
-(const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<TorrentAttribute>& torrent,
+(const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<TorrentAttribute>& torrent,
const Dict* infoDict,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<Option>& option,
const std::string& defaultName,
const std::string& overrideName,
const std::vector<std::string>& urlList)
@@ -228,7 +228,7 @@ void extractFileEntries
}
torrent->name = utf8Name;
int maxConn = option->getAsInt(PREF_MAX_CONNECTION_PER_SERVER);
- std::vector<SharedHandle<FileEntry> > fileEntries;
+ std::vector<std::shared_ptr<FileEntry> > fileEntries;
const List* filesList = downcast<List>(infoDict->get(C_FILES));
if(filesList) {
fileEntries.reserve(filesList->size());
@@ -292,7 +292,7 @@ void extractFileEntries
(util::percentEncode)));
std::vector<std::string> uris;
createUri(urlList.begin(), urlList.end(),std::back_inserter(uris),pePath);
- SharedHandle<FileEntry> fileEntry
+ std::shared_ptr<FileEntry> fileEntry
(new FileEntry(util::applyDir(option->get(PREF_DIR),
util::escapePath(utf8Path)),
fileLengthData->i(), offset, uris));
@@ -324,7 +324,7 @@ void extractFileEntries
uris.push_back(*i);
}
}
- SharedHandle<FileEntry> fileEntry
+ std::shared_ptr<FileEntry> fileEntry
(new FileEntry(util::applyDir(option->get(PREF_DIR),
util::escapePath(utf8Name)),
totalLength, 0, uris));
@@ -342,7 +342,7 @@ void extractFileEntries
namespace {
void extractAnnounce
-(const SharedHandle<TorrentAttribute>& torrent, const Dict* rootDict)
+(const std::shared_ptr<TorrentAttribute>& torrent, const Dict* rootDict)
{
const List* announceList = downcast<List>(rootDict->get(C_ANNOUNCE_LIST));
if(announceList) {
@@ -377,7 +377,7 @@ void extractAnnounce
namespace {
void extractNodes
-(const SharedHandle<TorrentAttribute>& torrent, const ValueBase* nodesListSrc)
+(const std::shared_ptr<TorrentAttribute>& torrent, const ValueBase* nodesListSrc)
{
const List* nodesList = downcast<List>(nodesListSrc);
if(nodesList) {
@@ -408,9 +408,9 @@ void extractNodes
namespace {
void processRootDictionary
-(const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<ValueBase>& root,
- const SharedHandle<Option>& option,
+(const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<ValueBase>& root,
+ const std::shared_ptr<Option>& option,
const std::string& defaultName,
const std::string& overrideName,
const std::vector<std::string>& uris)
@@ -425,7 +425,7 @@ void processRootDictionary
throw DL_ABORT_EX2(fmt(MSG_MISSING_BT_INFO, C_INFO.c_str()),
error_code::BITTORRENT_PARSE_ERROR);
}
- SharedHandle<TorrentAttribute> torrent(new TorrentAttribute());
+ std::shared_ptr<TorrentAttribute> torrent(new TorrentAttribute());
// retrieve infoHash
std::string encodedInfoDict = bencode2::encode(infoDict);
@@ -518,8 +518,8 @@ void processRootDictionary
} // namespace
void load(const std::string& torrentFile,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::string& overrideName)
{
ValueBaseBencodeParser parser;
@@ -532,8 +532,8 @@ void load(const std::string& torrentFile,
}
void load(const std::string& torrentFile,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& overrideName)
{
@@ -548,8 +548,8 @@ void load(const std::string& torrentFile,
void loadFromMemory(const unsigned char* content,
size_t length,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::string& defaultName,
const std::string& overrideName)
{
@@ -563,8 +563,8 @@ void loadFromMemory(const unsigned char* content,
void loadFromMemory(const unsigned char* content,
size_t length,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName)
@@ -578,8 +578,8 @@ void loadFromMemory(const unsigned char* content,
}
void loadFromMemory(const std::string& context,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::string& defaultName,
const std::string& overrideName)
{
@@ -592,8 +592,8 @@ void loadFromMemory(const std::string& context,
}
void loadFromMemory(const std::string& context,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName)
@@ -606,9 +606,9 @@ void loadFromMemory(const std::string& context,
uris);
}
-void loadFromMemory(const SharedHandle<ValueBase>& torrent,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+void loadFromMemory(const std::shared_ptr<ValueBase>& torrent,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName)
@@ -621,21 +621,22 @@ void loadFromMemory(const SharedHandle<ValueBase>& torrent,
uris);
}
-SharedHandle<TorrentAttribute> getTorrentAttrs
-(const SharedHandle<DownloadContext>& dctx)
+std::shared_ptr<TorrentAttribute> getTorrentAttrs
+(const std::shared_ptr<DownloadContext>& dctx)
{
- return static_pointer_cast<TorrentAttribute>(dctx->getAttribute(CTX_ATTR_BT));
+ return std::static_pointer_cast<TorrentAttribute>
+ (dctx->getAttribute(CTX_ATTR_BT));
}
const unsigned char*
-getInfoHash(const SharedHandle<DownloadContext>& dctx)
+getInfoHash(const std::shared_ptr<DownloadContext>& dctx)
{
return reinterpret_cast<const unsigned char*>
(getTorrentAttrs(dctx)->infoHash.data());
}
std::string
-getInfoHashString(const SharedHandle<DownloadContext>& dctx)
+getInfoHashString(const std::shared_ptr<DownloadContext>& dctx)
{
return util::toHex(getTorrentAttrs(dctx)->infoHash);
}
@@ -662,7 +663,7 @@ void computeFastSet
}
memcpy(tx+4, infoHash, 20);
unsigned char x[20];
- SharedHandle<MessageDigest> sha1 = MessageDigest::sha1();
+ std::shared_ptr<MessageDigest> sha1 = MessageDigest::sha1();
message_digest::digest(x, sizeof(x), sha1, tx, 24);
while(fastSet.size() < fastSetSize) {
for(size_t i = 0; i < 5 && fastSet.size() < fastSetSize; ++i) {
@@ -890,9 +891,9 @@ void assertID
}
}
-SharedHandle<TorrentAttribute> parseMagnet(const std::string& magnet)
+std::shared_ptr<TorrentAttribute> parseMagnet(const std::string& magnet)
{
- SharedHandle<Dict> r = magnet::parse(magnet);
+ std::shared_ptr<Dict> r = magnet::parse(magnet);
if(!r) {
throw DL_ABORT_EX2("Bad BitTorrent Magnet URI.",
error_code::MAGNET_PARSE_ERROR);
@@ -902,7 +903,7 @@ SharedHandle<TorrentAttribute> parseMagnet(const std::string& magnet)
throw DL_ABORT_EX2("Missing xt parameter in Magnet URI.",
error_code::MAGNET_PARSE_ERROR);
}
- SharedHandle<TorrentAttribute> attrs(new TorrentAttribute());
+ std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
std::string infoHash;
for(List::ValueType::const_iterator xtiter = xts->begin(),
eoi = xts->end(); xtiter != eoi && infoHash.empty(); ++xtiter) {
@@ -950,14 +951,14 @@ SharedHandle<TorrentAttribute> parseMagnet(const std::string& magnet)
}
void loadMagnet
-(const std::string& magnet, const SharedHandle<DownloadContext>& dctx)
+(const std::string& magnet, const std::shared_ptr<DownloadContext>& dctx)
{
- SharedHandle<TorrentAttribute> attrs = parseMagnet(magnet);
+ std::shared_ptr<TorrentAttribute> attrs = parseMagnet(magnet);
dctx->setAttribute(CTX_ATTR_BT, attrs);
}
std::string metadata2Torrent
-(const std::string& metadata, const SharedHandle<TorrentAttribute>& attrs)
+(const std::string& metadata, const std::shared_ptr<TorrentAttribute>& attrs)
{
std::string torrent = "d";
@@ -965,7 +966,7 @@ std::string metadata2Torrent
for(std::vector<std::vector<std::string> >::const_iterator tierIter =
attrs->announceList.begin(),
eoi = attrs->announceList.end(); tierIter != eoi; ++tierIter) {
- SharedHandle<List> tier = List::g();
+ std::shared_ptr<List> tier = List::g();
for(std::vector<std::string>::const_iterator uriIter = (*tierIter).begin(),
eoi2 = (*tierIter).end(); uriIter != eoi2; ++uriIter) {
tier->append(String::g(*uriIter));
@@ -984,7 +985,7 @@ std::string metadata2Torrent
return torrent;
}
-std::string torrent2Magnet(const SharedHandle<TorrentAttribute>& attrs)
+std::string torrent2Magnet(const std::shared_ptr<TorrentAttribute>& attrs)
{
std::string uri = "magnet:?";
if(!attrs->infoHash.empty()) {
@@ -1021,7 +1022,7 @@ int getCompactLength(int family)
}
void removeAnnounceUri
-(const SharedHandle<TorrentAttribute>& attrs,
+(const std::shared_ptr<TorrentAttribute>& attrs,
const std::vector<std::string>& uris)
{
if(uris.empty()) {
@@ -1049,7 +1050,7 @@ void removeAnnounceUri
}
void addAnnounceUri
-(const SharedHandle<TorrentAttribute>& attrs,
+(const std::shared_ptr<TorrentAttribute>& attrs,
const std::vector<std::string>& uris)
{
for(std::vector<std::string>::const_iterator i = uris.begin(),
@@ -1061,8 +1062,8 @@ void addAnnounceUri
}
void adjustAnnounceUri
-(const SharedHandle<TorrentAttribute>& attrs,
- const SharedHandle<Option>& option)
+(const std::shared_ptr<TorrentAttribute>& attrs,
+ const std::shared_ptr<Option>& option)
{
std::vector<std::string> excludeUris;
std::vector<std::string> addUris;
diff --git a/src/bittorrent_helper.h b/src/bittorrent_helper.h
index ba19c79f..d26d3af1 100644
--- a/src/bittorrent_helper.h
+++ b/src/bittorrent_helper.h
@@ -41,8 +41,8 @@
#include <string>
#include <vector>
#include <utility>
+#include <memory>
-#include "SharedHandle.h"
#include "TorrentAttribute.h"
#include "a2netcompat.h"
#include "Peer.h"
@@ -65,51 +65,51 @@ extern const std::string SINGLE;
extern const std::string MULTI;
void load(const std::string& torrentFile,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::string& overrideName = "");
void load(const std::string& torrentFile,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& overrideName = "");
void loadFromMemory(const unsigned char* content, size_t length,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const unsigned char* content, size_t length,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const std::string& context,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const std::string& context,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName = "");
-void loadFromMemory(const SharedHandle<ValueBase>& torrent,
- const SharedHandle<DownloadContext>& ctx,
- const SharedHandle<Option>& option,
+void loadFromMemory(const std::shared_ptr<ValueBase>& torrent,
+ const std::shared_ptr<DownloadContext>& ctx,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName = "");
// Parses BitTorrent Magnet URI and returns
-// SharedHandle<TorrentAttribute> which includes infoHash, name and
+// std::shared_ptr<TorrentAttribute> which includes infoHash, name and
// announceList. If parsing operation failed, an RecoverableException
// will be thrown. infoHash and name are string and announceList is a
// list of list of announce URI.
@@ -117,13 +117,13 @@ void loadFromMemory(const SharedHandle<ValueBase>& torrent,
// magnet:?xt=urn:btih:<info-hash>&dn=<name>&tr=<tracker-url>
// <info-hash> comes in 2 flavors: 40bytes hexadecimal ascii string,
// or 32bytes Base32 encoded string.
-SharedHandle<TorrentAttribute> parseMagnet(const std::string& magnet);
+std::shared_ptr<TorrentAttribute> parseMagnet(const std::string& magnet);
// Parses BitTorrent Magnet URI and set them in ctx as a
// bittorrent::BITTORRENT attibute. If parsing operation failed, an
// RecoverableException will be thrown.
void loadMagnet
-(const std::string& magnet, const SharedHandle<DownloadContext>& ctx);
+(const std::string& magnet, const std::shared_ptr<DownloadContext>& ctx);
// Generates Peer ID. BitTorrent specification says Peer ID is 20-byte
// length. This function uses peerIdPrefix as a Peer ID and it is
@@ -149,16 +149,16 @@ void computeFastSet
(std::vector<size_t>& fastSet, const std::string& ipaddr,
size_t numPieces, const unsigned char* infoHash, size_t fastSetSize);
-SharedHandle<TorrentAttribute> getTorrentAttrs
-(const SharedHandle<DownloadContext>& dctx);
+std::shared_ptr<TorrentAttribute> getTorrentAttrs
+(const std::shared_ptr<DownloadContext>& dctx);
// Returns the value associated with INFO_HASH key in BITTORRENT
// attribute.
const unsigned char*
-getInfoHash(const SharedHandle<DownloadContext>& downloadContext);
+getInfoHash(const std::shared_ptr<DownloadContext>& downloadContext);
std::string
-getInfoHashString(const SharedHandle<DownloadContext>& downloadContext);
+getInfoHashString(const std::shared_ptr<DownloadContext>& downloadContext);
// Returns 8bytes unsigned integer located at offset pos. The integer
// in msg is network byte order. This function converts it into host
@@ -237,21 +237,21 @@ void assertID
// Converts attrs into torrent data. This function does not guarantee
// the returned string is valid torrent data.
std::string metadata2Torrent
-(const std::string& metadata, const SharedHandle<TorrentAttribute>& attrs);
+(const std::string& metadata, const std::shared_ptr<TorrentAttribute>& attrs);
// Constructs BitTorrent Magnet URI using attrs.
-std::string torrent2Magnet(const SharedHandle<TorrentAttribute>& attrs);
+std::string torrent2Magnet(const std::shared_ptr<TorrentAttribute>& attrs);
// Removes announce URI in uris from attrs. If uris contains '*', all
// announce URIs are removed.
void removeAnnounceUri
-(const SharedHandle<TorrentAttribute>& attrs,
+(const std::shared_ptr<TorrentAttribute>& attrs,
const std::vector<std::string>& uris);
// Adds announce URI in uris to attrs. Each URI in uris creates its
// own tier.
void addAnnounceUri
-(const SharedHandle<TorrentAttribute>& attrs,
+(const std::shared_ptr<TorrentAttribute>& attrs,
const std::vector<std::string>& uris);
// This helper function uses 2 option values: PREF_BT_TRACKER and
@@ -260,8 +260,8 @@ void addAnnounceUri
// and call removeAnnounceUri(). Then the value of PREF_BT_TRACKER is
// converted to std::vector<std::string> and call addAnnounceUri().
void adjustAnnounceUri
-(const SharedHandle<TorrentAttribute>& attrs,
- const SharedHandle<Option>& option);
+(const std::shared_ptr<TorrentAttribute>& attrs,
+ const std::shared_ptr<Option>& option);
template<typename OutputIterator>
void extractPeer(const ValueBase* peerData, int family, OutputIterator dest)
@@ -290,7 +290,7 @@ void extractPeer(const ValueBase* peerData, int family, OutputIterator dest)
if(p.first.empty()) {
continue;
}
- *dest_++ = SharedHandle<Peer>(new Peer(p.first, p.second));
+ *dest_++ = std::shared_ptr<Peer>(new Peer(p.first, p.second));
}
}
}
@@ -314,7 +314,7 @@ void extractPeer(const ValueBase* peerData, int family, OutputIterator dest)
if(!ip || !port || !(0 < port->i() && port->i() < 65536)) {
continue;
}
- *dest_ = SharedHandle<Peer>(new Peer(ip->s(), port->i()));
+ *dest_ = std::shared_ptr<Peer>(new Peer(ip->s(), port->i()));
++dest_;
}
}
@@ -329,7 +329,7 @@ void extractPeer(const ValueBase* peerData, int family, OutputIterator dest)
template<typename OutputIterator>
void extractPeer
-(const SharedHandle<ValueBase>& peerData, int family, OutputIterator dest)
+(const std::shared_ptr<ValueBase>& peerData, int family, OutputIterator dest)
{
return extractPeer(peerData.get(), family, dest);
}
@@ -341,9 +341,9 @@ const char* getModeString(BtFileMode mode);
// Writes the detailed information about torrent loaded in dctx.
template<typename Output>
-void print(Output& o, const SharedHandle<DownloadContext>& dctx)
+void print(Output& o, const std::shared_ptr<DownloadContext>& dctx)
{
- SharedHandle<TorrentAttribute> torrentAttrs = getTorrentAttrs(dctx);
+ std::shared_ptr<TorrentAttribute> torrentAttrs = getTorrentAttrs(dctx);
o.write("*** BitTorrent File Information ***\n");
if(!torrentAttrs->comment.empty()) {
o.printf("Comment: %s\n", torrentAttrs->comment.c_str());
diff --git a/src/console.h b/src/console.h
index 8b99f7f1..ac138765 100644
--- a/src/console.h
+++ b/src/console.h
@@ -36,12 +36,14 @@
#define D_CONSOLE_H
#include "common.h"
-#include "SharedHandle.h"
+
+#include <memory>
+
#include "OutputFile.h"
namespace aria2 {
-typedef SharedHandle<OutputFile> Console;
+typedef std::shared_ptr<OutputFile> Console;
namespace global {
diff --git a/src/download_helper.cc b/src/download_helper.cc
index 7ac72a98..cfed2c8a 100644
--- a/src/download_helper.cc
+++ b/src/download_helper.cc
@@ -106,9 +106,9 @@ void splitURI(std::vector<std::string>& result,
} // namespace
namespace {
-SharedHandle<GroupId> getGID(const SharedHandle<Option>& option)
+std::shared_ptr<GroupId> getGID(const std::shared_ptr<Option>& option)
{
- SharedHandle<GroupId> gid;
+ std::shared_ptr<GroupId> gid;
if(option->defined(PREF_GID)) {
a2_gid_t n;
if(GroupId::toNumericId(n, option->get(PREF_GID).c_str()) != 0) {
@@ -128,14 +128,14 @@ SharedHandle<GroupId> getGID(const SharedHandle<Option>& option)
} // namespace
namespace {
-SharedHandle<RequestGroup> createRequestGroup
-(const SharedHandle<Option>& optionTemplate,
+std::shared_ptr<RequestGroup> createRequestGroup
+(const std::shared_ptr<Option>& optionTemplate,
const std::vector<std::string>& uris,
bool useOutOption = false)
{
- SharedHandle<Option> option = util::copy(optionTemplate);
- SharedHandle<RequestGroup> rg(new RequestGroup(getGID(option), option));
- SharedHandle<DownloadContext> dctx
+ std::shared_ptr<Option> option = util::copy(optionTemplate);
+ std::shared_ptr<RequestGroup> rg(new RequestGroup(getGID(option), option));
+ std::shared_ptr<DownloadContext> dctx
(new DownloadContext
(option->getAsInt(PREF_PIECE_LENGTH),
0,
@@ -165,17 +165,17 @@ SharedHandle<RequestGroup> createRequestGroup
#if defined ENABLE_BITTORRENT || ENABLE_METALINK
namespace {
-SharedHandle<MetadataInfo> createMetadataInfo(const SharedHandle<GroupId>& gid,
+std::shared_ptr<MetadataInfo> createMetadataInfo(const std::shared_ptr<GroupId>& gid,
const std::string& uri)
{
- return SharedHandle<MetadataInfo>(new MetadataInfo(gid, uri));
+ return std::shared_ptr<MetadataInfo>(new MetadataInfo(gid, uri));
}
} // namespace
namespace {
-SharedHandle<MetadataInfo> createMetadataInfoDataOnly()
+std::shared_ptr<MetadataInfo> createMetadataInfoDataOnly()
{
- return SharedHandle<MetadataInfo>(new MetadataInfo());
+ return std::shared_ptr<MetadataInfo>(new MetadataInfo());
}
} // namespace
#endif // ENABLE_BITTORRENT || ENABLE_METALINK
@@ -183,17 +183,17 @@ SharedHandle<MetadataInfo> createMetadataInfoDataOnly()
#ifdef ENABLE_BITTORRENT
namespace {
-SharedHandle<RequestGroup>
+std::shared_ptr<RequestGroup>
createBtRequestGroup(const std::string& metaInfoUri,
- const SharedHandle<Option>& optionTemplate,
+ const std::shared_ptr<Option>& optionTemplate,
const std::vector<std::string>& auxUris,
- const SharedHandle<ValueBase>& torrent,
+ const std::shared_ptr<ValueBase>& torrent,
bool adjustAnnounceUri = true)
{
- SharedHandle<Option> option = util::copy(optionTemplate);
- SharedHandle<GroupId> gid = getGID(option);
- SharedHandle<RequestGroup> rg(new RequestGroup(gid, option));
- SharedHandle<DownloadContext> dctx(new DownloadContext());
+ std::shared_ptr<Option> option = util::copy(optionTemplate);
+ std::shared_ptr<GroupId> gid = getGID(option);
+ std::shared_ptr<RequestGroup> rg(new RequestGroup(gid, option));
+ std::shared_ptr<DownloadContext> dctx(new DownloadContext());
// may throw exception
bittorrent::loadFromMemory(torrent, dctx, option, auxUris,
metaInfoUri.empty() ? "default" : metaInfoUri);
@@ -228,15 +228,15 @@ createBtRequestGroup(const std::string& metaInfoUri,
} // namespace
namespace {
-SharedHandle<RequestGroup>
+std::shared_ptr<RequestGroup>
createBtMagnetRequestGroup
(const std::string& magnetLink,
- const SharedHandle<Option>& optionTemplate)
+ const std::shared_ptr<Option>& optionTemplate)
{
- SharedHandle<Option> option = util::copy(optionTemplate);
- SharedHandle<GroupId> gid = getGID(option);
- SharedHandle<RequestGroup> rg(new RequestGroup(gid, option));
- SharedHandle<DownloadContext> dctx
+ std::shared_ptr<Option> option = util::copy(optionTemplate);
+ std::shared_ptr<GroupId> gid = getGID(option);
+ std::shared_ptr<RequestGroup> rg(new RequestGroup(gid, option));
+ std::shared_ptr<DownloadContext> dctx
(new DownloadContext(METADATA_PIECE_SIZE, 0,
A2STR::NIL));
// We only know info hash. Total Length is unknown at this moment.
@@ -244,17 +244,17 @@ createBtMagnetRequestGroup
rg->setFileAllocationEnabled(false);
rg->setPreLocalFileCheckEnabled(false);
bittorrent::loadMagnet(magnetLink, dctx);
- SharedHandle<TorrentAttribute> torrentAttrs =
+ std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(dctx);
bittorrent::adjustAnnounceUri(torrentAttrs, option);
dctx->getFirstFileEntry()->setPath(torrentAttrs->name);
rg->setDownloadContext(dctx);
rg->clearPostDownloadHandler();
- SharedHandle<UTMetadataPostDownloadHandler> utMetadataPostHandler
+ std::shared_ptr<UTMetadataPostDownloadHandler> utMetadataPostHandler
(new UTMetadataPostDownloadHandler());
rg->addPostDownloadHandler(utMetadataPostHandler);
rg->setDiskWriterFactory
- (SharedHandle<DiskWriterFactory>(new ByteArrayDiskWriterFactory()));
+ (std::shared_ptr<DiskWriterFactory>(new ByteArrayDiskWriterFactory()));
rg->setMetadataInfo(createMetadataInfo(gid, magnetLink));
rg->markInMemoryDownload();
rg->setPauseRequested(option->getAsBool(PREF_PAUSE));
@@ -264,14 +264,14 @@ createBtMagnetRequestGroup
} // namespace
void createRequestGroupForBitTorrent
-(std::vector<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option,
+(std::vector<std::shared_ptr<RequestGroup> >& result,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& metaInfoUri,
const std::string& torrentData,
bool adjustAnnounceUri)
{
- SharedHandle<ValueBase> torrent;
+ std::shared_ptr<ValueBase> torrent;
bittorrent::ValueBaseBencodeParser parser;
if(torrentData.empty()) {
torrent = parseFile(parser, metaInfoUri);
@@ -288,11 +288,11 @@ void createRequestGroupForBitTorrent
}
void createRequestGroupForBitTorrent
-(std::vector<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option,
+(std::vector<std::shared_ptr<RequestGroup> >& result,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& metaInfoUri,
- const SharedHandle<ValueBase>& torrent,
+ const std::shared_ptr<ValueBase>& torrent,
bool adjustAnnounceUri)
{
std::vector<std::string> nargs;
@@ -303,7 +303,7 @@ void createRequestGroupForBitTorrent
}
// we ignore -Z option here
size_t numSplit = option->getAsInt(PREF_SPLIT);
- SharedHandle<RequestGroup> rg =
+ std::shared_ptr<RequestGroup> rg =
createBtRequestGroup(metaInfoUri, option, nargs,
torrent, adjustAnnounceUri);
rg->setNumConcurrentCommand(numSplit);
@@ -314,8 +314,8 @@ void createRequestGroupForBitTorrent
#ifdef ENABLE_METALINK
void createRequestGroupForMetalink
-(std::vector<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option,
+(std::vector<std::shared_ptr<RequestGroup> >& result,
+ const std::shared_ptr<Option>& option,
const std::string& metalinkData)
{
if(metalinkData.empty()) {
@@ -324,7 +324,7 @@ void createRequestGroupForMetalink
option,
option->get(PREF_METALINK_BASE_URI));
} else {
- SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
+ std::shared_ptr<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
dw->setString(metalinkData);
Metalink2RequestGroup().generate(result, dw, option,
option->get(PREF_METALINK_BASE_URI));
@@ -335,14 +335,14 @@ void createRequestGroupForMetalink
namespace {
class AccRequestGroup {
private:
- std::vector<SharedHandle<RequestGroup> >& requestGroups_;
+ std::vector<std::shared_ptr<RequestGroup> >& requestGroups_;
ProtocolDetector detector_;
- SharedHandle<Option> option_;
+ std::shared_ptr<Option> option_;
bool ignoreLocalPath_;
bool throwOnError_;
public:
- AccRequestGroup(std::vector<SharedHandle<RequestGroup> >& requestGroups,
- const SharedHandle<Option>& option,
+ AccRequestGroup(std::vector<std::shared_ptr<RequestGroup> >& requestGroups,
+ const std::shared_ptr<Option>& option,
bool ignoreLocalPath = false,
bool throwOnError = false):
requestGroups_(requestGroups), option_(option),
@@ -361,19 +361,19 @@ public:
for(size_t i = 0; i < num; ++i) {
streamURIs.push_back(uri);
}
- SharedHandle<RequestGroup> rg = createRequestGroup(option_, streamURIs);
+ std::shared_ptr<RequestGroup> rg = createRequestGroup(option_, streamURIs);
rg->setNumConcurrentCommand(numSplit);
requestGroups_.push_back(rg);
}
#ifdef ENABLE_BITTORRENT
else if(detector_.guessTorrentMagnet(uri)) {
- SharedHandle<RequestGroup> group =
+ std::shared_ptr<RequestGroup> group =
createBtMagnetRequestGroup(uri, option_);
requestGroups_.push_back(group);
} else if(!ignoreLocalPath_ && detector_.guessTorrentFile(uri)) {
try {
bittorrent::ValueBaseBencodeParser parser;
- SharedHandle<ValueBase> torrent = parseFile(parser, uri);
+ std::shared_ptr<ValueBase> torrent = parseFile(parser, uri);
if(!torrent) {
throw DL_ABORT_EX2("Bencode decoding failed",
error_code::BENCODE_PARSE_ERROR);
@@ -431,8 +431,8 @@ public:
} // namespace
void createRequestGroupForUri
-(std::vector<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option,
+(std::vector<std::shared_ptr<RequestGroup> >& result,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
bool ignoreForceSequential,
bool ignoreLocalPath,
@@ -458,7 +458,7 @@ void createRequestGroupForUri
std::vector<std::string> streamURIs;
splitURI(streamURIs, nargs.begin(), strmProtoEnd, numSplit, numIter);
try {
- SharedHandle<RequestGroup> rg =
+ std::shared_ptr<RequestGroup> rg =
createRequestGroup(option, streamURIs, true);
rg->setNumConcurrentCommand(numSplit);
result.push_back(rg);
@@ -478,7 +478,7 @@ void createRequestGroupForUri
}
bool createRequestGroupFromUriListParser
-(std::vector<SharedHandle<RequestGroup> >& result,
+(std::vector<std::shared_ptr<RequestGroup> >& result,
const Option* option,
UriListParser* uriListParser)
{
@@ -493,9 +493,9 @@ bool createRequestGroupFromUriListParser
if(uris.empty()) {
continue;
}
- SharedHandle<Option> requestOption(new Option(*option));
+ std::shared_ptr<Option> requestOption(new Option(*option));
requestOption->remove(PREF_OUT);
- const SharedHandle<OptionParser>& oparser = OptionParser::getInstance();
+ const std::shared_ptr<OptionParser>& oparser = OptionParser::getInstance();
for(size_t i = 1, len = option::countOption(); i < len; ++i) {
const Pref* pref = option::i2p(i);
const OptionHandler* h = oparser->find(pref);
@@ -512,7 +512,7 @@ bool createRequestGroupFromUriListParser
return false;
}
-SharedHandle<UriListParser> openUriListParser(const std::string& filename)
+std::shared_ptr<UriListParser> openUriListParser(const std::string& filename)
{
std::string listPath;
if(filename == "-") {
@@ -524,36 +524,36 @@ SharedHandle<UriListParser> openUriListParser(const std::string& filename)
}
listPath = filename;
}
- return SharedHandle<UriListParser>(new UriListParser(listPath));
+ return std::shared_ptr<UriListParser>(new UriListParser(listPath));
}
void createRequestGroupForUriList
-(std::vector<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option)
+(std::vector<std::shared_ptr<RequestGroup> >& result,
+ const std::shared_ptr<Option>& option)
{
- SharedHandle<UriListParser> uriListParser = openUriListParser
+ std::shared_ptr<UriListParser> uriListParser = openUriListParser
(option->get(PREF_INPUT_FILE));
while(createRequestGroupFromUriListParser(result, option.get(),
uriListParser.get()));
}
-SharedHandle<MetadataInfo>
-createMetadataInfoFromFirstFileEntry(const SharedHandle<GroupId>& gid,
- const SharedHandle<DownloadContext>& dctx)
+std::shared_ptr<MetadataInfo>
+createMetadataInfoFromFirstFileEntry(const std::shared_ptr<GroupId>& gid,
+ const std::shared_ptr<DownloadContext>& dctx)
{
if(dctx->getFileEntries().empty()) {
- return SharedHandle<MetadataInfo>();
+ return std::shared_ptr<MetadataInfo>();
} else {
std::vector<std::string> uris;
dctx->getFileEntries()[0]->getUris(uris);
if(uris.empty()) {
- return SharedHandle<MetadataInfo>();
+ return std::shared_ptr<MetadataInfo>();
}
- return SharedHandle<MetadataInfo>(new MetadataInfo(gid, uris[0]));
+ return std::shared_ptr<MetadataInfo>(new MetadataInfo(gid, uris[0]));
}
}
-void removeOneshotOption(const SharedHandle<Option>& option)
+void removeOneshotOption(const std::shared_ptr<Option>& option)
{
option->remove(PREF_PAUSE);
option->remove(PREF_GID);
diff --git a/src/download_helper.h b/src/download_helper.h
index 7a7fcd01..6289c481 100644
--- a/src/download_helper.h
+++ b/src/download_helper.h
@@ -40,8 +40,7 @@
#include <string>
#include <vector>
#include <set>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -61,8 +60,8 @@ class GroupId;
// adjusted using bittorrent::adjustAnnounceUri(). In this function,
// force-sequential is ignored.
void createRequestGroupForBitTorrent
-(std::vector<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option,
+(std::vector<std::shared_ptr<RequestGroup> >& result,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& metaInfoUri,
const std::string& torrentData = "",
@@ -73,11 +72,11 @@ void createRequestGroupForBitTorrent
// adjusted using bittorrent::adjustAnnounceUri(). In this function,
// force-sequential is ignored.
void createRequestGroupForBitTorrent
-(std::vector<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option,
+(std::vector<std::shared_ptr<RequestGroup> >& result,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
const std::string& metaInfoUri,
- const SharedHandle<ValueBase>& torrent,
+ const std::shared_ptr<ValueBase>& torrent,
bool adjustAnnounceUri = true);
#endif // ENABLE_BITTORRENT
@@ -87,8 +86,8 @@ void createRequestGroupForBitTorrent
// metalink-file option. If non-empty metalinkData is specified, it is
// used as a content of metalink file instead.
void createRequestGroupForMetalink
-(std::vector<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option,
+(std::vector<std::shared_ptr<RequestGroup> >& result,
+ const std::shared_ptr<Option>& option,
const std::string& metalinkData = "");
#endif // ENABLE_METALINK
@@ -100,7 +99,7 @@ void createRequestGroupForMetalink
// is created and uriListParser reads all input, this function returns
// false. The option is used as a option template.
bool createRequestGroupFromUriListParser
-(std::vector<SharedHandle<RequestGroup> >& result,
+(std::vector<std::shared_ptr<RequestGroup> >& result,
const Option* option,
UriListParser* uriListParser);
@@ -108,9 +107,9 @@ bool createRequestGroupFromUriListParser
// then UriListParser is configured to read from standard input.
// Otherwise, this function first checks file denoted by filename
// exists. If it does not exist, this function throws exception.
-// This function returns SharedHandle<UriListParser> object if it
+// This function returns std::shared_ptr<UriListParser> object if it
// succeeds.
-SharedHandle<UriListParser> openUriListParser(const std::string& filename);
+std::shared_ptr<UriListParser> openUriListParser(const std::string& filename);
// Create RequestGroup objects from reading file specified by input-file option.
// If the value of input-file option is "-", stdin is used as a input source.
@@ -118,8 +117,8 @@ SharedHandle<UriListParser> openUriListParser(const std::string& filename);
// The additional out and dir options can be specified after each line of URIs.
// This optional line must start with white space(s).
void createRequestGroupForUriList
-(std::vector<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option);
+(std::vector<std::shared_ptr<RequestGroup> >& result,
+ const std::shared_ptr<Option>& option);
// Create RequestGroup object using provided uris. If ignoreLocalPath
// is true, a path to torrent file abd metalink file are ignored. If
@@ -128,8 +127,8 @@ void createRequestGroupForUriList
// given. If throwOnError is false, these errors are just logged as
// error.
void createRequestGroupForUri
-(std::vector<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option,
+(std::vector<std::shared_ptr<RequestGroup> >& result,
+ const std::shared_ptr<Option>& option,
const std::vector<std::string>& uris,
bool ignoreForceSequential = false,
bool ignoreLocalPath = false,
@@ -137,20 +136,20 @@ void createRequestGroupForUri
template<typename InputIterator>
void setMetadataInfo
-(InputIterator first, InputIterator last, const SharedHandle<MetadataInfo>& mi)
+(InputIterator first, InputIterator last, const std::shared_ptr<MetadataInfo>& mi)
{
for(; first != last; ++first) {
(*first)->setMetadataInfo(mi);
}
}
-SharedHandle<MetadataInfo>
-createMetadataInfoFromFirstFileEntry(const SharedHandle<GroupId>& gid,
- const SharedHandle<DownloadContext>& dctx);
+std::shared_ptr<MetadataInfo>
+createMetadataInfoFromFirstFileEntry(const std::shared_ptr<GroupId>& gid,
+ const std::shared_ptr<DownloadContext>& dctx);
// Removes option value which is only effective at the first
// construction time.
-void removeOneshotOption(const SharedHandle<Option>& option);
+void removeOneshotOption(const std::shared_ptr<Option>& option);
} // namespace aria2
diff --git a/src/json.cc b/src/json.cc
index 78463fc3..131b9755 100644
--- a/src/json.cc
+++ b/src/json.cc
@@ -85,7 +85,7 @@ std::string jsonEscape(const std::string& s)
}
// Serializes JSON object or array.
-std::string encode(const SharedHandle<ValueBase>& json)
+std::string encode(const std::shared_ptr<ValueBase>& json)
{
std::ostringstream out;
return encode(out, json.get()).str();
diff --git a/src/json.h b/src/json.h
index 7056dfec..fa2e07ee 100644
--- a/src/json.h
+++ b/src/json.h
@@ -118,13 +118,13 @@ OutputStream& encode(OutputStream& out, const ValueBase* vlb)
}
template<typename OutputStream>
-OutputStream& encode(OutputStream& out, const SharedHandle<ValueBase>& vlb)
+OutputStream& encode(OutputStream& out, const std::shared_ptr<ValueBase>& vlb)
{
return encode(out, vlb.get());
}
// Serializes JSON object or array.
-std::string encode(const SharedHandle<ValueBase>& json);
+std::string encode(const std::shared_ptr<ValueBase>& json);
struct JsonGetParam {
std::string request;
diff --git a/src/magnet.cc b/src/magnet.cc
index fb6c0aa5..31f404e8 100644
--- a/src/magnet.cc
+++ b/src/magnet.cc
@@ -40,9 +40,9 @@ namespace aria2 {
namespace magnet {
-SharedHandle<Dict> parse(const std::string& magnet)
+std::shared_ptr<Dict> parse(const std::string& magnet)
{
- SharedHandle<Dict> dict;
+ std::shared_ptr<Dict> dict;
if(!util::startsWith(magnet, "magnet:?")) {
return dict;
}
@@ -60,7 +60,7 @@ SharedHandle<Dict> parse(const std::string& magnet)
if(l) {
l->append(String::g(value));
} else {
- SharedHandle<List> l = List::g();
+ std::shared_ptr<List> l = List::g();
l->append(String::g(value));
dict->put(name, l);
}
diff --git a/src/magnet.h b/src/magnet.h
index d2de23c7..4cb34246 100644
--- a/src/magnet.h
+++ b/src/magnet.h
@@ -43,11 +43,11 @@ namespace aria2 {
namespace magnet {
// Parses Magnet URI magnet and stores parameters in
-// SharedHandle<Dict>. Because same parameter name can appear more
-// than once, the value associated with a key is SharedHandle<List>. A
+// std::shared_ptr<Dict>. Because same parameter name can appear more
+// than once, the value associated with a key is std::shared_ptr<List>. A
// parameter value is stored in a list. If parsing operation failed,
-// SharedHandle<Dict>() is returned.
-SharedHandle<Dict> parse(const std::string& magnet);
+// std::shared_ptr<Dict>() is returned.
+std::shared_ptr<Dict> parse(const std::string& magnet);
} // namespace magnet
diff --git a/src/main.cc b/src/main.cc
index 3bb11889..f2be6c59 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -37,7 +37,6 @@
#include <unistd.h>
#include <aria2/aria2.h>
-#include "SharedHandle.h"
#include "Context.h"
#include "MultiUrlRequestInfo.h"
#include "message.h"
diff --git a/src/message_digest_helper.cc b/src/message_digest_helper.cc
index 95705fb6..2f1eb2f6 100644
--- a/src/message_digest_helper.cc
+++ b/src/message_digest_helper.cc
@@ -49,8 +49,8 @@ namespace aria2 {
namespace message_digest {
std::string digest
-(const SharedHandle<MessageDigest>& ctx,
- const SharedHandle<BinaryStream>& bs,
+(const std::shared_ptr<MessageDigest>& ctx,
+ const std::shared_ptr<BinaryStream>& bs,
int64_t offset, int64_t length)
{
size_t BUFSIZE = 4096;
@@ -78,7 +78,7 @@ std::string digest
void digest
(unsigned char* md, size_t mdLength,
- const SharedHandle<MessageDigest>& ctx, const void* data, size_t length)
+ const std::shared_ptr<MessageDigest>& ctx, const void* data, size_t length)
{
size_t reqLength = ctx->getDigestLength();
if(mdLength < reqLength) {
diff --git a/src/message_digest_helper.h b/src/message_digest_helper.h
index aa7f4a09..9a05eecf 100644
--- a/src/message_digest_helper.h
+++ b/src/message_digest_helper.h
@@ -38,8 +38,7 @@
#include "common.h"
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -53,8 +52,8 @@ namespace message_digest {
* Returns raw digest string, not hex digest
*/
std::string digest
-(const SharedHandle<MessageDigest>& ctx,
- const SharedHandle<BinaryStream>& bs,
+(const std::shared_ptr<MessageDigest>& ctx,
+ const std::shared_ptr<BinaryStream>& bs,
int64_t offset, int64_t length);
/**
@@ -63,7 +62,7 @@ std::string digest
*/
void digest
(unsigned char* md, size_t mdLength,
- const SharedHandle<MessageDigest>& ctx,
+ const std::shared_ptr<MessageDigest>& ctx,
const void* data, size_t length);
} // namespace message_digest
diff --git a/src/metalink_helper.cc b/src/metalink_helper.cc
index c6db06c2..3f70ae5f 100644
--- a/src/metalink_helper.cc
+++ b/src/metalink_helper.cc
@@ -50,8 +50,8 @@ namespace metalink {
namespace {
void query
-(std::vector<SharedHandle<MetalinkEntry> >& result,
- const SharedHandle<Metalinker>& metalinker,
+(std::vector<std::shared_ptr<MetalinkEntry> >& result,
+ const std::shared_ptr<Metalinker>& metalinker,
const Option* option)
{
metalinker->queryEntry(result,
@@ -63,40 +63,40 @@ void query
} // namespace
void parseAndQuery
-(std::vector<SharedHandle<MetalinkEntry> >& result,
+(std::vector<std::shared_ptr<MetalinkEntry> >& result,
const std::string& filename,
const Option* option,
const std::string& baseUri)
{
- SharedHandle<Metalinker> metalinker = parseFile(filename, baseUri);
+ std::shared_ptr<Metalinker> metalinker = parseFile(filename, baseUri);
query(result, metalinker, option);
}
void parseAndQuery
-(std::vector<SharedHandle<MetalinkEntry> >& result,
+(std::vector<std::shared_ptr<MetalinkEntry> >& result,
BinaryStream* bs,
const Option* option,
const std::string& baseUri)
{
- SharedHandle<Metalinker> metalinker = parseBinaryStream(bs, baseUri);
+ std::shared_ptr<Metalinker> metalinker = parseBinaryStream(bs, baseUri);
query(result, metalinker, option);
}
void groupEntryByMetaurlName
(std::vector<
- std::pair<std::string, std::vector<SharedHandle<MetalinkEntry> > > >& result,
- const std::vector<SharedHandle<MetalinkEntry> >& entries)
+ std::pair<std::string, std::vector<std::shared_ptr<MetalinkEntry> > > >& result,
+ const std::vector<std::shared_ptr<MetalinkEntry> >& entries)
{
- for(std::vector<SharedHandle<MetalinkEntry> >::const_iterator eiter =
+ for(std::vector<std::shared_ptr<MetalinkEntry> >::const_iterator eiter =
entries.begin(), eoi = entries.end(); eiter != eoi; ++eiter) {
if((*eiter)->metaurls.empty()) {
- std::pair<std::string, std::vector<SharedHandle<MetalinkEntry> > > p;
+ std::pair<std::string, std::vector<std::shared_ptr<MetalinkEntry> > > p;
p.second.push_back(*eiter);
result.push_back(p);
} else {
std::vector<
std::pair<std::string,
- std::vector<SharedHandle<MetalinkEntry> > > >::iterator i =
+ std::vector<std::shared_ptr<MetalinkEntry> > > >::iterator i =
result.begin();
if((*eiter)->metaurls[0]->name.empty() ||
!(*eiter)->sizeKnown) {
@@ -110,7 +110,7 @@ void groupEntryByMetaurlName
}
}
if(i == result.end()) {
- std::pair<std::string, std::vector<SharedHandle<MetalinkEntry> > > p;
+ std::pair<std::string, std::vector<std::shared_ptr<MetalinkEntry> > > p;
p.first = (*eiter)->metaurls[0]->url;
p.second.push_back(*eiter);
result.push_back(p);
@@ -119,7 +119,7 @@ void groupEntryByMetaurlName
}
}
-SharedHandle<Metalinker> parseFile
+std::shared_ptr<Metalinker> parseFile
(const std::string& filename,
const std::string& baseUri)
{
@@ -136,7 +136,7 @@ SharedHandle<Metalinker> parseFile
return psm.getResult();
}
-SharedHandle<Metalinker> parseBinaryStream
+std::shared_ptr<Metalinker> parseBinaryStream
(BinaryStream* bs,
const std::string& baseUri)
{
diff --git a/src/metalink_helper.h b/src/metalink_helper.h
index f07752bd..875733be 100644
--- a/src/metalink_helper.h
+++ b/src/metalink_helper.h
@@ -39,8 +39,8 @@
#include <string>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "A2STR.h"
namespace aria2 {
@@ -53,27 +53,27 @@ class Metalinker;
namespace metalink {
void parseAndQuery
-(std::vector<SharedHandle<MetalinkEntry> >& result,
+(std::vector<std::shared_ptr<MetalinkEntry> >& result,
const std::string& filename,
const Option* option,
const std::string& baseUri = A2STR::NIL);
void parseAndQuery
-(std::vector<SharedHandle<MetalinkEntry> >& result,
+(std::vector<std::shared_ptr<MetalinkEntry> >& result,
BinaryStream* bs,
const Option* option,
const std::string& baseUri = A2STR::NIL);
void groupEntryByMetaurlName
(std::vector<
- std::pair<std::string, std::vector<SharedHandle<MetalinkEntry> > > >& result,
- const std::vector<SharedHandle<MetalinkEntry> >& entries);
+ std::pair<std::string, std::vector<std::shared_ptr<MetalinkEntry> > > >& result,
+ const std::vector<std::shared_ptr<MetalinkEntry> >& entries);
-SharedHandle<Metalinker> parseFile
+std::shared_ptr<Metalinker> parseFile
(const std::string& filename,
const std::string& baseUri = A2STR::NIL);
-SharedHandle<Metalinker> parseBinaryStream
+std::shared_ptr<Metalinker> parseBinaryStream
(BinaryStream* bs,
const std::string& baseUri = A2STR::NIL);
diff --git a/src/option_processing.cc b/src/option_processing.cc
index d93dff02..dc2e3bbd 100644
--- a/src/option_processing.cc
+++ b/src/option_processing.cc
@@ -68,13 +68,13 @@ namespace aria2 {
extern void showVersion();
extern void showUsage
(const std::string& keyword,
- const SharedHandle<OptionParser>& oparser,
+ const std::shared_ptr<OptionParser>& oparser,
const Console& out);
namespace {
void overrideWithEnv
(Option& op,
- const SharedHandle<OptionParser>& optionParser,
+ const std::shared_ptr<OptionParser>& optionParser,
const Pref* pref,
const std::string& envName)
{
@@ -131,7 +131,7 @@ int levenshtein
namespace {
void showCandidates
-(const std::string& unknownOption, const SharedHandle<OptionParser>& parser)
+(const std::string& unknownOption, const std::shared_ptr<OptionParser>& parser)
{
const char* optstr = unknownOption.c_str();
for(; *optstr == '-'; ++optstr);
@@ -195,7 +195,7 @@ error_code::Value option_processing(Option& op, bool standalone,
int argc, char** argv,
const KeyVals& options)
{
- const SharedHandle<OptionParser>& oparser = OptionParser::getInstance();
+ const std::shared_ptr<OptionParser>& oparser = OptionParser::getInstance();
try {
bool noConf = false;
std::string ucfname;
@@ -231,7 +231,7 @@ error_code::Value option_processing(Option& op, bool standalone,
}
}
}
- SharedHandle<Option> confOption(new Option());
+ std::shared_ptr<Option> confOption(new Option());
oparser->parseDefaultValues(*confOption);
if(!noConf) {
std::string cfname =
diff --git a/src/rpc_helper.cc b/src/rpc_helper.cc
index 2d5b1ef0..8b372908 100644
--- a/src/rpc_helper.cc
+++ b/src/rpc_helper.cc
@@ -56,9 +56,9 @@ RpcRequest xmlParseMemory(const char* xml, size_t size)
if(xml::XmlParser(&psm).parseFinal(xml, size) < 0) {
throw DL_ABORT_EX(MSG_CANNOT_PARSE_XML_RPC_REQUEST);
}
- SharedHandle<List> params;
+ std::shared_ptr<List> params;
if(downcast<List>(psm.getCurrentFrameValue())) {
- params = static_pointer_cast<List>(psm.getCurrentFrameValue());
+ params = std::static_pointer_cast<List>(psm.getCurrentFrameValue());
} else {
params = List::g();
}
@@ -68,9 +68,9 @@ RpcRequest xmlParseMemory(const char* xml, size_t size)
RpcResponse createJsonRpcErrorResponse(int code,
const std::string& msg,
- const SharedHandle<ValueBase>& id)
+ const std::shared_ptr<ValueBase>& id)
{
- SharedHandle<Dict> params = Dict::g();
+ std::shared_ptr<Dict> params = Dict::g();
params->put("code", Integer::g(code));
params->put("message", msg);
rpc::RpcResponse res(code, params, id);
@@ -79,7 +79,7 @@ RpcResponse createJsonRpcErrorResponse(int code,
RpcResponse processJsonRpcRequest(const Dict* jsondict, DownloadEngine* e)
{
- SharedHandle<ValueBase> id = jsondict->get("id");
+ std::shared_ptr<ValueBase> id = jsondict->get("id");
if(!id) {
return createJsonRpcErrorResponse(-32600, "Invalid Request.", Null::g());
}
@@ -87,10 +87,10 @@ RpcResponse processJsonRpcRequest(const Dict* jsondict, DownloadEngine* e)
if(!methodName) {
return createJsonRpcErrorResponse(-32600, "Invalid Request.", id);
}
- SharedHandle<List> params;
- const SharedHandle<ValueBase>& tempParams = jsondict->get("params");
+ std::shared_ptr<List> params;
+ const std::shared_ptr<ValueBase>& tempParams = jsondict->get("params");
if(downcast<List>(tempParams)) {
- params = static_pointer_cast<List>(tempParams);
+ params = std::static_pointer_cast<List>(tempParams);
} else if(!tempParams) {
params = List::g();
} else {
@@ -99,7 +99,7 @@ RpcResponse processJsonRpcRequest(const Dict* jsondict, DownloadEngine* e)
}
rpc::RpcRequest req(methodName->s(), params, id);
req.jsonRpc = true;
- SharedHandle<rpc::RpcMethod> method;
+ std::shared_ptr<rpc::RpcMethod> method;
try {
method = rpc::RpcMethodFactory::create(req.methodName);
} catch(RecoverableException& e) {
diff --git a/src/rpc_helper.h b/src/rpc_helper.h
index 4747a033..50e4595e 100644
--- a/src/rpc_helper.h
+++ b/src/rpc_helper.h
@@ -39,8 +39,7 @@
#include <cstdlib>
#include <string>
-
-#include "SharedHandle.h"
+#include <memory>
namespace aria2 {
@@ -61,7 +60,7 @@ RpcRequest xmlParseMemory(const char* xml, size_t size);
// |msg| is the error message. The |id| is the id of the request .
RpcResponse createJsonRpcErrorResponse(int code,
const std::string& msg,
- const SharedHandle<ValueBase>& id);
+ const std::shared_ptr<ValueBase>& id);
// Processes JSON-RPC request |jsondict| and returns the result.
RpcResponse processJsonRpcRequest(const Dict* jsondict, DownloadEngine* e);
diff --git a/src/util.cc b/src/util.cc
index 3d2a50f6..3eac6c38 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -656,14 +656,14 @@ void parseIntSegments(SegList<int>& sgl, const std::string& src)
namespace {
void computeHeadPieces
(std::vector<size_t>& indexes,
- const std::vector<SharedHandle<FileEntry> >& fileEntries,
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries,
size_t pieceLength,
int64_t head)
{
if(head == 0) {
return;
}
- for(std::vector<SharedHandle<FileEntry> >::const_iterator fi =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator fi =
fileEntries.begin(), eoi = fileEntries.end(); fi != eoi; ++fi) {
if((*fi)->getLength() == 0) {
continue;
@@ -681,14 +681,14 @@ void computeHeadPieces
namespace {
void computeTailPieces
(std::vector<size_t>& indexes,
- const std::vector<SharedHandle<FileEntry> >& fileEntries,
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries,
size_t pieceLength,
int64_t tail)
{
if(tail == 0) {
return;
}
- for(std::vector<SharedHandle<FileEntry> >::const_iterator fi =
+ for(std::vector<std::shared_ptr<FileEntry> >::const_iterator fi =
fileEntries.begin(), eoi = fileEntries.end(); fi != eoi; ++fi) {
if((*fi)->getLength() == 0) {
continue;
@@ -706,7 +706,7 @@ void computeTailPieces
void parsePrioritizePieceRange
(std::vector<size_t>& result, const std::string& src,
- const std::vector<SharedHandle<FileEntry> >& fileEntries,
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries,
size_t pieceLength,
int64_t defaultSize)
{
@@ -1409,7 +1409,7 @@ void convertBitfield(BitfieldMan* dest, const BitfieldMan* src)
}
}
-std::string toString(const SharedHandle<BinaryStream>& binaryStream)
+std::string toString(const std::shared_ptr<BinaryStream>& binaryStream)
{
std::stringstream strm;
char data[2048];
@@ -1506,7 +1506,7 @@ std::vector<std::pair<size_t, std::string> > createIndexPaths(std::istream& i)
namespace {
void generateRandomDataRandom(unsigned char* data, size_t length)
{
- const SharedHandle<SimpleRandomizer>& rd = SimpleRandomizer::getInstance();
+ const std::shared_ptr<SimpleRandomizer>& rd = SimpleRandomizer::getInstance();
for(size_t i = 0; i < length; ++i) {
data[i] = static_cast<unsigned long>(rd->getRandomNumber(256));
}
@@ -1793,7 +1793,7 @@ void executeHook
} // namespace
void executeHookByOptName
-(const SharedHandle<RequestGroup>& group, const Option* option,
+(const std::shared_ptr<RequestGroup>& group, const Option* option,
const Pref* pref)
{
executeHookByOptName(group.get(), option, pref);
@@ -1804,11 +1804,11 @@ void executeHookByOptName
{
const std::string& cmd = option->get(pref);
if(!cmd.empty()) {
- const SharedHandle<DownloadContext> dctx = group->getDownloadContext();
+ const std::shared_ptr<DownloadContext> dctx = group->getDownloadContext();
std::string firstFilename;
size_t numFiles = 0;
if(!group->inMemoryDownload()) {
- SharedHandle<FileEntry> file = dctx->getFirstRequestedFileEntry();
+ std::shared_ptr<FileEntry> file = dctx->getFirstRequestedFileEntry();
if(file) {
firstFilename = file->getPath();
}
diff --git a/src/util.h b/src/util.h
index 4803b7a9..07a40b7d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -52,8 +52,8 @@
#include <iomanip>
#include <algorithm>
#include <vector>
+#include <memory>
-#include "SharedHandle.h"
#include "a2time.h"
#include "a2netcompat.h"
#include "a2functional.h"
@@ -296,7 +296,7 @@ void parseIntSegments(SegList<int>& sgl, const std::string& src);
// sample: head=512K,tail=512K
void parsePrioritizePieceRange
(std::vector<size_t>& result, const std::string& src,
- const std::vector<SharedHandle<FileEntry> >& fileEntries,
+ const std::vector<std::shared_ptr<FileEntry> >& fileEntries,
size_t pieceLength,
int64_t defaultSize = 1048576 /* 1MiB */);
@@ -430,7 +430,7 @@ void mkdirs(const std::string& dirpath);
void convertBitfield(BitfieldMan* dest, const BitfieldMan* src);
// binaryStream has to be opened before calling this function.
-std::string toString(const SharedHandle<BinaryStream>& binaryStream);
+std::string toString(const std::shared_ptr<BinaryStream>& binaryStream);
#ifdef HAVE_POSIX_MEMALIGN
void* allocateAlignedMemory(size_t alignment, size_t size);
@@ -784,7 +784,7 @@ bool inSameCidrBlock
// No throw
void executeHookByOptName
-(const SharedHandle<RequestGroup>& group, const Option* option,
+(const std::shared_ptr<RequestGroup>& group, const Option* option,
const Pref* pref);
// No throw
@@ -861,9 +861,9 @@ nextParam
}
template<typename T>
-SharedHandle<T> copy(const SharedHandle<T>& a)
+std::shared_ptr<T> copy(const std::shared_ptr<T>& a)
{
- return SharedHandle<T>(new T(*a.get()));
+ return std::shared_ptr<T>(new T(*a.get()));
}
// This is a bit different from cookie_helper::domainMatch(). If
diff --git a/src/version_usage.cc b/src/version_usage.cc
index a62f9261..c3ad4c89 100644
--- a/src/version_usage.cc
+++ b/src/version_usage.cc
@@ -38,7 +38,6 @@
#include <iterator>
#include <algorithm>
-#include "SharedHandle.h"
#include "a2io.h"
#include "FeatureConfig.h"
#ifdef ENABLE_MESSAGE_DIGEST
@@ -84,7 +83,7 @@ void showVersion() {
void showUsage
(const std::string& keyword,
- const SharedHandle<OptionParser>& oparser,
+ const std::shared_ptr<OptionParser>& oparser,
const Console& out) {
out->printf(_("Usage: aria2c [OPTIONS] [URI | MAGNET | TORRENT_FILE |"
" METALINK_FILE]..."));