diff options
author | fcolin | 2007-02-01 13:05:00 +0000 |
---|---|---|
committer | fcolin | 2007-02-01 13:05:00 +0000 |
commit | 448bc8dc724aadaf0e687689bf4f8c7a390bf070 (patch) | |
tree | 402424e0041e71c219608afeb59849b9ab02b1c1 /Bus/Ivy | |
parent | bfe5acb474ef27c02e76522d8df33736168be762 (diff) | |
download | ivy-cplusplus-448bc8dc724aadaf0e687689bf4f8c7a390bf070.zip ivy-cplusplus-448bc8dc724aadaf0e687689bf4f8c7a390bf070.tar.gz ivy-cplusplus-448bc8dc724aadaf0e687689bf4f8c7a390bf070.tar.bz2 ivy-cplusplus-448bc8dc724aadaf0e687689bf4f8c7a390bf070.tar.xz |
Utilisateur : Fcolin Date : 14/02/01 Heure : 18:47 Archivé dans $/Ivy (vss 7)
Diffstat (limited to 'Bus/Ivy')
-rw-r--r-- | Bus/Ivy/ThreadedSocket.cxx | 79 |
1 files changed, 51 insertions, 28 deletions
diff --git a/Bus/Ivy/ThreadedSocket.cxx b/Bus/Ivy/ThreadedSocket.cxx index 7f36f07..4f94573 100644 --- a/Bus/Ivy/ThreadedSocket.cxx +++ b/Bus/Ivy/ThreadedSocket.cxx @@ -30,10 +30,21 @@ CThreadedSocket::CThreadedSocket() CThreadedSocket::~CThreadedSocket()
{
+ long PreviousCount = 0;
+ int err;
if (m_hSocket != INVALID_SOCKET)
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, INFINITE );
+ // wake up writer
+ if ( h_writer )
+ {
+ err = ReleaseSemaphore(send_count, 1, &PreviousCount);
+ WaitForSingleObject( h_writer, INFINITE );
+ }
+ TRACE("CThreadedSocket all thread ended\n");
}
int CThreadedSocket::Create(UINT nSocketPort, int nSocketType, const char * lpszSocketAddress)
{
@@ -376,7 +387,7 @@ UINT CThreadedSocket::SocketReader( ) {
int err;
int sock_err;
- unsigned long readcount;
+ unsigned long readcount = 0;
fd_set readfds;
fd_set writefds;
fd_set exceptfds;
@@ -390,6 +401,8 @@ UINT CThreadedSocket::SocketReader( ) FD_SET(m_hSocket, &readfds);
if ( connect_pending )
FD_SET(m_hSocket, &writefds);
+ else
+ FD_CLR(m_hSocket, &writefds);
FD_SET(m_hSocket, &exceptfds);
err = select( 1, &readfds, &writefds, &exceptfds, NULL );
@@ -402,8 +415,10 @@ UINT CThreadedSocket::SocketReader( ) break;
case SOCKET_ERROR:
- TRACE( "CThreadedSocketException( select )\n");
- Close();
+ TRACE( "CThreadedSocket::SocketReader( select error thread_id =( %d) )\n",reader_id);
+
+ if (m_hSocket != INVALID_SOCKET)
+ Close();
h_reader = NULL;
return sock_err;
break;
@@ -436,8 +451,11 @@ UINT CThreadedSocket::SocketReader( ) break;
}
}
- Close();
+ if (m_hSocket != INVALID_SOCKET)
+ Close();
h_reader = NULL;
+ TRACE( "CThreadedSocket::SocketReader( END thread_id =( 0x%x) )\n",reader_id);
+
return 0;
}
@@ -469,40 +487,45 @@ UINT CThreadedSocket::SocketWriter( ) case WAIT_TIMEOUT:
case WAIT_FAILED:
default:
- TRACE( "CThreadedSocketException( SocketWriter WaitForSingleObject )\n");
- Close();
+ TRACE( "CThreadedSocket::SocketWriter( WaitForSingleObject error thread_id =( %d) )\n",writer_id);
+ if (m_hSocket != INVALID_SOCKET)
+ Close();
h_writer = NULL;
return GetLastError();
break;
}
+ if (m_hSocket != INVALID_SOCKET)
+ {
+ FD_SET(m_hSocket, &writefds);
- FD_SET(m_hSocket, &writefds);
-
- err = select( 1, NULL, &writefds, NULL, NULL );
- sock_err = GetLastError();
+ err = select( 1, NULL, &writefds, NULL, NULL );
+ sock_err = GetLastError();
- switch ( err )
- {
- case 0:
- TRACE( "CThreadedSocket::SocketThread Unhandled Timeout Event !\n");
- break;
- case SOCKET_ERROR:
- TRACE( "CThreadedSocketException( select )\n");
- Close();
- h_reader = NULL;
- return sock_err;
- break;
- default:
-
- if ( FD_ISSET(m_hSocket, &writefds) )
- {
- OnSend( sock_err );
- }
+ switch ( err )
+ {
+ case 0:
+ TRACE( "CThreadedSocket::SocketThread Unhandled Timeout Event !\n");
+ break;
+ case SOCKET_ERROR:
+ TRACE( "CThreadedSocketException( select )\n");
+ Close();
+ h_reader = NULL;
+ return sock_err;
+ break;
+ default:
+
+ if ( FD_ISSET(m_hSocket, &writefds) )
+ {
+ OnSend( sock_err );
+ }
- break;
+ break;
+ }
}
}
Close();
h_writer = NULL;
+ TRACE( "CThreadedSocket::SocketWriter( END thread_id =( 0x%x) )\n",writer_id);
+
return 0;
}
|