summaryrefslogtreecommitdiff
path: root/Bus
diff options
context:
space:
mode:
Diffstat (limited to 'Bus')
-rw-r--r--Bus/Ivy/ThreadedSocket.cxx16
1 files changed, 12 insertions, 4 deletions
diff --git a/Bus/Ivy/ThreadedSocket.cxx b/Bus/Ivy/ThreadedSocket.cxx
index 610f9b7..ee1e03b 100644
--- a/Bus/Ivy/ThreadedSocket.cxx
+++ b/Bus/Ivy/ThreadedSocket.cxx
@@ -16,9 +16,11 @@
CThreadedSocket::CThreadedSocket()
{
- m_hSocket = INVALID_SOCKET;
+ m_hSocket = INVALID_SOCKET;
h_reader = NULL;
h_writer = NULL;
+ reader_id = 0;
+ writer_id = 0;
listen_mode = false;
connect_pending = true;
send_pending = false;
@@ -125,8 +127,13 @@ void CThreadedSocket::Close()
{
long PreviousCount = 0;
int err;
+ DWORD currentThreadId;
+
+
if (m_hSocket != INVALID_SOCKET)
{
+ currentThreadId = GetCurrentThreadId();
+
//ASSERT(SOCKET_ERROR != closesocket(m_hSocket));
SOCKET temp = m_hSocket; // Thread ACK
m_hSocket = INVALID_SOCKET;
@@ -136,9 +143,10 @@ void CThreadedSocket::Close()
//if ( thread ) // On fait de l'auto delete mais dans le cas de terminaison anormale l'object reste ????!!!
// delete thread;
// TRACE("CThreadedSocket waiting for thread end ...\n");
- if ( h_reader ) WaitForSingleObject( h_reader, 5000 );
+ if ( h_reader && currentThreadId != reader_id )
+ WaitForSingleObject( h_reader, 5000 );
// wake up writer
- if ( h_writer )
+ if ( h_writer && currentThreadId != writer_id )
{
err = ReleaseSemaphore(send_count, 1, &PreviousCount);
WaitForSingleObject( h_writer, 5000 );
@@ -533,7 +541,7 @@ UINT CThreadedSocket::SocketWriter( )
}
Close();
h_writer = NULL;
-// TRACE( "CThreadedSocket::SocketWriter( END thread_id =( 0x%x) )\n",writer_id);
+ TRACE( "CThreadedSocket::SocketWriter( END thread_id =( 0x%x) )\n",writer_id);
return 0;
}