aboutsummaryrefslogtreecommitdiff
path: root/src/socket.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-05-28 16:23:38 +0000
committerMike Buland <eichlan@xagasoft.com>2009-05-28 16:23:38 +0000
commit22914644fb62bc1a9d49eec50a10f2870dde1d0b (patch)
treeec7e69e4efddd3602d59444706a49e389ab01a45 /src/socket.cpp
parent98e1848ebf1024f28e82ee39cc6a81bd2b14d4fa (diff)
downloadlibbu++-22914644fb62bc1a9d49eec50a10f2870dde1d0b.tar.gz
libbu++-22914644fb62bc1a9d49eec50a10f2870dde1d0b.tar.bz2
libbu++-22914644fb62bc1a9d49eec50a10f2870dde1d0b.tar.xz
libbu++-22914644fb62bc1a9d49eec50a10f2870dde1d0b.zip
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.
Diffstat (limited to '')
-rw-r--r--src/socket.cpp12
1 files changed, 8 insertions, 4 deletions
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 ) }
34 34
35Bu::Socket::Socket( int nSocket ) : 35Bu::Socket::Socket( int nSocket ) :
36 nSocket( nSocket ), 36 nSocket( nSocket ),
37 bActive( true ) 37 bActive( true ),
38 bBlocking( true )
38{ 39{
39#ifdef WIN32 40#ifdef WIN32
40 Bu::Winsock2::getInstance(); 41 Bu::Winsock2::getInstance();
@@ -42,12 +43,14 @@ Bu::Socket::Socket( int nSocket ) :
42 setAddress(); 43 setAddress();
43} 44}
44 45
45Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) 46Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) :
47 nSocket( 0 ),
48 bActive( false ),
49 bBlocking( true )
46{ 50{
47#ifdef WIN32 51#ifdef WIN32
48 Bu::Winsock2::getInstance(); 52 Bu::Winsock2::getInstance();
49#endif 53#endif
50 bActive = false;
51 54
52 /* Create the socket. */ 55 /* Create the socket. */
53 nSocket = bu_socket( PF_INET, SOCK_STREAM, 0 ); 56 nSocket = bu_socket( PF_INET, SOCK_STREAM, 0 );
@@ -150,7 +153,7 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes )
150 struct timeval tv = {0, 0}; 153 struct timeval tv = {0, 0};
151 if( bu_select( nSocket+1, &rfds, NULL, NULL, &tv ) < 0 ) 154 if( bu_select( nSocket+1, &rfds, NULL, NULL, &tv ) < 0 )
152 throw SocketException( SocketException::cRead, strerror(errno) ); 155 throw SocketException( SocketException::cRead, strerror(errno) );
153 if( FD_ISSET( nSocket, &rfds ) ) 156 if( FD_ISSET( nSocket, &rfds ) || bBlocking )
154 { 157 {
155 int nRead = TEMP_FAILURE_RETRY( 158 int nRead = TEMP_FAILURE_RETRY(
156 bu_recv( nSocket, (char *) pBuf, nBytes, 0 ) ); 159 bu_recv( nSocket, (char *) pBuf, nBytes, 0 ) );
@@ -377,6 +380,7 @@ bool Bu::Socket::isBlocking()
377 380
378void Bu::Socket::setBlocking( bool bBlocking ) 381void Bu::Socket::setBlocking( bool bBlocking )
379{ 382{
383 this->bBlocking = bBlocking;
380#ifndef WIN32 384#ifndef WIN32
381 if( bBlocking ) 385 if( bBlocking )
382 { 386 {