summaryrefslogtreecommitdiff
path: root/src/socket.cpp
diff options
context:
space:
mode:
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;