diff options
Diffstat (limited to 'src/serversocket.cpp')
-rw-r--r-- | src/serversocket.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/serversocket.cpp b/src/serversocket.cpp index 6f7fc00..5ed661e 100644 --- a/src/serversocket.cpp +++ b/src/serversocket.cpp | |||
@@ -5,6 +5,13 @@ | |||
5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #ifndef WIN32 | ||
9 | #include <sys/socket.h> | ||
10 | #include <netinet/in.h> | ||
11 | #include <netdb.h> | ||
12 | #include <arpa/inet.h> | ||
13 | #endif | ||
14 | |||
8 | #include <time.h> | 15 | #include <time.h> |
9 | #include <string.h> | 16 | #include <string.h> |
10 | #include <stdio.h> | 17 | #include <stdio.h> |
@@ -12,14 +19,11 @@ | |||
12 | #include <stdlib.h> | 19 | #include <stdlib.h> |
13 | #include <unistd.h> | 20 | #include <unistd.h> |
14 | #include <sys/types.h> | 21 | #include <sys/types.h> |
15 | #include <sys/socket.h> | 22 | //#include <termios.h> |
16 | #include <termios.h> | ||
17 | #include <netinet/in.h> | ||
18 | #include <netdb.h> | ||
19 | #include <arpa/inet.h> | ||
20 | #include <fcntl.h> | 23 | #include <fcntl.h> |
21 | #include "bu/serversocket.h" | 24 | #include "bu/serversocket.h" |
22 | #include "bu/osx_compatibility.h" | 25 | #include "bu/osx_compatibility.h" |
26 | #include "bu/win32_compatibility.h" | ||
23 | 27 | ||
24 | namespace Bu { subExceptionDef( ServerSocketException ) } | 28 | namespace Bu { subExceptionDef( ServerSocketException ) } |
25 | 29 | ||
@@ -50,7 +54,11 @@ Bu::ServerSocket::ServerSocket(const FString &sAddr,int nPort, int nPoolSize) : | |||
50 | name.sin_family = AF_INET; | 54 | name.sin_family = AF_INET; |
51 | name.sin_port = htons( nPort ); | 55 | name.sin_port = htons( nPort ); |
52 | 56 | ||
57 | #ifdef WIN32 | ||
58 | name.sin_addr.s_addr = inet_addr( sAddr.getStr() ); | ||
59 | #else | ||
53 | inet_aton( sAddr.getStr(), &name.sin_addr ); | 60 | inet_aton( sAddr.getStr(), &name.sin_addr ); |
61 | #endif | ||
54 | 62 | ||
55 | startServer( name, nPoolSize ); | 63 | startServer( name, nPoolSize ); |
56 | } | 64 | } |
@@ -139,14 +147,17 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) | |||
139 | "Error accepting a new connection: %s", strerror( errno ) | 147 | "Error accepting a new connection: %s", strerror( errno ) |
140 | ); | 148 | ); |
141 | } | 149 | } |
150 | |||
151 | #ifndef WIN32 | ||
142 | char tmpa[20]; | 152 | char tmpa[20]; |
143 | inet_ntop( AF_INET, (void *)&clientname.sin_addr, tmpa, 20 ); | 153 | inet_ntop( AF_INET, (void *)&clientname.sin_addr, tmpa, 20 ); |
144 | //"New connection from host %s, port %hd.", | 154 | //"New connection from host %s, port %hd.", |
145 | // tmpa, ntohs (clientname.sin_port) ); | 155 | // tmpa, ntohs (clientname.sin_port) ); |
156 | #endif | ||
146 | 157 | ||
147 | { | 158 | { |
159 | #ifndef WIN32 | ||
148 | int flags; | 160 | int flags; |
149 | |||
150 | flags = fcntl( nClient, F_GETFL, 0 ); | 161 | flags = fcntl( nClient, F_GETFL, 0 ); |
151 | flags |= O_NONBLOCK; | 162 | flags |= O_NONBLOCK; |
152 | if( fcntl( nClient, F_SETFL, flags ) < 0) | 163 | if( fcntl( nClient, F_SETFL, flags ) < 0) |
@@ -156,6 +167,16 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) | |||
156 | strerror( errno ) | 167 | strerror( errno ) |
157 | ); | 168 | ); |
158 | } | 169 | } |
170 | #else | ||
171 | //------------------------- | ||
172 | // Set the socket I/O mode: In this case FIONBIO | ||
173 | // enables or disables the blocking mode for the | ||
174 | // socket based on the numerical value of iMode. | ||
175 | // If iMode = 0, blocking is enabled; | ||
176 | // If iMode != 0, non-blocking mode is enabled. | ||
177 | u_long iMode = 1; | ||
178 | ioctlsocket(nClient, FIONBIO, &iMode); | ||
179 | #endif | ||
159 | } | 180 | } |
160 | 181 | ||
161 | return nClient; | 182 | return nClient; |