diff --git a/client/IOCPClient.cpp b/client/IOCPClient.cpp index 76e3b45..ba3c0bd 100644 --- a/client/IOCPClient.cpp +++ b/client/IOCPClient.cpp @@ -448,7 +448,7 @@ VOID IOCPClient::OnServerReceiving(CBuffer* m_CompressedBuffer, char* szBuffer, const int bufSize = 512; BYTE buf1[bufSize], buf2[bufSize]; PBYTE CompressedBuffer = ulCompressedLength > bufSize ? new BYTE[ulCompressedLength] : buf1; - PBYTE DeCompressedBuffer = ulCompressedLength > bufSize ? new BYTE[ulOriginalLength] : buf2; + PBYTE DeCompressedBuffer = ulOriginalLength > bufSize ? new BYTE[ulOriginalLength] : buf2; m_CompressedBuffer->ReadBuffer(CompressedBuffer, ulCompressedLength); m_Encoder->Decode(CompressedBuffer, ulCompressedLength, (LPBYTE)szPacketFlag); diff --git a/client/Manager.cpp b/client/Manager.cpp index e190ee7..95acf18 100644 --- a/client/Manager.cpp +++ b/client/Manager.cpp @@ -172,7 +172,7 @@ CManager::~CManager() } -int CManager::Send(LPBYTE lpData, UINT nSize) +BOOL CManager::Send(LPBYTE lpData, UINT nSize) { int nRet = 0; try { diff --git a/client/Manager.h b/client/Manager.h index bb23b11..807ee50 100644 --- a/client/Manager.h +++ b/client/Manager.h @@ -53,8 +53,8 @@ public: return m_ClientObject ? m_ClientObject->Reconnect(this) : FALSE; } virtual void Notify() { } - int Send(LPBYTE lpData, UINT nSize); - int SendData(LPBYTE lpData, UINT nSize) + BOOL Send(LPBYTE lpData, UINT nSize); + BOOL SendData(LPBYTE lpData, UINT nSize) { return Send(lpData, nSize); } diff --git a/server/2015Remote/IOCPKCPServer.cpp b/server/2015Remote/IOCPKCPServer.cpp index c693146..446e09d 100644 --- a/server/2015Remote/IOCPKCPServer.cpp +++ b/server/2015Remote/IOCPKCPServer.cpp @@ -155,12 +155,12 @@ void IOCPKCPServer::KCPUpdateLoop() } } -void IOCPKCPServer::Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) +BOOL IOCPKCPServer::Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) { - if (!ContextObject || !ContextObject->kcp) return; + if (!ContextObject || !ContextObject->kcp) return FALSE; ContextObject->OutCompressedBuffer.ClearBuffer(); if (!WriteContextData(ContextObject, szBuffer, ulOriginalLength)) - return; + return FALSE; { std::lock_guard lock(m_contextsMutex); @@ -169,6 +169,7 @@ void IOCPKCPServer::Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, U (int)ContextObject->OutCompressedBuffer.GetBufferLength()); ikcp_flush(ContextObject->kcp); } + return TRUE; } void IOCPKCPServer::Destroy() diff --git a/server/2015Remote/IOCPKCPServer.h b/server/2015Remote/IOCPKCPServer.h index 96d19b0..25c9416 100644 --- a/server/2015Remote/IOCPKCPServer.h +++ b/server/2015Remote/IOCPKCPServer.h @@ -50,7 +50,7 @@ public: return m_port; } virtual UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort) override; - virtual void Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) override; + virtual BOOL Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) override; virtual void Destroy() override; virtual void Disconnect(CONTEXT_OBJECT* ctx) override; diff --git a/server/2015Remote/IOCPServer.cpp b/server/2015Remote/IOCPServer.cpp index c3e83a0..441f03d 100644 --- a/server/2015Remote/IOCPServer.cpp +++ b/server/2015Remote/IOCPServer.cpp @@ -574,7 +574,7 @@ BOOL WriteContextData(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOr } } -VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength) +BOOL IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength) { if (WriteContextData(ContextObject, szBuffer, ulOriginalLength)) { OVERLAPPEDPLUS* OverlappedPlus = new OVERLAPPEDPLUS(IOWrite); @@ -584,8 +584,11 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe Mprintf("!!! OnClientPreSending ͶµÝÏûϢʧ°Ü\n"); RemoveStaleContext(ContextObject); SAFE_DELETE(OverlappedPlus); + return FALSE; } + return TRUE; } + return FALSE; } BOOL IOCPServer::OnClientPostSending(CONTEXT_OBJECT* ContextObject,ULONG ulCompletedLength) diff --git a/server/2015Remote/IOCPServer.h b/server/2015Remote/IOCPServer.h index 40d57e5..f798136 100644 --- a/server/2015Remote/IOCPServer.h +++ b/server/2015Remote/IOCPServer.h @@ -69,7 +69,7 @@ private: BOOL HandleIO(IOType PacketFlags, PCONTEXT_OBJECT ContextObject, DWORD dwTrans, ZSTD_DCtx* ctx); BOOL OnClientInitializing(PCONTEXT_OBJECT ContextObject, DWORD dwTrans); BOOL OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans, ZSTD_DCtx* ctx); - VOID OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength); + BOOL OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength); BOOL OnClientPostSending(CONTEXT_OBJECT* ContextObject, ULONG ulCompressedLength); int AddWorkThread(int n) { @@ -90,9 +90,9 @@ public: UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort); - VOID Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) + BOOL Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) override { - OnClientPreSending(ContextObject, szBuffer, ulOriginalLength); + return OnClientPreSending(ContextObject, szBuffer, ulOriginalLength); } void UpdateMaxConnection(int maxConn); diff --git a/server/2015Remote/IOCPUDPServer.cpp b/server/2015Remote/IOCPUDPServer.cpp index bf540dc..132452f 100644 --- a/server/2015Remote/IOCPUDPServer.cpp +++ b/server/2015Remote/IOCPUDPServer.cpp @@ -122,11 +122,11 @@ void IOCPUDPServer::WorkerThread() m_hThread = NULL; } -VOID IOCPUDPServer::Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) +BOOL IOCPUDPServer::Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) { ContextObject->OutCompressedBuffer.ClearBuffer(); if (!WriteContextData(ContextObject, szBuffer, ulOriginalLength)) - return; + return FALSE; WSABUF buf = { ContextObject->OutCompressedBuffer.GetBufferLength(), (CHAR*)ContextObject->OutCompressedBuffer.GetBuffer(), @@ -150,7 +150,9 @@ VOID IOCPUDPServer::Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, U if (err == SOCKET_ERROR) { DWORD err = WSAGetLastError(); Mprintf("[IOCP] Send2Client error: %d\n", err); + return FALSE; } + return TRUE; } VOID IOCPUDPServer::Destroy() diff --git a/server/2015Remote/IOCPUDPServer.h b/server/2015Remote/IOCPUDPServer.h index c65e290..1d513e2 100644 --- a/server/2015Remote/IOCPUDPServer.h +++ b/server/2015Remote/IOCPUDPServer.h @@ -27,7 +27,7 @@ public: return m_port; } UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort) override; - VOID Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) override; + BOOL Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) override; VOID Destroy() override; virtual void UpdateMaxConnection(int maxConn) override { diff --git a/server/2015Remote/Server.h b/server/2015Remote/Server.h index c6a325d..8394ebd 100644 --- a/server/2015Remote/Server.h +++ b/server/2015Remote/Server.h @@ -303,7 +303,7 @@ public: virtual UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort) = 0; - virtual void Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) = 0; + virtual BOOL Send2Client(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, ULONG ulOriginalLength) = 0; virtual void UpdateMaxConnection(int maxConn) {} @@ -317,7 +317,7 @@ class context public: // ´¿Ð麯Êý virtual VOID InitMember(SOCKET s, Server* svr)=0; - virtual void Send2Client(PBYTE szBuffer, ULONG ulOriginalLength) = 0; + virtual BOOL Send2Client(PBYTE szBuffer, ULONG ulOriginalLength) = 0; virtual CString GetClientData(int index)const = 0; virtual void GetAdditionalData(CString(&s)[RES_MAX]) const =0; virtual CString GetAdditionalData(int index) const = 0; @@ -409,10 +409,11 @@ public: { return server; } - VOID Send2Client(PBYTE szBuffer, ULONG ulOriginalLength) override + BOOL Send2Client(PBYTE szBuffer, ULONG ulOriginalLength) override { if (server) - server->Send2Client(this, szBuffer, ulOriginalLength); + return server->Send2Client(this, szBuffer, ulOriginalLength); + return FALSE; } VOID SetClientInfo(const CString(&s)[ONLINELIST_MAX], const std::vector& a = {}) {