diff options
author | fcolin | 2007-02-01 12:53:28 +0000 |
---|---|---|
committer | fcolin | 2007-02-01 12:53:28 +0000 |
commit | 17b10f43897aec90cf5e4b57ebc7ab0e26ca5b83 (patch) | |
tree | 164744a75acb2ccc961882afd49437d8ddd9bd72 | |
parent | c5851089facb6bcc36b736d21efd9941941667c3 (diff) | |
download | ivy-cplusplus-17b10f43897aec90cf5e4b57ebc7ab0e26ca5b83.zip ivy-cplusplus-17b10f43897aec90cf5e4b57ebc7ab0e26ca5b83.tar.gz ivy-cplusplus-17b10f43897aec90cf5e4b57ebc7ab0e26ca5b83.tar.bz2 ivy-cplusplus-17b10f43897aec90cf5e4b57ebc7ab0e26ca5b83.tar.xz |
Utilisateur : Fcolin Date : 2/02/01 Heure : 18:30 Archivé dans $/Ivy Commentaire: win CE compile not finished (vss 5)
-rw-r--r-- | Ivy/BufferedSocket.cxx | 79 |
1 files changed, 35 insertions, 44 deletions
diff --git a/Ivy/BufferedSocket.cxx b/Ivy/BufferedSocket.cxx index 63fd6c0..6a17b71 100644 --- a/Ivy/BufferedSocket.cxx +++ b/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());
+// }
}
|