/* */ #ifndef _D_DOWNLOAD_ENGINE_H_ #define _D_DOWNLOAD_ENGINE_H_ #include "common.h" #include "SharedHandle.h" #include "Command.h" #include "a2netcompat.h" #include #include namespace aria2 { class Logger; class Option; #ifdef ENABLE_ASYNC_DNS class AsyncNameResolver; #endif // ENABLE_ASYNC_DNS class RequestGroupMan; class FileAllocationMan; class StatCalc; class CheckIntegrityMan; class SocketCore; class SocketEntry { public: enum TYPE { TYPE_RD, TYPE_WR, }; SharedHandle socket; Command* command; TYPE type; public: SocketEntry(const SharedHandle& socket, Command* command, TYPE type); bool operator==(const SocketEntry& entry); }; typedef std::deque SocketEntries; #ifdef ENABLE_ASYNC_DNS class AsyncNameResolverEntry { public: SharedHandle nameResolver; Command* command; public: AsyncNameResolverEntry(const SharedHandle& nameResolver, Command* command); bool operator==(const AsyncNameResolverEntry& entry); }; typedef std::deque AsyncNameResolverEntries; #endif // ENABLE_ASYNC_DNS class DownloadEngine { private: void waitData(); SocketEntries socketEntries; #ifdef ENABLE_ASYNC_DNS AsyncNameResolverEntries nameResolverEntries; #endif // ENABLE_ASYNC_DNS fd_set rfdset; fd_set wfdset; int fdmax; Logger* logger; SharedHandle _statCalc; bool _haltRequested; // key = IP address:port, value = Socket std::multimap > _socketPool; void shortSleep() const; bool addSocket(const SocketEntry& socketEntry); bool deleteSocket(const SocketEntry& socketEntry); /** * Delegates to StatCalc */ void calculateStatistics(); void onEndOfRun(); void afterEachIteration(); private: bool _noWait; std::deque _routineCommands; public: std::deque commands; SharedHandle _requestGroupMan; SharedHandle _fileAllocationMan; SharedHandle _checkIntegrityMan; const Option* option; DownloadEngine(); virtual ~DownloadEngine(); void run(); void cleanQueue(); void updateFdSet(); bool addSocketForReadCheck(const SharedHandle& socket, Command* command); bool deleteSocketForReadCheck(const SharedHandle& socket, Command* command); bool addSocketForWriteCheck(const SharedHandle& socket, Command* command); bool deleteSocketForWriteCheck(const SharedHandle& socket, Command* command); #ifdef ENABLE_ASYNC_DNS bool addNameResolverCheck(const SharedHandle& resolver, Command* command); bool deleteNameResolverCheck(const SharedHandle& resolver, Command* command); #endif // ENABLE_ASYNC_DNS void addCommand(const Commands& commands); void fillCommand(); void setStatCalc(const SharedHandle& statCalc); bool isHaltRequested() const { return _haltRequested; } void requestHalt(); void setNoWait(bool b); void addRoutineCommand(Command* command); void poolSocket(const std::string& ipaddr, uint16_t port, const SharedHandle& sock); SharedHandle popPooledSocket(const std::string& ipaddr, uint16_t port); SharedHandle popPooledSocket(const std::deque& ipaddrs, uint16_t port); }; typedef SharedHandle DownloadEngineHandle; } // namespace aria2 #endif // _D_DOWNLOAD_ENGINE_H_