/* */ #ifndef _D_ABSTRACT_COMMAND_H_ #define _D_ABSTRACT_COMMAND_H_ #include "Command.h" #include "SharedHandle.h" #include "TimeA2.h" #include "FileEntry.h" #include "RequestGroup.h" namespace aria2 { class Request; class DownloadEngine; class Segment; class Exception; class SocketCore; class Option; #ifdef ENABLE_ASYNC_DNS class AsyncNameResolver; #endif // ENABLE_ASYNC_DNS class AbstractCommand : public Command { private: Time checkPoint; time_t timeout; protected: RequestGroup* _requestGroup; SharedHandle req; SharedHandle _fileEntry; DownloadEngine* e; SharedHandle socket; std::deque > _segments; #ifdef ENABLE_ASYNC_DNS SharedHandle _asyncNameResolver; bool isAsyncNameResolverInitialized() const; void initAsyncNameResolver(const std::string& hostname); bool asyncResolveHostname(); const std::deque& getResolvedAddresses(); #endif // ENABLE_ASYNC_DNS void tryReserved(); virtual bool prepareForRetry(time_t wait); virtual void onAbort(); virtual bool executeInternal() = 0; void setReadCheckSocket(const SharedHandle& socket); void setWriteCheckSocket(const SharedHandle& socket); void disableReadCheckSocket(); void disableWriteCheckSocket(); /** * If pred == true, calls setReadCheckSocket(socket). Otherwise, calls * disableReadCheckSocket(). */ void setReadCheckSocketIf(const SharedHandle& socket, bool pred); /** * If pred == true, calls setWriteCheckSocket(socket). Otherwise, calls * disableWriteCheckSocket(). */ void setWriteCheckSocketIf(const SharedHandle& socket, bool pred); void setTimeout(time_t timeout) { this->timeout = timeout; } void prepareForNextAction(Command* nextCommand = 0); // 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 SharedHandle& 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 SharedHandle(). */ SharedHandle 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 SharedHandle