From d872f7e07c5367f251cf5ebb70a03916251f5306 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 1 Oct 2008 16:46:32 +0000 Subject: 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. --- src/socket.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/socket.cpp') 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 @@ #include #include #include "socket.h" -#include "exceptions.h" #include "osx_compatibility.h" #define RBS (1024*2) +namespace Bu { subExceptionDef( SocketException ) } + Bu::Socket::Socket( int nSocket ) : nSocket( nSocket ), bActive( true ) @@ -50,7 +51,7 @@ Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) flags |= O_NONBLOCK; if (fcntl(nSocket, F_SETFL, flags) < 0) { - throw ExceptionBase("Couldn't set socket options.\n"); + throw Bu::SocketException("Couldn't set socket options.\n"); } /* Connect to the server. */ @@ -63,7 +64,7 @@ Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) hostinfo = gethostbyname( sAddr.getStr() ); if (hostinfo == NULL) { - throw ExceptionBase("Couldn't resolve hostname.\n"); + throw Bu::SocketException("Couldn't resolve hostname.\n"); } xServerName.sin_addr = *(struct in_addr *) hostinfo->h_addr; } @@ -136,8 +137,8 @@ void Bu::Socket::read() { //printf("errno: %d, %s\n", errno, strerror( errno ) ); //perror("readInput"); - throw ConnectionException( - excodeReadError, + throw SocketException( + SocketException::cRead, "Read error: %s", strerror( errno ) ); @@ -162,8 +163,8 @@ void Bu::Socket::read() struct timeval tv = { 0, 0 }; int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); if( retval == -1 ) - throw ConnectionException( - excodeBadReadError, + throw SocketException( + SocketException::cBadRead, "Bad Read error" ); if( !FD_ISSET( nSocket, &rfds ) ) @@ -178,7 +179,7 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes ) int nRead = TEMP_FAILURE_RETRY( ::read( nSocket, pBuf, nBytes ) ); if( nRead < 0 ) { - throw ConnectionException( excodeReadError, strerror(errno) ); + throw SocketException( SocketException::cRead, strerror(errno) ); } return nRead; } @@ -220,7 +221,7 @@ size_t Bu::Socket::write( const void *pBuf, size_t nBytes ) if( nWrote < 0 ) { if( errno == EAGAIN ) return 0; - throw ConnectionException( excodeWriteError, strerror(errno) ); + throw SocketException( SocketException::cWrite, strerror(errno) ); } return nWrote; } @@ -288,8 +289,8 @@ bool Bu::Socket::canRead() struct timeval tv = { 0, 0 }; int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); if( retval == -1 ) - throw ConnectionException( - excodeBadReadError, + throw SocketException( + SocketException::cBadRead, "Bad Read error" ); if( !FD_ISSET( nSocket, &rfds ) ) @@ -305,8 +306,8 @@ bool Bu::Socket::canWrite() struct timeval tv = { 0, 0 }; int retval = select( nSocket+1, NULL, &wfds, NULL, &tv ); if( retval == -1 ) - throw ConnectionException( - excodeBadReadError, + throw SocketException( + SocketException::cBadRead, "Bad Read error" ); if( !FD_ISSET( nSocket, &wfds ) ) -- cgit v1.2.3