@@ -29,6 +29,15 @@ typedef int socklen_t;
29
29
#include <emscripten.h>
30
30
#endif
31
31
32
+ #ifdef _WIN32
33
+ typedef u_long ioctlarg_t ;
34
+ #else
35
+ #define INVALID_SOCKET -1
36
+ #define SOCKET_ERROR -1
37
+ #define ioctlsocket ioctl
38
+ typedef int ioctlarg_t ;
39
+ #endif
40
+
32
41
#include "test_sockets_msg.h"
33
42
34
43
typedef enum {
@@ -193,16 +202,16 @@ int main() {
193
202
#else
194
203
server .fd = socket (PF_INET , SOCK_DGRAM , IPPROTO_UDP );
195
204
#endif
196
- if (server .fd == -1 ) {
205
+ if (server .fd == INVALID_SOCKET ) {
197
206
perror ("cannot create socket" );
198
207
exit (EXIT_FAILURE );
199
208
}
200
- #ifdef _WIN32
201
- unsigned long nonblocking = 1 ;
202
- ioctlsocket (server .fd , FIONBIO , & nonblocking );
203
- #else
204
- fcntl ( server . fd , F_SETFL , O_NONBLOCK );
205
- #endif
209
+
210
+ ioctlarg_t on = 1 ;
211
+ if ( ioctlsocket (server .fd , FIONBIO , & nonblocking ) == SOCKET_ERROR ) {
212
+ perror ( "ioctlsocket failed" );
213
+ exit ( EXIT_FAILURE );
214
+ }
206
215
207
216
memset (& addr , 0 , sizeof (addr ));
208
217
addr .sin_family = AF_INET ;
@@ -213,14 +222,14 @@ int main() {
213
222
}
214
223
215
224
res = bind (server .fd , (struct sockaddr * )& addr , sizeof (addr ));
216
- if (res == -1 ) {
225
+ if (res == SOCKET_ERROR ) {
217
226
perror ("bind failed" );
218
227
exit (EXIT_FAILURE );
219
228
}
220
229
221
230
#if !TEST_DGRAM
222
231
res = listen (server .fd , 50 );
223
- if (res == -1 ) {
232
+ if (res == SOCKET_ERROR ) {
224
233
perror ("listen failed" );
225
234
exit (EXIT_FAILURE );
226
235
}
0 commit comments