diff options
Diffstat (limited to 'src/serversocket.cpp')
-rw-r--r-- | src/serversocket.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/serversocket.cpp b/src/serversocket.cpp index 30f584d..6f7fc00 100644 --- a/src/serversocket.cpp +++ b/src/serversocket.cpp | |||
@@ -18,9 +18,10 @@ | |||
18 | #include <netdb.h> | 18 | #include <netdb.h> |
19 | #include <arpa/inet.h> | 19 | #include <arpa/inet.h> |
20 | #include <fcntl.h> | 20 | #include <fcntl.h> |
21 | #include "serversocket.h" | 21 | #include "bu/serversocket.h" |
22 | #include "exceptions.h" | 22 | #include "bu/osx_compatibility.h" |
23 | #include "osx_compatibility.h" | 23 | |
24 | namespace Bu { subExceptionDef( ServerSocketException ) } | ||
24 | 25 | ||
25 | Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : | 26 | Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : |
26 | nPort( nPort ) | 27 | nPort( nPort ) |
@@ -64,7 +65,7 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) | |||
64 | nServer = socket( PF_INET, SOCK_STREAM, 0 ); | 65 | nServer = socket( PF_INET, SOCK_STREAM, 0 ); |
65 | if( nServer < 0 ) | 66 | if( nServer < 0 ) |
66 | { | 67 | { |
67 | throw Bu::SocketException("Couldn't create a listen socket."); | 68 | throw Bu::ServerSocketException("Couldn't create a listen socket."); |
68 | } | 69 | } |
69 | 70 | ||
70 | int opt = 1; | 71 | int opt = 1; |
@@ -78,12 +79,12 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) | |||
78 | 79 | ||
79 | if( bind( nServer, (struct sockaddr *) &name, sizeof(name) ) < 0 ) | 80 | if( bind( nServer, (struct sockaddr *) &name, sizeof(name) ) < 0 ) |
80 | { | 81 | { |
81 | throw Bu::SocketException("Couldn't bind to the listen socket."); | 82 | throw Bu::ServerSocketException("Couldn't bind to the listen socket."); |
82 | } | 83 | } |
83 | 84 | ||
84 | if( listen( nServer, nPoolSize ) < 0 ) | 85 | if( listen( nServer, nPoolSize ) < 0 ) |
85 | { | 86 | { |
86 | throw Bu::SocketException( | 87 | throw Bu::ServerSocketException( |
87 | "Couldn't begin listening to the server socket." | 88 | "Couldn't begin listening to the server socket." |
88 | ); | 89 | ); |
89 | } | 90 | } |
@@ -109,7 +110,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) | |||
109 | 110 | ||
110 | if( TEMP_FAILURE_RETRY(select( nServer+1, &fdRead, NULL, NULL, &xT )) < 0 ) | 111 | if( TEMP_FAILURE_RETRY(select( nServer+1, &fdRead, NULL, NULL, &xT )) < 0 ) |
111 | { | 112 | { |
112 | throw SocketException( | 113 | throw Bu::ServerSocketException( |
113 | "Error scanning for new connections: %s", strerror( errno ) | 114 | "Error scanning for new connections: %s", strerror( errno ) |
114 | ); | 115 | ); |
115 | } | 116 | } |
@@ -134,7 +135,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) | |||
134 | #endif /* __CYGWIN__ */ | 135 | #endif /* __CYGWIN__ */ |
135 | if( nClient < 0 ) | 136 | if( nClient < 0 ) |
136 | { | 137 | { |
137 | throw SocketException( | 138 | throw Bu::ServerSocketException( |
138 | "Error accepting a new connection: %s", strerror( errno ) | 139 | "Error accepting a new connection: %s", strerror( errno ) |
139 | ); | 140 | ); |
140 | } | 141 | } |
@@ -150,7 +151,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) | |||
150 | flags |= O_NONBLOCK; | 151 | flags |= O_NONBLOCK; |
151 | if( fcntl( nClient, F_SETFL, flags ) < 0) | 152 | if( fcntl( nClient, F_SETFL, flags ) < 0) |
152 | { | 153 | { |
153 | throw SocketException( | 154 | throw Bu::ServerSocketException( |
154 | "Error setting option on client socket: %s", | 155 | "Error setting option on client socket: %s", |
155 | strerror( errno ) | 156 | strerror( errno ) |
156 | ); | 157 | ); |