diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-04-01 00:12:27 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-04-01 00:12:27 +0900 |
| commit | 597e1a5c1b10aa3668f91bcae02a864dcd0c045b (patch) | |
| tree | 4437c2896b410b441013452b7385dfa303441772 /src/HttpRequestCommand.cc | |
| parent | d671d8bf3672cbefc06f3727f82b77872abe6120 (diff) | |
Implement simple Happy Eyeballs for HTTP/FTP downloads
Diffstat (limited to 'src/HttpRequestCommand.cc')
| -rw-r--r-- | src/HttpRequestCommand.cc | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index f393125f..6fc083c6 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -59,6 +59,7 @@ #include "LogFactory.h" #include "fmt.h" #include "SocketRecvBuffer.h" +#include "BackupIPv4ConnectCommand.h" namespace aria2 { @@ -79,7 +80,12 @@ HttpRequestCommand::HttpRequestCommand setWriteCheckSocket(getSocket()); } -HttpRequestCommand::~HttpRequestCommand() {} +HttpRequestCommand::~HttpRequestCommand() +{ + if(backupConnectionInfo_) { + backupConnectionInfo_->cancel = true; + } +} namespace { SharedHandle<HttpRequest> @@ -122,14 +128,52 @@ createHttpRequest(const SharedHandle<Request>& req, } } // namespace +bool HttpRequestCommand::noCheck() { + return backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty(); +} + bool HttpRequestCommand::executeInternal() { //socket->setBlockingMode(); if(httpConnection_->sendBufferIsEmpty()) { + if(backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty()) { + A2_LOG_INFO(fmt("CUID#%"PRId64" - Use backup connection address %s", + getCuid(), backupConnectionInfo_->ipaddr.c_str())); + getDownloadEngine()->markBadIPAddress + (getRequest()->getConnectedHostname(), + getRequest()->getConnectedAddr(), + getRequest()->getConnectedPort()); + + getRequest()->setConnectedAddrInfo(getRequest()->getConnectedHostname(), + backupConnectionInfo_->ipaddr, + getRequest()->getConnectedPort()); + + SharedHandle<SocketRecvBuffer> socketRecvBuffer + (new SocketRecvBuffer(backupConnectionInfo_->socket)); + SharedHandle<HttpConnection> httpConnection + (new HttpConnection(getCuid(), backupConnectionInfo_->socket, + socketRecvBuffer)); + HttpRequestCommand* c = + new HttpRequestCommand(getCuid(), getRequest(), getFileEntry(), + getRequestGroup(), + httpConnection, + getDownloadEngine(), + backupConnectionInfo_->socket); + c->setProxyRequest(proxyRequest_); + c->setStatus(STATUS_ONESHOT_REALTIME); + getDownloadEngine()->setNoWait(true); + getDownloadEngine()->addCommand(c); + backupConnectionInfo_.reset(); + return true; + } if(!checkIfConnectionEstablished (getSocket(), getRequest()->getConnectedHostname(), getRequest()->getConnectedAddr(), getRequest()->getConnectedPort())) { return true; } + if(backupConnectionInfo_) { + backupConnectionInfo_->cancel = true; + backupConnectionInfo_.reset(); + } #ifdef ENABLE_SSL if(getRequest()->getProtocol() == "https") { if(!getSocket()->tlsConnect(getRequest()->getHost())) { @@ -235,4 +279,10 @@ void HttpRequestCommand::setProxyRequest proxyRequest_ = proxyRequest; } +void HttpRequestCommand::setBackupConnectInfo +(const SharedHandle<BackupConnectInfo>& info) +{ + backupConnectionInfo_ = info; +} + } // namespace aria2 |
