summaryrefslogtreecommitdiff
path: root/src/uTPCore.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/uTPCore.h')
-rw-r--r--src/uTPCore.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/uTPCore.h b/src/uTPCore.h
new file mode 100644
index 00000000..f844bab7
--- /dev/null
+++ b/src/uTPCore.h
@@ -0,0 +1,88 @@
+#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* readCommand_;
+ Command* writeCommand_;
+
+ 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(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<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