From 00d85a7fcb3d1709dc555174f0eddbb6d1e5add4 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:36 +0000 Subject: Utilisateur : Fcolin Date : 18/11/05 Heure : 11:46 Archivé dans $/Bus/Ivy Commentaire: repassage a la STL et correction bug multithread (vss 25) --- Bus/Ivy/ThreadedSocket.cxx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Bus/Ivy/ThreadedSocket.cxx') 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; } -- cgit v1.1