diff --git a/client/IOCPClient.cpp b/client/IOCPClient.cpp index 30459c6..9441798 100644 --- a/client/IOCPClient.cpp +++ b/client/IOCPClient.cpp @@ -373,6 +373,7 @@ bool IOCPClient::ProcessRecvData(CBuffer *m_CompressedBuffer, char *szBuffer, in int iReceivedLength = ReceiveData(szBuffer, len, flag); if (iReceivedLength <= 0) { int a = WSAGetLastError(); + Mprintf("[recv] return %d, GetLastError= %d. \n", iReceivedLength, a); Disconnect(); //½ÓÊÕ´íÎó´¦Àí m_CompressedBuffer->ClearBuffer(); if (m_exit_while_disconnect) diff --git a/client/ScreenManager.cpp b/client/ScreenManager.cpp index c4ac9a4..321fc56 100644 --- a/client/ScreenManager.cpp +++ b/client/ScreenManager.cpp @@ -262,7 +262,7 @@ VOID CScreenManager::SendBitMapInfo() //ÕâÀォbmpλͼ½á¹¹·¢ËͳöÈ¥ memcpy(szBuffer + 1, m_ScreenSpyObject->GetBIData(), ulLength - 1); HttpMask mask(DEFAULT_HOST, m_ClientObject->GetClientIPHeader()); - m_ClientObject->Send2Server((char*)szBuffer, ulLength, &mask); + m_ClientObject->Send2Server((char*)szBuffer, ulLength, 0); VirtualFree(szBuffer, 0, MEM_RELEASE); } diff --git a/common/locker.h b/common/locker.h index 3caffcb..79f6515 100644 --- a/common/locker.h +++ b/common/locker.h @@ -87,6 +87,23 @@ public: } }; +class CAutoCLock +{ +private: + CLock& m_cs; + +public: + CAutoCLock(CLock& cs) : m_cs(cs) + { + m_cs.Lock(); + } + + ~CAutoCLock() + { + m_cs.Unlock(); + } +}; + // 智能计时器,计算函数的耗时 class auto_tick { diff --git a/server/2015Remote/IOCPServer.cpp b/server/2015Remote/IOCPServer.cpp index d7e6891..aea115a 100644 --- a/server/2015Remote/IOCPServer.cpp +++ b/server/2015Remote/IOCPServer.cpp @@ -593,6 +593,7 @@ BOOL IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe BOOL IOCPServer::OnClientPostSending(CONTEXT_OBJECT* ContextObject,ULONG ulCompletedLength) { + CAutoCLock L(ContextObject->SendLock); try { DWORD ulFlags = MSG_PARTIAL; @@ -609,10 +610,12 @@ BOOL IOCPServer::OnClientPostSending(CONTEXT_OBJECT* ContextObject,ULONG ulCompl NULL, ulFlags,&OverlappedPlus->m_ol, NULL); if ( iOk == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING ) { int a = GetLastError(); - Mprintf("!!! OnClientPostSending ͶµÝÏûϢʧ°Ü\n"); + Mprintf("!!! OnClientPostSending ͶµÝÏûϢʧ°Ü: %d\n", a); RemoveStaleContext(ContextObject); SAFE_DELETE(OverlappedPlus); + return FALSE; } + return TRUE; } } catch(...) { Mprintf("[ERROR] OnClientPostSending catch an error \n"); diff --git a/server/2015Remote/Server.h b/server/2015Remote/Server.h index 8394ebd..954923c 100644 --- a/server/2015Remote/Server.h +++ b/server/2015Remote/Server.h @@ -374,6 +374,7 @@ public: Server* server; // ËùÊô·þÎñ¶Ë ikcpcb* kcp = nullptr; // ÐÂÔö£¬Ö¸ÏòKCP»á»° std::string GroupName; // ·Ö×éÃû³Æ + CLock SendLock; // fix #214 std::string GetProtocol() const override { @@ -411,8 +412,10 @@ public: } BOOL Send2Client(PBYTE szBuffer, ULONG ulOriginalLength) override { - if (server) + if (server) { + CAutoCLock L(SendLock); return server->Send2Client(this, szBuffer, ulOriginalLength); + } return FALSE; } VOID SetClientInfo(const CString(&s)[ONLINELIST_MAX], const std::vector& a = {})