aboutsummaryrefslogtreecommitdiff
path: root/src/socket.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-25 02:29:05 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-25 02:29:05 +0000
commita0c6e974a3393642bda80fed5bce464a6c6cf2ec (patch)
tree30e3098bb9a4da43bf5f94bd1e1944e070144615 /src/socket.cpp
parentecc191f590f76584a14c9c51727412b0b7b3086e (diff)
downloadlibbu++-a0c6e974a3393642bda80fed5bce464a6c6cf2ec.tar.gz
libbu++-a0c6e974a3393642bda80fed5bce464a6c6cf2ec.tar.bz2
libbu++-a0c6e974a3393642bda80fed5bce464a6c6cf2ec.tar.xz
libbu++-a0c6e974a3393642bda80fed5bce464a6c6cf2ec.zip
We now have a portable tempfile function, cool, it compiles on windows.
Fixed a bug in Socket, it wasn't closing the socket in all exception cases. Also fixed a few things in the unit test framework, going to add some more helpers soon.
Diffstat (limited to 'src/socket.cpp')
-rw-r--r--src/socket.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/socket.cpp b/src/socket.cpp
index 41e0763..696db1e 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -77,6 +77,7 @@ Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) :
77 if( (ret = bu_getaddrinfo( 77 if( (ret = bu_getaddrinfo(
78 sAddr.getStr(), ibuf, &aiHints, &pAddr )) != 0 ) 78 sAddr.getStr(), ibuf, &aiHints, &pAddr )) != 0 )
79 { 79 {
80 close();
80 throw Bu::SocketException("Couldn't resolve hostname %s (%s).\n", 81 throw Bu::SocketException("Couldn't resolve hostname %s (%s).\n",
81 sAddr.getStr(), bu_gai_strerror(ret)); 82 sAddr.getStr(), bu_gai_strerror(ret));
82 } 83 }
@@ -151,7 +152,11 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes )
151 FD_SET(nSocket, &rfds); 152 FD_SET(nSocket, &rfds);
152 struct timeval tv = {0, 0}; 153 struct timeval tv = {0, 0};
153 if( bu_select( nSocket+1, &rfds, NULL, NULL, &tv ) < 0 ) 154 if( bu_select( nSocket+1, &rfds, NULL, NULL, &tv ) < 0 )
154 throw SocketException( SocketException::cRead, strerror(errno) ); 155 {
156 int iErr = errno;
157 close();
158 throw SocketException( SocketException::cRead, strerror(iErr) );
159 }
155 if( FD_ISSET( nSocket, &rfds ) || bBlocking ) 160 if( FD_ISSET( nSocket, &rfds ) || bBlocking )
156 { 161 {
157 int nRead = TEMP_FAILURE_RETRY( 162 int nRead = TEMP_FAILURE_RETRY(
@@ -176,7 +181,9 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes )
176 } 181 }
177 if( errno == EAGAIN ) 182 if( errno == EAGAIN )
178 return 0; 183 return 0;
179 throw SocketException( SocketException::cRead, strerror(errno) ); 184 int iErr = errno;
185 close();
186 throw SocketException( SocketException::cRead, strerror(iErr) );
180#endif 187#endif
181 } 188 }
182 return nRead; 189 return nRead;