[DEBUG] correct the stop sequence

This commit is contained in:
Edouard DUPIN 2016-12-08 21:01:37 +01:00
parent 18a4b7f72b
commit 39660fae32
2 changed files with 11 additions and 1 deletions

View File

@ -167,7 +167,9 @@ void enet::Http::stop(bool _inThreadStop){
} }
if (_inThreadStop == false) { if (_inThreadStop == false) {
if (m_thread != nullptr) { if (m_thread != nullptr) {
ENET_DEBUG("wait join Thread ...");
m_thread->join(); m_thread->join();
ENET_DEBUG("wait join Thread (done)");
delete m_thread; delete m_thread;
m_thread = nullptr; m_thread = nullptr;
} }

View File

@ -11,6 +11,7 @@
#include <unistd.h> #include <unistd.h>
#include <cstring> #include <cstring>
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
#include <ethread/tools.hpp>
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
#include <winsock2.h> #include <winsock2.h>
@ -89,20 +90,25 @@ enet::Tcp& enet::Tcp::operator = (enet::Tcp&& _obj) {
} }
bool enet::Tcp::unlink() { bool enet::Tcp::unlink() {
// prevent call while stoping ...
m_status = status::unlink;
if (m_socketId >= 0) { if (m_socketId >= 0) {
ENET_INFO("Close socket (start)"); ENET_INFO("Close socket (start)");
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
shutdown(m_socketId, SD_BOTH); shutdown(m_socketId, SD_BOTH);
// Release hand of the socket to permit the Select to exit ... ==> otherwise it lock ...
std::this_thread::sleep_for(std::chrono::milliseconds(20));
closesocket(m_socketId); closesocket(m_socketId);
m_socketId = INVALID_SOCKET; m_socketId = INVALID_SOCKET;
#else #else
shutdown(m_socketId, SHUT_RDWR); shutdown(m_socketId, SHUT_RDWR);
// Release hand of the socket to permit the Select to exit ... ==> otherwise it lock ...
std::this_thread::sleep_for(std::chrono::milliseconds(20));
close(m_socketId); close(m_socketId);
m_socketId = -1; m_socketId = -1;
#endif #endif
ENET_INFO("Close socket (done)"); ENET_INFO("Close socket (done)");
} }
m_status = status::unlink;
return true; return true;
} }
@ -121,7 +127,9 @@ int32_t enet::Tcp::read(void* _data, int32_t _maxLen) {
timeOutStruct.tv_usec = 0; timeOutStruct.tv_usec = 0;
FD_ZERO(&sock); FD_ZERO(&sock);
FD_SET(m_socketId,&sock); FD_SET(m_socketId,&sock);
ENET_VERBOSE(" select ...");
int rc = select(m_socketId+1, &sock, NULL, NULL, &timeOutStruct); int rc = select(m_socketId+1, &sock, NULL, NULL, &timeOutStruct);
ENET_VERBOSE(" select (done)");
// Check to see if the poll call failed. // Check to see if the poll call failed.
if (rc < 0) { if (rc < 0) {
ENET_ERROR(" select() failed"); ENET_ERROR(" select() failed");