From a0c6e974a3393642bda80fed5bce464a6c6cf2ec Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 25 May 2010 02:29:05 +0000 Subject: 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. --- src/socket.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/socket.cpp') 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 ) : if( (ret = bu_getaddrinfo( sAddr.getStr(), ibuf, &aiHints, &pAddr )) != 0 ) { + close(); throw Bu::SocketException("Couldn't resolve hostname %s (%s).\n", sAddr.getStr(), bu_gai_strerror(ret)); } @@ -151,7 +152,11 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes ) FD_SET(nSocket, &rfds); struct timeval tv = {0, 0}; if( bu_select( nSocket+1, &rfds, NULL, NULL, &tv ) < 0 ) - throw SocketException( SocketException::cRead, strerror(errno) ); + { + int iErr = errno; + close(); + throw SocketException( SocketException::cRead, strerror(iErr) ); + } if( FD_ISSET( nSocket, &rfds ) || bBlocking ) { int nRead = TEMP_FAILURE_RETRY( @@ -176,7 +181,9 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes ) } if( errno == EAGAIN ) return 0; - throw SocketException( SocketException::cRead, strerror(errno) ); + int iErr = errno; + close(); + throw SocketException( SocketException::cRead, strerror(iErr) ); #endif } return nRead; -- cgit v1.2.3