diff --git a/ChangeLog b/ChangeLog index fff4b2a7..141f3b5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-05-17 Tatsuhiro Tsujikawa + + Don't add closed socket to DownloadEngine::addSocketForReadCheck() + * src/AbstractCommand.cc + * src/AbstractCommand.h + * src/ActivePeerConnectionCommand.cc + * src/FtpInitiateConnectionCommand.cc + * src/HttpInitiateConnectionCommand.cc + * src/InitiateConnectionCommandFactory.cc + * src/PeerAbstractCommand.cc + * src/PeerAbstractCommand.h + * src/PeerInitiateConnectionCommand.cc + * src/TrackerWatcherCommand.cc + 2008-05-17 Tatsuhiro Tsujikawa Sort RequestSlot in ascending order and manipulate them using diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 024e67c6..e9f16e73 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -58,8 +58,6 @@ namespace aria2 { -// TODO $$$$$$$$$$$ fix two nearly identical constructor. $$$$$$$$$$$$$$ -// Modify two constructor at the same time! AbstractCommand::AbstractCommand(int32_t cuid, const SharedHandle& req, RequestGroup* requestGroup, @@ -69,22 +67,10 @@ AbstractCommand::AbstractCommand(int32_t cuid, req(req), e(e), socket(s), checkSocketIsReadable(false), checkSocketIsWritable(false), nameResolverCheck(false) -{ - setReadCheckSocket(socket); - timeout = this->e->option->getAsInt(PREF_TIMEOUT); - _requestGroup->increaseStreamConnection(); -} - -AbstractCommand::AbstractCommand(int32_t cuid, - const SharedHandle& req, - RequestGroup* requestGroup, - DownloadEngine* e): - Command(cuid), RequestGroupAware(requestGroup), - req(req), e(e), socket(new SocketCore()), - checkSocketIsReadable(false), checkSocketIsWritable(false), - nameResolverCheck(false) -{ - setReadCheckSocket(socket); +{ + if(!socket.isNull() && socket->isOpen()) { + setReadCheckSocket(socket); + } timeout = this->e->option->getAsInt(PREF_TIMEOUT); _requestGroup->increaseStreamConnection(); } diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h index 45151ef6..ce27e3c1 100644 --- a/src/AbstractCommand.h +++ b/src/AbstractCommand.h @@ -106,10 +106,7 @@ private: public: AbstractCommand(int32_t cuid, const SharedHandle& req, RequestGroup* requestGroup, DownloadEngine* e, - const SharedHandle& s); - - AbstractCommand(int32_t cuid, const SharedHandle& req, - RequestGroup* requestGroup, DownloadEngine* e); + const SharedHandle& s = SharedHandle()); virtual ~AbstractCommand(); bool execute(); diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index 21bb9a64..a1249d91 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/src/ActivePeerConnectionCommand.cc @@ -46,6 +46,7 @@ #include "prefs.h" #include "Option.h" #include "BtConstants.h" +#include "SocketCore.h" namespace aria2 { diff --git a/src/FtpInitiateConnectionCommand.cc b/src/FtpInitiateConnectionCommand.cc index e5a94d56..e1598efa 100644 --- a/src/FtpInitiateConnectionCommand.cc +++ b/src/FtpInitiateConnectionCommand.cc @@ -67,6 +67,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand logger->info(MSG_CONNECTING_TO_SERVER, cuid, e->option->get(PREF_HTTP_PROXY_HOST).c_str(), e->option->getAsInt(PREF_HTTP_PROXY_PORT)); + socket.reset(new SocketCore()); socket->establishConnection(resolvedAddresses.front(), e->option->getAsInt(PREF_HTTP_PROXY_PORT)); @@ -86,6 +87,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(), req->getPort()); + socket.reset(new SocketCore()); socket->establishConnection(resolvedAddresses.front(), req->getPort()); command = new FtpNegotiationCommand(cuid, req, _requestGroup, e, socket); } else { diff --git a/src/HttpInitiateConnectionCommand.cc b/src/HttpInitiateConnectionCommand.cc index 76400187..84d8c6d6 100644 --- a/src/HttpInitiateConnectionCommand.cc +++ b/src/HttpInitiateConnectionCommand.cc @@ -66,6 +66,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand logger->info(MSG_CONNECTING_TO_SERVER, cuid, e->option->get(PREF_HTTP_PROXY_HOST).c_str(), e->option->getAsInt(PREF_HTTP_PROXY_PORT)); + socket.reset(new SocketCore()); socket->establishConnection(resolvedAddresses.front(), e->option->getAsInt(PREF_HTTP_PROXY_PORT)); if(useProxyTunnel()) { @@ -84,6 +85,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand if(pooledSocket.isNull()) { logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(), req->getPort()); + socket.reset(new SocketCore()); socket->establishConnection(resolvedAddresses.front(), req->getPort()); } else { socket = pooledSocket; diff --git a/src/InitiateConnectionCommandFactory.cc b/src/InitiateConnectionCommandFactory.cc index 80503780..b38cd18f 100644 --- a/src/InitiateConnectionCommandFactory.cc +++ b/src/InitiateConnectionCommandFactory.cc @@ -42,6 +42,7 @@ #include "StringFormat.h" #include "Option.h" #include "prefs.h" +#include "SocketCore.h" namespace aria2 { diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc index d8ee695f..05a2ba6a 100644 --- a/src/PeerAbstractCommand.cc +++ b/src/PeerAbstractCommand.cc @@ -52,18 +52,9 @@ PeerAbstractCommand::PeerAbstractCommand(int32_t cuid, checkSocketIsReadable(false), checkSocketIsWritable(false), uploadLimitCheck(false), uploadLimit(0), noCheck(false) { - setReadCheckSocket(socket); - timeout = e->option->getAsInt(PREF_BT_TIMEOUT); -} - -PeerAbstractCommand::PeerAbstractCommand(int32_t cuid, - const PeerHandle& peer, - DownloadEngine* e) - :Command(cuid), e(e), socket(new SocketCore()), peer(peer), - checkSocketIsReadable(false), checkSocketIsWritable(false), - uploadLimitCheck(false), uploadLimit(0), noCheck(false) -{ - setReadCheckSocket(socket); + if(!socket.isNull() && socket->isOpen()) { + setReadCheckSocket(socket); + } timeout = e->option->getAsInt(PREF_BT_TIMEOUT); } diff --git a/src/PeerAbstractCommand.h b/src/PeerAbstractCommand.h index e44e1d58..95efdb99 100644 --- a/src/PeerAbstractCommand.h +++ b/src/PeerAbstractCommand.h @@ -80,11 +80,7 @@ public: PeerAbstractCommand(int32_t cuid, const SharedHandle& peer, DownloadEngine* e, - const SharedHandle& s); - - PeerAbstractCommand(int32_t cuid, - const SharedHandle& peer, - DownloadEngine* e); + const SharedHandle& s = SharedHandle()); virtual ~PeerAbstractCommand(); diff --git a/src/PeerInitiateConnectionCommand.cc b/src/PeerInitiateConnectionCommand.cc index 239dc946..ddaf53b3 100644 --- a/src/PeerInitiateConnectionCommand.cc +++ b/src/PeerInitiateConnectionCommand.cc @@ -75,6 +75,7 @@ PeerInitiateConnectionCommand::~PeerInitiateConnectionCommand() bool PeerInitiateConnectionCommand::executeInternal() { logger->info(MSG_CONNECTING_TO_SERVER, cuid, peer->ipaddr.c_str(), peer->port); + socket.reset(new SocketCore()); socket->establishConnection(peer->ipaddr, peer->port); Command* command; if(_mseHandshakeEnabled) { diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index ba775274..302b3fdb 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -54,6 +54,7 @@ #include "DlAbortEx.h" #include "Logger.h" #include "A2STR.h" +#include "SocketCore.h" #include namespace aria2 {