aboutsummaryrefslogtreecommitdiff
path: root/src/tcpserversocket.cpp
diff options
context:
space:
mode:
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
28namespace Bu { subExceptionDef( ServerSocketException ) } 28namespace Bu { subExceptionDef( TcpServerSocketException ) }
29 29
30Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : 30Bu::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
51Bu::ServerSocket::ServerSocket(const FString &sAddr,int nPort, int nPoolSize) : 51Bu::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
75Bu::ServerSocket::ServerSocket( int nServer, bool bInit, int nPoolSize ) : 75Bu::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
98Bu::ServerSocket::ServerSocket( const ServerSocket &rSrc ) 98Bu::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
110Bu::ServerSocket::~ServerSocket() 110Bu::TcpServerSocket::~TcpServerSocket()
111{ 111{
112 if( nServer > -1 ) 112 if( nServer > -1 )
113 ::close( nServer ); 113 ::close( nServer );
114} 114}
115 115
116void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) 116void 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
138void Bu::ServerSocket::initServer( struct sockaddr_in &name, int nPoolSize ) 138void 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
157int Bu::ServerSocket::getSocket() 157int Bu::TcpServerSocket::getSocket()
158{ 158{
159 return nServer; 159 return nServer;
160} 160}
161 161
162int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) 162int 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
245int Bu::ServerSocket::getPort() 245int Bu::TcpServerSocket::getPort()
246{ 246{
247 return nPort; 247 return nPort;
248} 248}