summaryrefslogtreecommitdiff
path: root/src/DownloadEngine.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-09-02 17:35:50 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-09-02 17:35:50 +0900
commit2a51949132f65123dd90f2990adc885a0d4bfdde (patch)
tree6e43d7879900df3be7c884a4220ceb6185afcb71 /src/DownloadEngine.cc
parent984095579841a53a66336c9a27c87d327fb5a582 (diff)
Catch exception from Socket::getPeerInfo() when pooling connection
Socket::getPeerInfo() may fail if its TCP connection has already disconnected. In this case, we log this error. The success or failure of pooling connection should not affect the later execution of the program.
Diffstat (limited to 'src/DownloadEngine.cc')
-rw-r--r--src/DownloadEngine.cc30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc
index ba82fdee..fe751df1 100644
--- a/src/DownloadEngine.cc
+++ b/src/DownloadEngine.cc
@@ -347,6 +347,22 @@ void DownloadEngine::poolSocket
poolSocket(createSockPoolKey(ipaddr, port, A2STR::NIL,proxyhost,proxyport),e);
}
+namespace {
+bool getPeerInfo(std::pair<std::string, uint16_t>& res,
+ const SharedHandle<SocketCore>& socket)
+{
+ try {
+ socket->getPeerInfo(res);
+ return true;
+ } catch(RecoverableException& e) {
+ // socket->getPeerInfo() can fail if the socket has been
+ // disconnected.
+ A2_LOG_INFO_EX("Getting peer info failed. Pooling socket canceled.", e);
+ return false;
+ }
+}
+} // namespace
+
void DownloadEngine::poolSocket(const SharedHandle<Request>& request,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<SocketCore>& socket,
@@ -354,9 +370,10 @@ void DownloadEngine::poolSocket(const SharedHandle<Request>& request,
{
if(!proxyRequest) {
std::pair<std::string, uint16_t> peerInfo;
- socket->getPeerInfo(peerInfo);
- poolSocket(peerInfo.first, peerInfo.second,
- A2STR::NIL, 0, socket, timeout);
+ if(getPeerInfo(peerInfo, socket)) {
+ poolSocket(peerInfo.first, peerInfo.second,
+ A2STR::NIL, 0, socket, timeout);
+ }
} else {
// If proxy is defined, then pool socket with its hostname.
poolSocket(request->getHost(), request->getPort(),
@@ -375,9 +392,10 @@ void DownloadEngine::poolSocket
{
if(!proxyRequest) {
std::pair<std::string, uint16_t> peerInfo;
- socket->getPeerInfo(peerInfo);
- poolSocket(peerInfo.first, peerInfo.second, username,
- A2STR::NIL, 0, socket, options, timeout);
+ if(getPeerInfo(peerInfo, socket)) {
+ poolSocket(peerInfo.first, peerInfo.second, username,
+ A2STR::NIL, 0, socket, options, timeout);
+ }
} else {
// If proxy is defined, then pool socket with its hostname.
poolSocket(request->getHost(), request->getPort(), username,