diff options
author | Mike Buland <eichlan@xagasoft.com> | 2008-10-01 16:46:32 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2008-10-01 16:46:32 +0000 |
commit | d872f7e07c5367f251cf5ebb70a03916251f5306 (patch) | |
tree | 2140986825705e4b6bf35eba8dd556be772888ff /src/socket.cpp | |
parent | 467c255511749f018c4572017c9e0e87275524ac (diff) | |
download | libbu++-d872f7e07c5367f251cf5ebb70a03916251f5306.tar.gz libbu++-d872f7e07c5367f251cf5ebb70a03916251f5306.tar.bz2 libbu++-d872f7e07c5367f251cf5ebb70a03916251f5306.tar.xz libbu++-d872f7e07c5367f251cf5ebb70a03916251f5306.zip |
Ok, NIDS is getting better and better, and I went ahead and cleaned up some
exception related code that's been annoying me. You should no longer have to
include any exception header explicitly for normal operations, every class that
has it's own exception to throw defines it in it's own headers.
This may break some code that uses libbu++, but it's an easy fix, just delete
the include for exceptions.h. Sometime soon I would also like to move from
Bu::ExceptionBase to Bu::Exception, but that will affect a lot more code than
this change did.
Diffstat (limited to 'src/socket.cpp')
-rw-r--r-- | src/socket.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/socket.cpp b/src/socket.cpp index 651a2e1..531d8ac 100644 --- a/src/socket.cpp +++ b/src/socket.cpp | |||
@@ -19,11 +19,12 @@ | |||
19 | #include <errno.h> | 19 | #include <errno.h> |
20 | #include <fcntl.h> | 20 | #include <fcntl.h> |
21 | #include "socket.h" | 21 | #include "socket.h" |
22 | #include "exceptions.h" | ||
23 | #include "osx_compatibility.h" | 22 | #include "osx_compatibility.h" |
24 | 23 | ||
25 | #define RBS (1024*2) | 24 | #define RBS (1024*2) |
26 | 25 | ||
26 | namespace Bu { subExceptionDef( SocketException ) } | ||
27 | |||
27 | Bu::Socket::Socket( int nSocket ) : | 28 | Bu::Socket::Socket( int nSocket ) : |
28 | nSocket( nSocket ), | 29 | nSocket( nSocket ), |
29 | bActive( true ) | 30 | bActive( true ) |
@@ -50,7 +51,7 @@ Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) | |||
50 | flags |= O_NONBLOCK; | 51 | flags |= O_NONBLOCK; |
51 | if (fcntl(nSocket, F_SETFL, flags) < 0) | 52 | if (fcntl(nSocket, F_SETFL, flags) < 0) |
52 | { | 53 | { |
53 | throw ExceptionBase("Couldn't set socket options.\n"); | 54 | throw Bu::SocketException("Couldn't set socket options.\n"); |
54 | } | 55 | } |
55 | 56 | ||
56 | /* Connect to the server. */ | 57 | /* Connect to the server. */ |
@@ -63,7 +64,7 @@ Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) | |||
63 | hostinfo = gethostbyname( sAddr.getStr() ); | 64 | hostinfo = gethostbyname( sAddr.getStr() ); |
64 | if (hostinfo == NULL) | 65 | if (hostinfo == NULL) |
65 | { | 66 | { |
66 | throw ExceptionBase("Couldn't resolve hostname.\n"); | 67 | throw Bu::SocketException("Couldn't resolve hostname.\n"); |
67 | } | 68 | } |
68 | xServerName.sin_addr = *(struct in_addr *) hostinfo->h_addr; | 69 | xServerName.sin_addr = *(struct in_addr *) hostinfo->h_addr; |
69 | } | 70 | } |
@@ -136,8 +137,8 @@ void Bu::Socket::read() | |||
136 | { | 137 | { |
137 | //printf("errno: %d, %s\n", errno, strerror( errno ) ); | 138 | //printf("errno: %d, %s\n", errno, strerror( errno ) ); |
138 | //perror("readInput"); | 139 | //perror("readInput"); |
139 | throw ConnectionException( | 140 | throw SocketException( |
140 | excodeReadError, | 141 | SocketException::cRead, |
141 | "Read error: %s", | 142 | "Read error: %s", |
142 | strerror( errno ) | 143 | strerror( errno ) |
143 | ); | 144 | ); |
@@ -162,8 +163,8 @@ void Bu::Socket::read() | |||
162 | struct timeval tv = { 0, 0 }; | 163 | struct timeval tv = { 0, 0 }; |
163 | int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); | 164 | int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); |
164 | if( retval == -1 ) | 165 | if( retval == -1 ) |
165 | throw ConnectionException( | 166 | throw SocketException( |
166 | excodeBadReadError, | 167 | SocketException::cBadRead, |
167 | "Bad Read error" | 168 | "Bad Read error" |
168 | ); | 169 | ); |
169 | if( !FD_ISSET( nSocket, &rfds ) ) | 170 | if( !FD_ISSET( nSocket, &rfds ) ) |
@@ -178,7 +179,7 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes ) | |||
178 | int nRead = TEMP_FAILURE_RETRY( ::read( nSocket, pBuf, nBytes ) ); | 179 | int nRead = TEMP_FAILURE_RETRY( ::read( nSocket, pBuf, nBytes ) ); |
179 | if( nRead < 0 ) | 180 | if( nRead < 0 ) |
180 | { | 181 | { |
181 | throw ConnectionException( excodeReadError, strerror(errno) ); | 182 | throw SocketException( SocketException::cRead, strerror(errno) ); |
182 | } | 183 | } |
183 | return nRead; | 184 | return nRead; |
184 | } | 185 | } |
@@ -220,7 +221,7 @@ size_t Bu::Socket::write( const void *pBuf, size_t nBytes ) | |||
220 | if( nWrote < 0 ) | 221 | if( nWrote < 0 ) |
221 | { | 222 | { |
222 | if( errno == EAGAIN ) return 0; | 223 | if( errno == EAGAIN ) return 0; |
223 | throw ConnectionException( excodeWriteError, strerror(errno) ); | 224 | throw SocketException( SocketException::cWrite, strerror(errno) ); |
224 | } | 225 | } |
225 | return nWrote; | 226 | return nWrote; |
226 | } | 227 | } |
@@ -288,8 +289,8 @@ bool Bu::Socket::canRead() | |||
288 | struct timeval tv = { 0, 0 }; | 289 | struct timeval tv = { 0, 0 }; |
289 | int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); | 290 | int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); |
290 | if( retval == -1 ) | 291 | if( retval == -1 ) |
291 | throw ConnectionException( | 292 | throw SocketException( |
292 | excodeBadReadError, | 293 | SocketException::cBadRead, |
293 | "Bad Read error" | 294 | "Bad Read error" |
294 | ); | 295 | ); |
295 | if( !FD_ISSET( nSocket, &rfds ) ) | 296 | if( !FD_ISSET( nSocket, &rfds ) ) |
@@ -305,8 +306,8 @@ bool Bu::Socket::canWrite() | |||
305 | struct timeval tv = { 0, 0 }; | 306 | struct timeval tv = { 0, 0 }; |
306 | int retval = select( nSocket+1, NULL, &wfds, NULL, &tv ); | 307 | int retval = select( nSocket+1, NULL, &wfds, NULL, &tv ); |
307 | if( retval == -1 ) | 308 | if( retval == -1 ) |
308 | throw ConnectionException( | 309 | throw SocketException( |
309 | excodeBadReadError, | 310 | SocketException::cBadRead, |
310 | "Bad Read error" | 311 | "Bad Read error" |
311 | ); | 312 | ); |
312 | if( !FD_ISSET( nSocket, &wfds ) ) | 313 | if( !FD_ISSET( nSocket, &wfds ) ) |