mirror of https://github.com/aria2/aria2
2008-05-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added timeout to socket pool. The default timeout is 15 seconds, which is the same value Apache uses. * src/DownloadEngine.cc * src/DownloadEngine.hpull/1/head
parent
8fab8859b1
commit
2c54667beb
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2008-05-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Added timeout to socket pool. The default timeout is 15 seconds,
|
||||||
|
which is the same value Apache uses.
|
||||||
|
* src/DownloadEngine.cc
|
||||||
|
* src/DownloadEngine.h
|
||||||
|
|
||||||
|
2008-05-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Fixed misuse of multimap::find()
|
||||||
|
* src/HttpHeader.cc
|
||||||
|
* test/HttpHeaderTest.cc
|
||||||
|
|
||||||
2008-05-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-05-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Rewritten name resolver. Now async DNS can be disabled by --async-dns
|
Rewritten name resolver. Now async DNS can be disabled by --async-dns
|
||||||
|
|
|
@ -368,29 +368,36 @@ void DownloadEngine::addRoutineCommand(Command* command)
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadEngine::poolSocket(const std::string& ipaddr, uint16_t port,
|
void DownloadEngine::poolSocket(const std::string& ipaddr, uint16_t port,
|
||||||
const SharedHandle<SocketCore>& sock)
|
const SharedHandle<SocketCore>& sock,
|
||||||
|
time_t timeout)
|
||||||
{
|
{
|
||||||
std::string addr = ipaddr+":"+Util::uitos(port);
|
std::string addr = ipaddr+":"+Util::uitos(port);
|
||||||
logger->info("Pool socket for %s", addr.c_str());
|
logger->info("Pool socket for %s", addr.c_str());
|
||||||
std::multimap<std::string, SharedHandle<SocketCore> >::value_type newPair
|
|
||||||
(addr, sock);
|
SocketPoolEntry e(sock, timeout);
|
||||||
_socketPool.insert(newPair);
|
std::multimap<std::string, SocketPoolEntry>::value_type p(addr, e);
|
||||||
|
_socketPool.insert(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedHandle<SocketCore>
|
SharedHandle<SocketCore>
|
||||||
DownloadEngine::popPooledSocket(const std::string& ipaddr, uint16_t port)
|
DownloadEngine::popPooledSocket(const std::string& ipaddr, uint16_t port)
|
||||||
{
|
{
|
||||||
|
SharedHandle<SocketCore> s;
|
||||||
std::string addr = ipaddr+":"+Util::uitos(port);
|
std::string addr = ipaddr+":"+Util::uitos(port);
|
||||||
std::multimap<std::string, SharedHandle<SocketCore> >::iterator i =
|
|
||||||
_socketPool.find(addr);
|
std::multimap<std::string, SocketPoolEntry>::iterator first = _socketPool.find(addr);
|
||||||
if(i == _socketPool.end()) {
|
|
||||||
return SharedHandle<SocketCore>();
|
for(std::multimap<std::string, SocketPoolEntry>::iterator i = first;
|
||||||
} else {
|
i != _socketPool.end() && (*i).first == addr; ++i) {
|
||||||
logger->info("Reuse socket for %s", addr.c_str());
|
const SocketPoolEntry& e = (*i).second;
|
||||||
SharedHandle<SocketCore> s = (*i).second;
|
if(!e.isTimeout()) {
|
||||||
_socketPool.erase(i);
|
logger->info("Reuse socket for %s", addr.c_str());
|
||||||
return s;
|
s = e.getSocket();
|
||||||
|
_socketPool.erase(first, ++i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedHandle<SocketCore>
|
SharedHandle<SocketCore>
|
||||||
|
@ -407,4 +414,22 @@ DownloadEngine::popPooledSocket
|
||||||
return SharedHandle<SocketCore>();
|
return SharedHandle<SocketCore>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DownloadEngine::SocketPoolEntry::SocketPoolEntry
|
||||||
|
(const SharedHandle<SocketCore>& socket,
|
||||||
|
time_t timeout):
|
||||||
|
_socket(socket),
|
||||||
|
_timeout(timeout) {}
|
||||||
|
|
||||||
|
DownloadEngine::SocketPoolEntry::~SocketPoolEntry() {}
|
||||||
|
|
||||||
|
bool DownloadEngine::SocketPoolEntry::isTimeout() const
|
||||||
|
{
|
||||||
|
return _registeredTime.elapsed(_timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedHandle<SocketCore> DownloadEngine::SocketPoolEntry::getSocket() const
|
||||||
|
{
|
||||||
|
return _socket;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "a2netcompat.h"
|
#include "a2netcompat.h"
|
||||||
|
#include "TimeA2.h"
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
@ -107,8 +108,26 @@ private:
|
||||||
|
|
||||||
bool _haltRequested;
|
bool _haltRequested;
|
||||||
|
|
||||||
// key = IP address:port, value = Socket
|
class SocketPoolEntry {
|
||||||
std::multimap<std::string, SharedHandle<SocketCore> > _socketPool;
|
private:
|
||||||
|
SharedHandle<SocketCore> _socket;
|
||||||
|
|
||||||
|
time_t _timeout;
|
||||||
|
|
||||||
|
Time _registeredTime;
|
||||||
|
public:
|
||||||
|
SocketPoolEntry(const SharedHandle<SocketCore>& socket,
|
||||||
|
time_t timeout);
|
||||||
|
|
||||||
|
~SocketPoolEntry();
|
||||||
|
|
||||||
|
bool isTimeout() const;
|
||||||
|
|
||||||
|
SharedHandle<SocketCore> getSocket() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
// key = IP address:port, value = SocketPoolEntry
|
||||||
|
std::multimap<std::string, SocketPoolEntry> _socketPool;
|
||||||
|
|
||||||
void shortSleep() const;
|
void shortSleep() const;
|
||||||
bool addSocket(const SocketEntry& socketEntry);
|
bool addSocket(const SocketEntry& socketEntry);
|
||||||
|
@ -178,7 +197,7 @@ public:
|
||||||
void addRoutineCommand(Command* command);
|
void addRoutineCommand(Command* command);
|
||||||
|
|
||||||
void poolSocket(const std::string& ipaddr, uint16_t port,
|
void poolSocket(const std::string& ipaddr, uint16_t port,
|
||||||
const SharedHandle<SocketCore>& sock);
|
const SharedHandle<SocketCore>& sock, time_t timeout = 15);
|
||||||
|
|
||||||
SharedHandle<SocketCore> popPooledSocket(const std::string& ipaddr,
|
SharedHandle<SocketCore> popPooledSocket(const std::string& ipaddr,
|
||||||
uint16_t port);
|
uint16_t port);
|
||||||
|
|
Loading…
Reference in New Issue