/* */ #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