Files
SimpleRemoter/client/IOCPKCPClient.h
2025-07-20 12:08:13 +02:00

35 lines
952 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include "IOCPUDPClient.h"
#include "ikcp.h"
#include <thread>
#include <atomic>
class IOCPKCPClient : public IOCPUDPClient
{
public:
IOCPKCPClient(State& bExit, bool exit_while_disconnect = false);
virtual ~IOCPKCPClient();
virtual BOOL ConnectServer(const char* szServerIP, unsigned short uPort) override;
// 重写接收函数输入UDP数据给KCP输出KCP层解包后的数据
virtual int ReceiveData(char* buffer, int bufSize, int flags) override;
virtual bool ProcessRecvData(CBuffer* m_CompressedBuffer, char* szBuffer, int len, int flag) override;
// 重写发送函数将应用数据通过KCP发送
virtual int SendTo(const char* buf, int len, int flags) override;
private:
// KCP发送数据的回调函数负责调用UDP的sendto
static int kcpOutput(const char* buf, int len, struct IKCPCB* kcp, void* user);
// 定时调用ikcp_update的线程函数
void KCPUpdateLoop();
private:
ikcpcb* kcp_;
std::thread updateThread_;
std::atomic<bool> running_;
};