diff options
author | George Hazan <ghazan@miranda.im> | 2021-09-08 17:11:01 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-09-08 17:11:01 +0300 |
commit | 77a3554616362939d78649fd257f65e464312e68 (patch) | |
tree | 6c628a79a046444b4a6b07b8a3b0acf7cc4ae47d /protocols | |
parent | 410dcf305260b51294a39a6f0825a2a548030dba (diff) |
fixes #2897 (EMLan: hangup on exit)
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/EmLanProto/src/lan.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/protocols/EmLanProto/src/lan.cpp b/protocols/EmLanProto/src/lan.cpp index deff7edd18..42787169d2 100644 --- a/protocols/EmLanProto/src/lan.cpp +++ b/protocols/EmLanProto/src/lan.cpp @@ -80,8 +80,8 @@ void CLan::StopListen() if (m_hListenThread) {
shutdown(m_income, SD_BOTH);
- WaitForSingleObject(m_hListenThread, INFINITE);
- m_hListenThread = nullptr;
+ while (m_hListenThread)
+ SleepEx(100, TRUE);
}
if (m_hAcceptTCPThread) {
TerminateThread(m_hAcceptTCPThread, 0);
@@ -176,22 +176,23 @@ void __cdecl CLan::ListenProc(void *lpParameter) void CLan::Listen()
{
+ if (m_mode != LM_LISTEN)
+ return;
+
MThreadHandle threadLock(m_hListenThread);
+ mir_ptr<char> buf((char*)mir_alloc(65536));
- if (m_mode == LM_LISTEN) {
- char buf[65536];
- while (true) {
- sockaddr_in addr;
- int addrLen = sizeof(addr);
- Sleep(20);
- int recLen = recvfrom(m_income, buf, 65536, 0, (sockaddr*)&addr, &addrLen);
- if (recLen == SOCKET_ERROR)
- break;
-
- OnRecvPacket((u_char*)buf, recLen, addr.sin_addr);
- }
+ while (true) {
+ Sleep(20);
+
+ sockaddr_in addr;
+ int addrLen = sizeof(addr);
+ int recLen = recvfrom(m_income, buf, 65536, 0, (sockaddr*)&addr, &addrLen);
+ if (recLen == SOCKET_ERROR)
+ break;
+
+ OnRecvPacket((u_char*)buf.get(), recLen, addr.sin_addr);
}
- m_hListenThread = nullptr;
}
void CLan::SendPacketBroadcast(const u_char* mes, int len)
|