/* */ #ifndef D_ABSTRACT_COMMAND_H #define D_ABSTRACT_COMMAND_H #include "Command.h" #include #include #include #include "TimerA2.h" namespace aria2 { class FileEntry; class RequestGroup; class CheckIntegrityEntry; class DownloadContext; class SegmentMan; class PieceStorage; class Request; class DownloadEngine; class Segment; class SocketCore; class Option; class SocketRecvBuffer; #ifdef ENABLE_ASYNC_DNS class AsyncNameResolver; class AsyncNameResolverMan; #endif // ENABLE_ASYNC_DNS class AbstractCommand : public Command { private: Timer checkPoint_; time_t timeout_; RequestGroup* requestGroup_; std::shared_ptr req_; std::shared_ptr fileEntry_; DownloadEngine* e_; std::shared_ptr socket_; std::shared_ptr socketRecvBuffer_; std::vector > segments_; #ifdef ENABLE_ASYNC_DNS std::unique_ptr asyncNameResolverMan_; #endif // ENABLE_ASYNC_DNS bool checkSocketIsReadable_; bool checkSocketIsWritable_; std::shared_ptr readCheckTarget_; std::shared_ptr writeCheckTarget_; bool incNumConnection_; Timer serverStatTimer_; int32_t calculateMinSplitSize() const; void useFasterRequest(const std::shared_ptr& fasterRequest); public: RequestGroup* getRequestGroup() const { return requestGroup_; } const std::shared_ptr& getRequest() const { return req_; } void setRequest(const std::shared_ptr& request); // Resets request_. This method is more efficient than // setRequest(std::shared_ptr()); void resetRequest(); const std::shared_ptr& getFileEntry() const { return fileEntry_; } void setFileEntry(const std::shared_ptr& fileEntry); DownloadEngine* getDownloadEngine() const { return e_; } const std::shared_ptr& getSocket() const { return socket_; } std::shared_ptr& getSocket() { return socket_; } void setSocket(const std::shared_ptr& s); void createSocket(); const std::shared_ptr& getSocketRecvBuffer() const { return socketRecvBuffer_; } const std::vector >& getSegments() const { return segments_; } // Resolves hostname. The resolved addresses are stored in addrs // and first element is returned. If resolve is not finished, // return empty string. In this case, call this function with same // arguments until resolved address is returned. Exception is // thrown on error. port is used for retrieving cached addresses. std::string resolveHostname (std::vector& addrs, const std::string& hostname, uint16_t port); void tryReserved(); void setReadCheckSocket(const std::shared_ptr& socket); void setWriteCheckSocket(const std::shared_ptr& socket); void disableReadCheckSocket(); void disableWriteCheckSocket(); /** * If pred == true, calls setReadCheckSocket(socket). Otherwise, calls * disableReadCheckSocket(). */ void setReadCheckSocketIf(const std::shared_ptr& socket, bool pred); /** * If pred == true, calls setWriteCheckSocket(socket). Otherwise, calls * disableWriteCheckSocket(). */ void setWriteCheckSocketIf(const std::shared_ptr& socket, bool pred); // Swaps socket_ with socket. This disables current read and write // check. void swapSocket(std::shared_ptr& socket); time_t getTimeout() const { return timeout_; } void setTimeout(time_t timeout) { timeout_ = timeout; } void prepareForNextAction(std::unique_ptr checkEntry); // Check if socket is connected. If socket is not connected and // there are other addresses to try, command is created using // InitiateConnectionCommandFactory and it is pushed to // DownloadEngine and returns false. If no addresses left, DlRetryEx // exception is thrown. bool checkIfConnectionEstablished (const std::shared_ptr& socket, const std::string& connectedHostname, const std::string& connectedAddr, uint16_t connectedPort); /* * Returns true if proxy for the procol indicated by Request::getProtocol() * is defined. Otherwise, returns false. */ bool isProxyDefined() const; /* * Creates Request object for proxy URI and returns it. * If no valid proxy is defined, then returns std::shared_ptr(). */ std::shared_ptr createProxyRequest() const; // Returns proxy method for given protocol. Either V_GET or V_TUNNEL // is returned. For HTTPS, always returns V_TUNNEL. const std::string& resolveProxyMethod(const std::string& protocol) const; const std::shared_ptr