summaryrefslogtreecommitdiff
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
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.
-rw-r--r--src/cache.h16
-rw-r--r--src/socket.cpp12
-rw-r--r--src/socket.h1
3 files changed, 25 insertions, 4 deletions
diff --git a/src/cache.h b/src/cache.h
index 97ed140..c4e1b0b 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -100,6 +100,11 @@ namespace Bu
100 return pData != NULL; 100 return pData != NULL;
101 } 101 }
102 102
103 operator bool() const
104 {
105 return isBound() && isValid();
106 }
107
103 const keytype &getKey() const 108 const keytype &getKey() const
104 { 109 {
105 return kId; 110 return kId;
@@ -112,6 +117,17 @@ namespace Bu
112 pData = NULL; 117 pData = NULL;
113 } 118 }
114 119
120 void clear()
121 {
122 unbind();
123 pCache = NULL;
124 }
125
126 void unset()
127 {
128 clear();
129 }
130
115 Ptr &operator=( const Ptr &rRhs ) 131 Ptr &operator=( const Ptr &rRhs )
116 { 132 {
117 if( pCache && pData ) 133 if( pCache && pData )
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 {
diff --git a/src/socket.h b/src/socket.h
index f12f79c..bef0e9c 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -104,6 +104,7 @@ namespace Bu
104 int nSocket; 104 int nSocket;
105#endif 105#endif
106 bool bActive; 106 bool bActive;
107 bool bBlocking;
107 FString sReadBuf; 108 FString sReadBuf;
108 FString sAddress; 109 FString sAddress;
109 }; 110 };