From c5f521add8aac8af9b57b85bef0e82f00b2d819f Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:53:28 +0000 Subject: Utilisateur : Fcolin Date : 2/02/01 Heure : 18:30 Archivé dans $/Ivy Commentaire: win CE compile not finished (vss 5) --- Bus/Ivy/BufferedSocket.cxx | 79 ++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/Bus/Ivy/BufferedSocket.cxx b/Bus/Ivy/BufferedSocket.cxx index 63fd6c0..6a17b71 100644 --- a/Bus/Ivy/BufferedSocket.cxx +++ b/Bus/Ivy/BufferedSocket.cxx @@ -6,13 +6,10 @@ #include "BufferedSocket.h" #ifdef _DEBUG -#undef THIS_FILE -static char THIS_FILE[]=__FILE__; +#define DEBUG_NEW new(__FILE__, __LINE__) #define new DEBUG_NEW #endif -//IMPLEMENT_DYNAMIC(CBufferedSocket, CThreadedSocket) - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -99,54 +96,48 @@ void CBufferedSocket::SetSeparator( char sep ) { separator = sep; } -void CBufferedSocket::OnWakeup() +void CBufferedSocket::OnSend( int nErrorCode ) { string msg; bool empty; - try - { - // on essaye de garder la section critique a l'interieur de la boucle - // pour permettre l'entrelacement avec la partie emetrice - do + + // on essaye de garder la section critique a l'interieur de la boucle + // pour permettre l'entrelacement avec la partie emetrice + do + { + EnterCriticalSection( &m_CritSection ); + empty = buf_out.empty(); + if ( !empty ) msg = buf_out.front(); + LeaveCriticalSection( &m_CritSection ); + TRACE("CBufferedSocket::OnSend Sending buffer %s\n",msg.c_str()); + if ( !empty ) { - EnterCriticalSection( &m_CritSection ); - empty = buf_out.empty(); - if ( !empty ) msg = buf_out.front(); - LeaveCriticalSection( &m_CritSection ); - //TRACE("CBufferedSocket::OnWakeup Sending buffer %s\n",msg.c_str()); - if ( !empty ) - { - int lg = msg.length(); - CThreadedSocket::Send( msg.c_str(), lg ); + int lg = msg.length(); + int sent = CThreadedSocket::Send( msg.c_str(), lg ); + if ( sent == lg ) + { // emission correcte on enleve le msg de la file EnterCriticalSection( &m_CritSection ); buf_out.pop_front(); LeaveCriticalSection( &m_CritSection ); } - } while ( !empty ); - } - catch ( CThreadedSocketException* e ) - { - int err = e->GetError(); - if ( err == WSAEWOULDBLOCK ) - { - // put back the buffer, preserving the order - //EnterCriticalSection( &m_CritSection ); - //buf_out.push_front( msg); - //LeaveCriticalSection( &m_CritSection ); + else + { // erreur + int err = GetLastError(); + if ( err == WSAEWOULDBLOCK ) // si la file est pleine on sort en silence ! + { + } + else + TRACE("CBufferedSocket::OnWakeup error %d Sending buffer %s \n",err,msg); + break; } - else TRACE("CBufferedSocket::OnWakeup error %d Sending buffer %s \n",err,msg); - } - - -} -void CBufferedSocket::OnSend( int nErrorCode ) -{ - OnWakeup(); + } + } while ( !empty ); } + void CBufferedSocket::OnConnect( int nErrorCode ) { connected = true; - OnWakeup(); + StartWriter(); //TRACE("CBufferedSocket::OnConnect buffer empty %d\n",buf_out.IsEmpty()); } void CBufferedSocket::Send ( const char * data ) @@ -157,9 +148,9 @@ void CBufferedSocket::Send ( const char * data ) buf_out.push_back( string(data) ); LeaveCriticalSection( &m_CritSection ); //TRACE("CBufferedSocket::Send Adding buffer to send count %d\n",buf_out.size()); - if ( connected ) - { -// BOOL ok = WSASetEvent( m_hEvent[1] ); -// if ( !ok ) TRACE( "CBufferedSocket::Send Error SetEvent %d\n", WSAGetLastError()); - } +// if ( connected ) +// { + bool ok = SignalWriter(); + if ( !ok ) TRACE( "CBufferedSocket::SignalWriter Error %d\n", ::GetLastError()); +// } } -- cgit v1.1