diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-10-16 03:02:11 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-10-16 03:02:11 +0000 |
commit | 9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5 (patch) | |
tree | 17bc9d96b13d16d79385016c087321fc1267743f /src/tcpserversocket.cpp | |
parent | 93c028162318a00b9bd03fc4a48383f830cc529d (diff) | |
download | libbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.tar.gz libbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.tar.bz2 libbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.tar.xz libbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.zip |
Many, many changes. Documentation changes, renamed the socket class to
TcpSocket, fixed many other things, and finally removed ParamProc. Anything
that needs it will now have to switch to OptParser.
Diffstat (limited to '')
-rw-r--r-- | src/tcpserversocket.cpp (renamed from src/serversocket.cpp) | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/serversocket.cpp b/src/tcpserversocket.cpp index 87d0035..7d7f6e4 100644 --- a/src/serversocket.cpp +++ b/src/tcpserversocket.cpp | |||
@@ -21,13 +21,13 @@ | |||
21 | #include <sys/types.h> | 21 | #include <sys/types.h> |
22 | //#include <termios.h> | 22 | //#include <termios.h> |
23 | #include <fcntl.h> | 23 | #include <fcntl.h> |
24 | #include "bu/serversocket.h" | 24 | #include "bu/tcpserversocket.h" |
25 | 25 | ||
26 | #include "bu/config.h" | 26 | #include "bu/config.h" |
27 | 27 | ||
28 | namespace Bu { subExceptionDef( ServerSocketException ) } | 28 | namespace Bu { subExceptionDef( TcpServerSocketException ) } |
29 | 29 | ||
30 | Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : | 30 | Bu::TcpServerSocket::TcpServerSocket( int nPort, int nPoolSize ) : |
31 | nPort( nPort ) | 31 | nPort( nPort ) |
32 | { | 32 | { |
33 | #ifdef WIN32 | 33 | #ifdef WIN32 |
@@ -48,7 +48,7 @@ Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : | |||
48 | startServer( name, nPoolSize ); | 48 | startServer( name, nPoolSize ); |
49 | } | 49 | } |
50 | 50 | ||
51 | Bu::ServerSocket::ServerSocket(const FString &sAddr,int nPort, int nPoolSize) : | 51 | Bu::TcpServerSocket::TcpServerSocket(const FString &sAddr,int nPort, int nPoolSize) : |
52 | nPort( nPort ) | 52 | nPort( nPort ) |
53 | { | 53 | { |
54 | #ifdef WIN32 | 54 | #ifdef WIN32 |
@@ -72,7 +72,7 @@ Bu::ServerSocket::ServerSocket(const FString &sAddr,int nPort, int nPoolSize) : | |||
72 | startServer( name, nPoolSize ); | 72 | startServer( name, nPoolSize ); |
73 | } | 73 | } |
74 | 74 | ||
75 | Bu::ServerSocket::ServerSocket( int nServer, bool bInit, int nPoolSize ) : | 75 | Bu::TcpServerSocket::TcpServerSocket( int nServer, bool bInit, int nPoolSize ) : |
76 | nServer( nServer ), | 76 | nServer( nServer ), |
77 | nPort( 0 ) | 77 | nPort( 0 ) |
78 | { | 78 | { |
@@ -95,7 +95,7 @@ Bu::ServerSocket::ServerSocket( int nServer, bool bInit, int nPoolSize ) : | |||
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | Bu::ServerSocket::ServerSocket( const ServerSocket &rSrc ) | 98 | Bu::TcpServerSocket::TcpServerSocket( const TcpServerSocket &rSrc ) |
99 | { | 99 | { |
100 | #ifdef WIN32 | 100 | #ifdef WIN32 |
101 | Bu::Winsock2::getInstance(); | 101 | Bu::Winsock2::getInstance(); |
@@ -107,20 +107,20 @@ Bu::ServerSocket::ServerSocket( const ServerSocket &rSrc ) | |||
107 | FD_SET( nServer, &fdActive ); | 107 | FD_SET( nServer, &fdActive ); |
108 | } | 108 | } |
109 | 109 | ||
110 | Bu::ServerSocket::~ServerSocket() | 110 | Bu::TcpServerSocket::~TcpServerSocket() |
111 | { | 111 | { |
112 | if( nServer > -1 ) | 112 | if( nServer > -1 ) |
113 | ::close( nServer ); | 113 | ::close( nServer ); |
114 | } | 114 | } |
115 | 115 | ||
116 | void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) | 116 | void Bu::TcpServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) |
117 | { | 117 | { |
118 | /* Create the socket. */ | 118 | /* Create the socket. */ |
119 | nServer = bu_socket( PF_INET, SOCK_STREAM, 0 ); | 119 | nServer = bu_socket( PF_INET, SOCK_STREAM, 0 ); |
120 | 120 | ||
121 | if( nServer < 0 ) | 121 | if( nServer < 0 ) |
122 | { | 122 | { |
123 | throw Bu::ServerSocketException("Couldn't create a listen socket."); | 123 | throw Bu::TcpServerSocketException("Couldn't create a listen socket."); |
124 | } | 124 | } |
125 | 125 | ||
126 | int opt = 1; | 126 | int opt = 1; |
@@ -135,16 +135,16 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) | |||
135 | initServer( name, nPoolSize ); | 135 | initServer( name, nPoolSize ); |
136 | } | 136 | } |
137 | 137 | ||
138 | void Bu::ServerSocket::initServer( struct sockaddr_in &name, int nPoolSize ) | 138 | void Bu::TcpServerSocket::initServer( struct sockaddr_in &name, int nPoolSize ) |
139 | { | 139 | { |
140 | if( bu_bind( nServer, (struct sockaddr *) &name, sizeof(name) ) < 0 ) | 140 | if( bu_bind( nServer, (struct sockaddr *) &name, sizeof(name) ) < 0 ) |
141 | { | 141 | { |
142 | throw Bu::ServerSocketException("Couldn't bind to the listen socket."); | 142 | throw Bu::TcpServerSocketException("Couldn't bind to the listen socket."); |
143 | } | 143 | } |
144 | 144 | ||
145 | if( bu_listen( nServer, nPoolSize ) < 0 ) | 145 | if( bu_listen( nServer, nPoolSize ) < 0 ) |
146 | { | 146 | { |
147 | throw Bu::ServerSocketException( | 147 | throw Bu::TcpServerSocketException( |
148 | "Couldn't begin listening to the server socket." | 148 | "Couldn't begin listening to the server socket." |
149 | ); | 149 | ); |
150 | } | 150 | } |
@@ -154,12 +154,12 @@ void Bu::ServerSocket::initServer( struct sockaddr_in &name, int nPoolSize ) | |||
154 | FD_SET( nServer, &fdActive ); | 154 | FD_SET( nServer, &fdActive ); |
155 | } | 155 | } |
156 | 156 | ||
157 | int Bu::ServerSocket::getSocket() | 157 | int Bu::TcpServerSocket::getSocket() |
158 | { | 158 | { |
159 | return nServer; | 159 | return nServer; |
160 | } | 160 | } |
161 | 161 | ||
162 | int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) | 162 | int Bu::TcpServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) |
163 | { | 163 | { |
164 | fd_set fdRead = fdActive; | 164 | fd_set fdRead = fdActive; |
165 | 165 | ||
@@ -171,7 +171,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) | |||
171 | if( TEMP_FAILURE_RETRY( | 171 | if( TEMP_FAILURE_RETRY( |
172 | bu_select( nServer+1, &fdRead, NULL, NULL, &xT )) < 0 ) | 172 | bu_select( nServer+1, &fdRead, NULL, NULL, &xT )) < 0 ) |
173 | { | 173 | { |
174 | throw Bu::ServerSocketException( | 174 | throw Bu::TcpServerSocketException( |
175 | "Error scanning for new connections: %s", strerror( errno ) | 175 | "Error scanning for new connections: %s", strerror( errno ) |
176 | ); | 176 | ); |
177 | } | 177 | } |
@@ -200,7 +200,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) | |||
200 | #endif /* WIN32 */ | 200 | #endif /* WIN32 */ |
201 | if( nClient < 0 ) | 201 | if( nClient < 0 ) |
202 | { | 202 | { |
203 | throw Bu::ServerSocketException( | 203 | throw Bu::TcpServerSocketException( |
204 | "Error accepting a new connection: %s", strerror( errno ) | 204 | "Error accepting a new connection: %s", strerror( errno ) |
205 | ); | 205 | ); |
206 | } | 206 | } |
@@ -219,7 +219,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) | |||
219 | flags |= O_NONBLOCK; | 219 | flags |= O_NONBLOCK; |
220 | if( fcntl( nClient, F_SETFL, flags ) < 0) | 220 | if( fcntl( nClient, F_SETFL, flags ) < 0) |
221 | { | 221 | { |
222 | throw Bu::ServerSocketException( | 222 | throw Bu::TcpServerSocketException( |
223 | "Error setting option on client socket: %s", | 223 | "Error setting option on client socket: %s", |
224 | strerror( errno ) | 224 | strerror( errno ) |
225 | ); | 225 | ); |
@@ -242,7 +242,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) | |||
242 | return -1; | 242 | return -1; |
243 | } | 243 | } |
244 | 244 | ||
245 | int Bu::ServerSocket::getPort() | 245 | int Bu::TcpServerSocket::getPort() |
246 | { | 246 | { |
247 | return nPort; | 247 | return nPort; |
248 | } | 248 | } |