diff options
| author | Hanjie Wu <wu@x-nagi.com> | 2023-12-16 01:13:23 -0800 |
|---|---|---|
| committer | Hanjie Wu <wu@x-nagi.com> | 2023-12-16 01:13:23 -0800 |
| commit | 58054f460e6bb04d6fd28a881c0b010df778bf5d (patch) | |
| tree | 1ee1b9297f6a891155dc7b5deeda103e400bb6c6 /src/uTPCore.h | |
| parent | 5c87f1b7b6345b895caf9f9b29a2c3c7ca94a0af (diff) | |
add uTP support for outbound connections
Diffstat (limited to 'src/uTPCore.h')
| -rw-r--r-- | src/uTPCore.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/uTPCore.h b/src/uTPCore.h new file mode 100644 index 00000000..afca8047 --- /dev/null +++ b/src/uTPCore.h @@ -0,0 +1,85 @@ +#ifndef D_UTP_CORE_H +#define D_UTP_CORE_H + +#include <memory> +#include <array> +#include <vector> + +#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<char> buf_; + size_t pos_, end_; + int errNum_; + + bool isWritable_; + bool needDrainRead_; + + bool readCheck_; + bool writeCheck_; + Command* command_; + + static utp_context* ctx_; + static utp_context* ctx6_; + static std::shared_ptr<SocketCore> sock_; + static std::shared_ptr<SocketCore> sock6_; + static Timer start_; + +public: + uTPCore(); + 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 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; + + 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 writeLog(utp_callback_arguments* arg); + static uint64 sendTo(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<SocketCore> sock_; + DownloadEngine* e_; + +public: + uTPListenCommand(cuid_t cuid, DownloadEngine* e, utp_context* ctx, + std::shared_ptr<SocketCore> sock); + + virtual ~uTPListenCommand(); + + virtual bool execute() CXX11_OVERRIDE; +}; + +} // namespace aria2 + +#endif // D_UTP_CORE_H |
