aboutsummaryrefslogtreecommitdiff
path: root/src/serversocket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/serversocket.cpp')
-rw-r--r--src/serversocket.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/serversocket.cpp b/src/serversocket.cpp
index 946d0d3..89fef7e 100644
--- a/src/serversocket.cpp
+++ b/src/serversocket.cpp
@@ -24,6 +24,7 @@
24#include "bu/serversocket.h" 24#include "bu/serversocket.h"
25#include "bu/osx_compatibility.h" 25#include "bu/osx_compatibility.h"
26#include "bu/win32_compatibility.h" 26#include "bu/win32_compatibility.h"
27#include "bu/linux_compatibility.h"
27 28
28namespace Bu { subExceptionDef( ServerSocketException ) } 29namespace Bu { subExceptionDef( ServerSocketException ) }
29 30
@@ -35,11 +36,11 @@ Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) :
35 36
36 /* Give the socket a name. */ 37 /* Give the socket a name. */
37 name.sin_family = AF_INET; 38 name.sin_family = AF_INET;
38 name.sin_port = DYNLOAD htons( nPort ); 39 name.sin_port = bu_htons( nPort );
39 40
40 // I think this specifies who we will accept connections from, 41 // I think this specifies who we will accept connections from,
41 // a good thing to make configurable later on 42 // a good thing to make configurable later on
42 name.sin_addr.s_addr = DYNLOAD htonl( INADDR_ANY ); 43 name.sin_addr.s_addr = bu_htonl( INADDR_ANY );
43 44
44 startServer( name, nPoolSize ); 45 startServer( name, nPoolSize );
45} 46}
@@ -53,10 +54,10 @@ Bu::ServerSocket::ServerSocket(const FString &sAddr,int nPort, int nPoolSize) :
53 /* Give the socket a name. */ 54 /* Give the socket a name. */
54 name.sin_family = AF_INET; 55 name.sin_family = AF_INET;
55 56
56 name.sin_port = DYNLOAD htons( nPort ); 57 name.sin_port = bu_htons( nPort );
57 58
58#ifdef WIN32 59#ifdef WIN32
59 name.sin_addr.s_addr = DYNLOAD inet_addr( sAddr.getStr() ); 60 name.sin_addr.s_addr = bu_inet_addr( sAddr.getStr() );
60#else 61#else
61 inet_aton( sAddr.getStr(), &name.sin_addr ); 62 inet_aton( sAddr.getStr(), &name.sin_addr );
62#endif 63#endif
@@ -72,7 +73,7 @@ Bu::ServerSocket::~ServerSocket()
72void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) 73void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize )
73{ 74{
74 /* Create the socket. */ 75 /* Create the socket. */
75 nServer = DYNLOAD socket( PF_INET, SOCK_STREAM, 0 ); 76 nServer = bu_socket( PF_INET, SOCK_STREAM, 0 );
76 77
77 if( nServer < 0 ) 78 if( nServer < 0 )
78 { 79 {
@@ -80,7 +81,7 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize )
80 } 81 }
81 82
82 int opt = 1; 83 int opt = 1;
83 DYNLOAD setsockopt( 84 bu_setsockopt(
84 nServer, 85 nServer,
85 SOL_SOCKET, 86 SOL_SOCKET,
86 SO_REUSEADDR, 87 SO_REUSEADDR,
@@ -88,13 +89,12 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize )
88 sizeof( opt ) 89 sizeof( opt )
89 ); 90 );
90 91
91 if( DYNLOAD bind( 92 if( bu_bind( nServer, (struct sockaddr *) &name, sizeof(name) ) < 0 )
92 nServer, (struct sockaddr *) &name, sizeof(name) ) < 0 )
93 { 93 {
94 throw Bu::ServerSocketException("Couldn't bind to the listen socket."); 94 throw Bu::ServerSocketException("Couldn't bind to the listen socket.");
95 } 95 }
96 96
97 if( DYNLOAD listen( nServer, nPoolSize ) < 0 ) 97 if( bu_listen( nServer, nPoolSize ) < 0 )
98 { 98 {
99 throw Bu::ServerSocketException( 99 throw Bu::ServerSocketException(
100 "Couldn't begin listening to the server socket." 100 "Couldn't begin listening to the server socket."
@@ -121,18 +121,14 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec )
121 xT.tv_usec = nTimeoutUSec; 121 xT.tv_usec = nTimeoutUSec;
122 122
123 if( TEMP_FAILURE_RETRY( 123 if( TEMP_FAILURE_RETRY(
124 DYNLOAD select( nServer+1, &fdRead, NULL, NULL, &xT )) < 0 ) 124 bu_select( nServer+1, &fdRead, NULL, NULL, &xT )) < 0 )
125 { 125 {
126 throw Bu::ServerSocketException( 126 throw Bu::ServerSocketException(
127 "Error scanning for new connections: %s", strerror( errno ) 127 "Error scanning for new connections: %s", strerror( errno )
128 ); 128 );
129 } 129 }
130 130
131#ifdef WIN32
132 if( DynamicWinsock2::DYN_FD_ISSET( nServer, &fdRead ) )
133#else
134 if( FD_ISSET( nServer, &fdRead ) ) 131 if( FD_ISSET( nServer, &fdRead ) )
135#endif
136 { 132 {
137 struct sockaddr_in clientname; 133 struct sockaddr_in clientname;
138 socklen_t size; 134 socklen_t size;
@@ -140,8 +136,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec )
140 136
141 size = sizeof( clientname ); 137 size = sizeof( clientname );
142#ifdef WIN32 138#ifdef WIN32
143 nClient = DYNLOAD accept( 139 nClient = bu_accept( nServer, (struct sockaddr *)&clientname, &size);
144 nServer, (struct sockaddr *)&clientname, (int *)&size);
145#else /* not-WIN32 */ 140#else /* not-WIN32 */
146#ifdef __CYGWIN__ 141#ifdef __CYGWIN__
147 nClient = ::accept( nServer, (struct sockaddr *)&clientname, 142 nClient = ::accept( nServer, (struct sockaddr *)&clientname,
@@ -189,7 +184,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec )
189 // If iMode = 0, blocking is enabled; 184 // If iMode = 0, blocking is enabled;
190 // If iMode != 0, non-blocking mode is enabled. 185 // If iMode != 0, non-blocking mode is enabled.
191 u_long iMode = 1; 186 u_long iMode = 1;
192 DYNLOAD ioctlsocket(nClient, FIONBIO, &iMode); 187 bu_ioctlsocket(nClient, FIONBIO, &iMode);
193#endif 188#endif
194 } 189 }
195 190