/* */ #include "HttpServerResponseCommand.h" #include "SocketCore.h" #include "DownloadEngine.h" #include "HttpServer.h" #include "Logger.h" #include "HttpServerCommand.h" #include "RequestGroupMan.h" #include "RecoverableException.h" #include "FileEntry.h" #include "wallclock.h" #include "util.h" #include "ServerStatMan.h" #include "FileAllocationEntry.h" #include "CheckIntegrityEntry.h" namespace aria2 { HttpServerResponseCommand::HttpServerResponseCommand (cuid_t cuid, const SharedHandle& httpServer, DownloadEngine* e, const SharedHandle& socket): Command(cuid), _e(e), _socket(socket), _httpServer(httpServer) { setStatus(Command::STATUS_ONESHOT_REALTIME); _e->addSocketForWriteCheck(_socket, this); } HttpServerResponseCommand::~HttpServerResponseCommand() { _e->deleteSocketForWriteCheck(_socket, this); } bool HttpServerResponseCommand::execute() { if(_e->getRequestGroupMan()->downloadFinished() || _e->isHaltRequested()) { return true; } try { _httpServer->sendResponse(); } catch(RecoverableException& e) { if(getLogger()->info()) { getLogger()->info ("CUID#%s - Error occurred while transmitting response body.", e, util::itos(getCuid()).c_str()); } return true; } if(_httpServer->sendBufferIsEmpty()) { if(getLogger()->info()) { getLogger()->info("CUID#%s - HttpServer: all response transmitted.", util::itos(getCuid()).c_str()); } if(_httpServer->supportsPersistentConnection()) { if(getLogger()->info()) { getLogger()->info("CUID#%s - Persist connection.", util::itos(getCuid()).c_str()); } _e->addCommand (new HttpServerCommand(getCuid(), _httpServer, _e, _socket)); } return true; } else { if(_timeoutTimer.difference(global::wallclock) >= 10) { if(getLogger()->info()) { getLogger()->info("CUID#%s - HttpServer: Timeout while trasmitting" " response.", util::itos(getCuid()).c_str()); } return true; } else { _e->addCommand(this); return false; } } } } // namespace aria2