mirror of https://github.com/aria2/aria2
2008-09-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
If establishing conneciton to a server is failed, then mark error on its ServerStat. Added the cause of error to log when error event occurred. Moved message string to message.h for translation. * src/AbstractCommand.cc * src/AbstractCommand.h * src/FtpNegotiationCommand.cc * src/HttpRequestCommand.cc * src/PeerAbstractCommand.cc * src/message.hpull/1/head
parent
8687877139
commit
c921529d68
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2008-09-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
If establishing conneciton to a server is failed, then mark error on
|
||||
its ServerStat.
|
||||
Added the cause of error to log when error event occurred.
|
||||
Moved message string to message.h for translation.
|
||||
* src/AbstractCommand.cc
|
||||
* src/AbstractCommand.h
|
||||
* src/FtpNegotiationCommand.cc
|
||||
* src/HttpRequestCommand.cc
|
||||
* src/PeerAbstractCommand.cc
|
||||
* src/message.h
|
||||
|
||||
2008-09-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Added the function to get error message from socket.
|
||||
|
|
|
@ -137,17 +137,15 @@ bool AbstractCommand::execute() {
|
|||
}
|
||||
return executeInternal();
|
||||
} else if(_errorEvent) {
|
||||
throw DlRetryEx("Network problem has occurred.");
|
||||
throw DlRetryEx
|
||||
(StringFormat(MSG_NETWORK_PROBLEM,
|
||||
socket->getSocketError().c_str()).str());
|
||||
} else {
|
||||
if(checkPoint.elapsed(timeout)) {
|
||||
// timeout triggers ServerStat error state.
|
||||
SharedHandle<ServerStat> ss =
|
||||
e->_requestGroupMan->findServerStat(req->getHost(),
|
||||
req->getProtocol());
|
||||
if(ss.isNull()) {
|
||||
ss.reset(new ServerStat(req->getHost(), req->getProtocol()));
|
||||
e->_requestGroupMan->addServerStat(ss);
|
||||
}
|
||||
e->_requestGroupMan->getOrCreateServerStat(req->getHost(),
|
||||
req->getProtocol());
|
||||
ss->setError();
|
||||
|
||||
throw DlRetryEx(EX_TIME_OUT);
|
||||
|
@ -286,12 +284,29 @@ void AbstractCommand::initAsyncNameResolver(const std::string& hostname)
|
|||
setNameResolverCheck(_asyncNameResolver);
|
||||
}
|
||||
|
||||
static bool isProxyGETRequest(const std::string& protocol, const Option* option)
|
||||
{
|
||||
return
|
||||
// For HTTP/HTTPS
|
||||
((protocol == Request::PROTO_HTTP || protocol == Request::PROTO_HTTPS) &&
|
||||
(option->getAsBool(PREF_HTTP_PROXY_ENABLED) &&
|
||||
option->get(PREF_HTTP_PROXY_METHOD) == V_GET)) ||
|
||||
// For FTP
|
||||
(protocol == Request::PROTO_FTP &&
|
||||
(option->getAsBool(PREF_HTTP_PROXY_ENABLED) &&
|
||||
option->get(PREF_FTP_VIA_HTTP_PROXY) == V_GET));
|
||||
}
|
||||
|
||||
bool AbstractCommand::asyncResolveHostname()
|
||||
{
|
||||
switch(_asyncNameResolver->getStatus()) {
|
||||
case AsyncNameResolver::STATUS_SUCCESS:
|
||||
return true;
|
||||
case AsyncNameResolver::STATUS_ERROR:
|
||||
if(!isProxyGETRequest(req->getProtocol(), e->option)) {
|
||||
e->_requestGroupMan->getOrCreateServerStat
|
||||
(req->getHost(), req->getProtocol())->setError();
|
||||
}
|
||||
throw DlAbortEx(StringFormat(MSG_NAME_RESOLUTION_FAILED, cuid,
|
||||
_asyncNameResolver->getHostname().c_str(),
|
||||
_asyncNameResolver->getError().c_str()).str());
|
||||
|
@ -339,4 +354,21 @@ void AbstractCommand::prepareForNextAction(Command* nextCommand)
|
|||
e->setNoWait(true);
|
||||
}
|
||||
|
||||
void AbstractCommand::checkIfConnectionEstablished
|
||||
(const SharedHandle<SocketCore>& socket)
|
||||
{
|
||||
if(socket->isReadable(0)) {
|
||||
std::string error = socket->getSocketError();
|
||||
if(!error.empty()) {
|
||||
// Don't set error if proxy server is used and its method is GET.
|
||||
if(!isProxyGETRequest(req->getProtocol(), e->option)) {
|
||||
e->_requestGroupMan->getOrCreateServerStat
|
||||
(req->getHost(), req->getProtocol())->setError();
|
||||
}
|
||||
throw DlRetryEx
|
||||
(StringFormat(MSG_ESTABLISHING_CONNECTION_FAILED, error.c_str()).str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -88,6 +88,7 @@ protected:
|
|||
|
||||
void prepareForNextAction(Command* nextCommand = 0);
|
||||
|
||||
void checkIfConnectionEstablished(const SharedHandle<SocketCore>& socket);
|
||||
private:
|
||||
bool checkSocketIsReadable;
|
||||
bool checkSocketIsWritable;
|
||||
|
|
|
@ -115,6 +115,7 @@ bool FtpNegotiationCommand::executeInternal() {
|
|||
}
|
||||
|
||||
bool FtpNegotiationCommand::recvGreeting() {
|
||||
checkIfConnectionEstablished(socket);
|
||||
setTimeout(e->option->getAsInt(PREF_TIMEOUT));
|
||||
//socket->setBlockingMode();
|
||||
disableWriteCheckSocket();
|
||||
|
|
|
@ -100,6 +100,7 @@ createHttpRequest(const SharedHandle<Request>& req,
|
|||
bool HttpRequestCommand::executeInternal() {
|
||||
//socket->setBlockingMode();
|
||||
if(_httpConnection->sendBufferIsEmpty()) {
|
||||
checkIfConnectionEstablished(socket);
|
||||
if(req->getProtocol() == Request::PROTO_HTTPS) {
|
||||
socket->initiateSecureConnection();
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "message.h"
|
||||
#include "prefs.h"
|
||||
#include "DownloadFailureException.h"
|
||||
#include "StringFormat.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -84,7 +85,9 @@ bool PeerAbstractCommand::execute()
|
|||
_hupEvent) {
|
||||
checkPoint.reset();
|
||||
} else if(_errorEvent) {
|
||||
throw DlAbortEx("Network problem has occurred.");
|
||||
throw DlAbortEx
|
||||
(StringFormat(MSG_NETWORK_PROBLEM,
|
||||
socket->getSocketError().c_str()).str());
|
||||
}
|
||||
if(checkPoint.elapsed(timeout)) {
|
||||
throw DlAbortEx(EX_TIME_OUT);
|
||||
|
|
|
@ -154,6 +154,9 @@
|
|||
#define MSG_SERVER_STAT_SAVED _("ServerStat file %s saved successfully.")
|
||||
#define MSG_WRITING_SERVER_STAT_FILE_FAILED _("Failed to write ServerStat to"\
|
||||
" %s.")
|
||||
#define MSG_ESTABLISHING_CONNECTION_FAILED \
|
||||
_("Failed to establish connection, cause: %s")
|
||||
#define MSG_NETWORK_PROBLEM _("Network problem has occurred. cause:%s")
|
||||
|
||||
#define EX_TIME_OUT _("Timeout.")
|
||||
#define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.")
|
||||
|
|
Loading…
Reference in New Issue