/* */ #ifndef D_PEER_ABSTRACT_COMMAND_H #define D_PEER_ABSTRACT_COMMAND_H #include "Command.h" #include "SharedHandle.h" #include "TimerA2.h" namespace aria2 { class DownloadEngine; class Exception; class Peer; class SocketCore; class PeerAbstractCommand : public Command { private: Timer checkPoint_; time_t timeout_; DownloadEngine* e_; SharedHandle socket_; SharedHandle peer_; bool checkSocketIsReadable_; bool checkSocketIsWritable_; SharedHandle readCheckTarget_; SharedHandle writeCheckTarget_; bool noCheck_; protected: DownloadEngine* getDownloadEngine() const { return e_; } const SharedHandle& getSocket() const { return socket_; } void createSocket(); const SharedHandle& getPeer() const { return peer_; } void setTimeout(time_t timeout) { timeout_ = timeout; } virtual bool prepareForNextPeer(time_t wait); virtual void onAbort() {}; // This function is called when DownloadFailureException is caught right after // the invocation of onAbort(). virtual void onFailure(const Exception& err) {}; virtual bool exitBeforeExecute() = 0; virtual bool executeInternal() = 0; void setReadCheckSocket(const SharedHandle& socket); void setWriteCheckSocket(const SharedHandle& socket); void disableReadCheckSocket(); void disableWriteCheckSocket(); void setNoCheck(bool check); void updateKeepAlive(); public: PeerAbstractCommand(cuid_t cuid, const SharedHandle& peer, DownloadEngine* e, const SharedHandle& s = SharedHandle()); virtual ~PeerAbstractCommand(); virtual bool execute(); }; } // namespace aria2 #endif // D_PEER_ABSTRACT_COMMAND_H