aboutsummaryrefslogtreecommitdiff
path: root/src/socket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/socket.cpp')
-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 {