#ifndef D_UTP_CORE_H #define D_UTP_CORE_H #include #include #include #include "utp.h" #include "Command.h" #include "wallclock.h" #include "SocketCore.h" namespace aria2 { class DownloadEngine; class uTPCore : public SocketCore { private: utp_socket* s_; std::vector buf_; size_t pos_, end_; int errNum_; bool isWritable_; bool needDrainRead_; bool readCheck_; bool writeCheck_; Command* readCommand_; Command* writeCommand_; static utp_context* ctx_; static utp_context* ctx6_; static std::shared_ptr sock_; static std::shared_ptr sock6_; static Timer start_; public: uTPCore(utp_socket* s = nullptr); virtual ~uTPCore(); static void initContext(uint16_t port, DownloadEngine* e); static void destroyContext(); virtual void establishConnection(const std::string& host, uint16_t port, bool tcpNodelay = true) CXX11_OVERRIDE; virtual bool isOpen() const CXX11_OVERRIDE { return s_ != nullptr; }; virtual bool isWritable(time_t timeout) CXX11_OVERRIDE; virtual bool isReadable(time_t timeout) CXX11_OVERRIDE; virtual ssize_t writeData(const void* data, size_t len) CXX11_OVERRIDE; virtual ssize_t writeVector(a2iovec* iov, size_t iovcnt) CXX11_OVERRIDE; virtual void readData(void* data, size_t& len) CXX11_OVERRIDE; virtual void closeConnection() CXX11_OVERRIDE; virtual std::string getSocketError() const CXX11_OVERRIDE; void setRWCheck(Command* command, int is_add, int is_read); static uint64 getMilliseconds(utp_callback_arguments* arg); static uint64 getMicroseconds(utp_callback_arguments* arg); static uint64 getReadBufferSize(utp_callback_arguments* arg); static uint64 writeLogCallback(utp_callback_arguments* arg); static uint64 sendtoCallback(utp_callback_arguments* arg); static uint64 acceptCallback(utp_callback_arguments* arg); static uint64 stateChangeCallback(utp_callback_arguments* arg); static uint64 readCallback(utp_callback_arguments* arg); static uint64 errorCallback(utp_callback_arguments* arg); }; class uTPListenCommand : public Command { private: utp_context* ctx_; std::shared_ptr sock_; DownloadEngine* e_; public: uTPListenCommand(cuid_t cuid, DownloadEngine* e, utp_context* ctx, std::shared_ptr sock); virtual ~uTPListenCommand(); virtual bool execute() CXX11_OVERRIDE; }; } // namespace aria2 #endif // D_UTP_CORE_H