From 22914644fb62bc1a9d49eec50a10f2870dde1d0b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 28 May 2009 16:23:38 +0000 Subject: Added some helpers to the Bu::Cache::Ptr, you can clear them now, and cast to bool to see if they're bound, you still have to use isValid to see if they're valid or not. Also, fixed a bug in libbu++ that's been around for a while, apparently, in the Bu::Socket code. Non-blocking reading wasn't working correctly, when data wasn't waiting on the line, it would return immediately with zero bytes read. That was sure stupid. This should fix a lot of things. --- src/socket.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/socket.cpp') diff --git a/src/socket.cpp b/src/socket.cpp index c01c63a..46e6cd7 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -34,7 +34,8 @@ namespace Bu { subExceptionDef( SocketException ) } Bu::Socket::Socket( int nSocket ) : nSocket( nSocket ), - bActive( true ) + bActive( true ), + bBlocking( true ) { #ifdef WIN32 Bu::Winsock2::getInstance(); @@ -42,12 +43,14 @@ Bu::Socket::Socket( int nSocket ) : setAddress(); } -Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) +Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) : + nSocket( 0 ), + bActive( false ), + bBlocking( true ) { #ifdef WIN32 Bu::Winsock2::getInstance(); #endif - bActive = false; /* Create the socket. */ nSocket = bu_socket( PF_INET, SOCK_STREAM, 0 ); @@ -150,7 +153,7 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes ) struct timeval tv = {0, 0}; if( bu_select( nSocket+1, &rfds, NULL, NULL, &tv ) < 0 ) throw SocketException( SocketException::cRead, strerror(errno) ); - if( FD_ISSET( nSocket, &rfds ) ) + if( FD_ISSET( nSocket, &rfds ) || bBlocking ) { int nRead = TEMP_FAILURE_RETRY( bu_recv( nSocket, (char *) pBuf, nBytes, 0 ) ); @@ -377,6 +380,7 @@ bool Bu::Socket::isBlocking() void Bu::Socket::setBlocking( bool bBlocking ) { + this->bBlocking = bBlocking; #ifndef WIN32 if( bBlocking ) { -- cgit v1.2.3