Skip to content

Commit 1e6be97

Browse files
authored
Merge pull request #2587 from jvandenbroek/domoticztcp
Fix crash on stopping DomoticzTCP
2 parents c473047 + fd8d94d commit 1e6be97

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

hardware/DomoticzTCP.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include "../main/WebServerHelper.h"
88
#include "../webserver/proxyclient.h"
99

10+
#ifdef WIN32
11+
#define SHUT_RDWR SD_BOTH
12+
#endif
13+
1014
#define RETRY_DELAY 30
1115

1216
extern http::server::CWebServerHelper m_webservers;
@@ -147,20 +151,18 @@ bool DomoticzTCP::StopHardwareTCP()
147151
//Don't throw from a Stop command
148152
}
149153
}
150-
else {
151-
try {
152-
if (m_thread)
153-
{
154-
m_stoprequested = true;
155-
m_thread->join();
156-
m_thread.reset();
157-
}
158-
}
159-
catch (...)
154+
try {
155+
if (m_thread)
160156
{
161-
//Don't throw from a Stop command
157+
m_stoprequested = true;
158+
m_thread->join();
159+
m_thread.reset();
162160
}
163161
}
162+
catch (...)
163+
{
164+
//Don't throw from a Stop command
165+
}
164166
m_bIsStarted = false;
165167
return true;
166168
}
@@ -213,11 +215,10 @@ void DomoticzTCP::disconnectTCP()
213215
m_stoprequested = true;
214216
if (m_socket != INVALID_SOCKET)
215217
{
218+
shutdown(m_socket, SHUT_RDWR);
216219
closesocket(m_socket); //will terminate the thread
217220
m_socket = INVALID_SOCKET;
218-
sleep_seconds(1);
219221
}
220-
//m_thread-> join();
221222
}
222223

223224
void DomoticzTCP::Do_Work()

0 commit comments

Comments
 (0)