diff options
Diffstat (limited to 'src/util/network.c')
-rw-r--r-- | src/util/network.c | 576 |
1 files changed, 341 insertions, 235 deletions
diff --git a/src/util/network.c b/src/util/network.c index 6ce3df1c2..b533ce183 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -82,25 +82,27 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock) | |||
82 | 82 | ||
83 | #if MINGW | 83 | #if MINGW |
84 | u_long mode; | 84 | u_long mode; |
85 | |||
85 | mode = !doBlock; | 86 | mode = !doBlock; |
86 | if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR) | 87 | if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR) |
87 | 88 | ||
88 | { | 89 | { |
89 | SetErrnoFromWinsockError (WSAGetLastError ()); | 90 | SetErrnoFromWinsockError (WSAGetLastError ()); |
90 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); | 91 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); |
91 | return GNUNET_SYSERR; | 92 | return GNUNET_SYSERR; |
92 | } | 93 | } |
93 | return GNUNET_OK; | 94 | return GNUNET_OK; |
94 | 95 | ||
95 | #else | 96 | #else |
96 | /* not MINGW */ | 97 | /* not MINGW */ |
97 | int flags = fcntl (fd->fd, F_GETFL); | 98 | int flags = fcntl (fd->fd, F_GETFL); |
99 | |||
98 | if (flags == -1) | 100 | if (flags == -1) |
99 | 101 | ||
100 | { | 102 | { |
101 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); | 103 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); |
102 | return GNUNET_SYSERR; | 104 | return GNUNET_SYSERR; |
103 | } | 105 | } |
104 | if (doBlock) | 106 | if (doBlock) |
105 | flags &= ~O_NONBLOCK; | 107 | flags &= ~O_NONBLOCK; |
106 | 108 | ||
@@ -108,10 +110,10 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock) | |||
108 | flags |= O_NONBLOCK; | 110 | flags |= O_NONBLOCK; |
109 | if (0 != fcntl (fd->fd, F_SETFL, flags)) | 111 | if (0 != fcntl (fd->fd, F_SETFL, flags)) |
110 | 112 | ||
111 | { | 113 | { |
112 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); | 114 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); |
113 | return GNUNET_SYSERR; | 115 | return GNUNET_SYSERR; |
114 | } | 116 | } |
115 | return GNUNET_OK; | 117 | return GNUNET_OK; |
116 | #endif | 118 | #endif |
117 | } | 119 | } |
@@ -130,7 +132,7 @@ socket_set_inheritable (const struct GNUNET_NETWORK_Handle *h) | |||
130 | { | 132 | { |
131 | int i; | 133 | int i; |
132 | 134 | ||
133 | i = fcntl (h->fd, F_GETFD); | 135 | i = fcntl (h->fd, F_GETFD); |
134 | if (i < 0) | 136 | if (i < 0) |
135 | return GNUNET_SYSERR; | 137 | return GNUNET_SYSERR; |
136 | if (i == (i | FD_CLOEXEC)) | 138 | if (i == (i | FD_CLOEXEC)) |
@@ -153,8 +155,10 @@ static void | |||
153 | socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h) | 155 | socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h) |
154 | { | 156 | { |
155 | int abs_value = 1; | 157 | int abs_value = 1; |
158 | |||
156 | if (0 != | 159 | if (0 != |
157 | setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value, sizeof (abs_value))) | 160 | setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value, |
161 | sizeof (abs_value))) | ||
158 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 162 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
159 | } | 163 | } |
160 | #endif | 164 | #endif |
@@ -170,15 +174,19 @@ socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h) | |||
170 | static void | 174 | static void |
171 | socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h) | 175 | socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h) |
172 | { | 176 | { |
173 | #ifndef WINDOWS | 177 | #ifndef WINDOWS |
174 | int value = 1; | 178 | int value = 1; |
179 | |||
175 | if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value))) | 180 | if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value))) |
176 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 181 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
177 | #else | 182 | #else |
178 | const char * abs_value = "1"; | 183 | const char *abs_value = "1"; |
179 | if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value, sizeof (abs_value))) | 184 | |
185 | if (0 != | ||
186 | setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value, | ||
187 | sizeof (abs_value))) | ||
180 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 188 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
181 | #endif | 189 | #endif |
182 | } | 190 | } |
183 | 191 | ||
184 | 192 | ||
@@ -192,8 +200,7 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h) | |||
192 | */ | 200 | */ |
193 | struct GNUNET_NETWORK_Handle * | 201 | struct GNUNET_NETWORK_Handle * |
194 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | 202 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, |
195 | struct sockaddr *address, | 203 | struct sockaddr *address, socklen_t * address_len) |
196 | socklen_t * address_len) | ||
197 | { | 204 | { |
198 | struct GNUNET_NETWORK_Handle *ret; | 205 | struct GNUNET_NETWORK_Handle *ret; |
199 | 206 | ||
@@ -203,10 +210,11 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
203 | struct sockaddr name; | 210 | struct sockaddr name; |
204 | int namelen = sizeof (name); | 211 | int namelen = sizeof (name); |
205 | int gsn = getsockname (desc->fd, &name, &namelen); | 212 | int gsn = getsockname (desc->fd, &name, &namelen); |
213 | |||
206 | if (gsn == 0) | 214 | if (gsn == 0) |
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
208 | "Accepting connection on `%s'\n", | 216 | "Accepting connection on `%s'\n", |
209 | GNUNET_a2s (&name, namelen)); | 217 | GNUNET_a2s (&name, namelen)); |
210 | } | 218 | } |
211 | #endif | 219 | #endif |
212 | ret->fd = accept (desc->fd, address, address_len); | 220 | ret->fd = accept (desc->fd, address, address_len); |
@@ -215,31 +223,31 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
215 | else | 223 | else |
216 | ret->af = desc->af; | 224 | ret->af = desc->af; |
217 | if (ret->fd == INVALID_SOCKET) | 225 | if (ret->fd == INVALID_SOCKET) |
218 | { | 226 | { |
219 | #ifdef MINGW | 227 | #ifdef MINGW |
220 | SetErrnoFromWinsockError (WSAGetLastError ()); | 228 | SetErrnoFromWinsockError (WSAGetLastError ()); |
221 | #endif | 229 | #endif |
222 | GNUNET_free (ret); | 230 | GNUNET_free (ret); |
223 | return NULL; | 231 | return NULL; |
224 | } | 232 | } |
225 | #ifndef MINGW | 233 | #ifndef MINGW |
226 | if (ret->fd >= FD_SETSIZE) | 234 | if (ret->fd >= FD_SETSIZE) |
227 | { | 235 | { |
228 | GNUNET_break (0 == close (ret->fd)); | 236 | GNUNET_break (0 == close (ret->fd)); |
229 | GNUNET_free (ret); | 237 | GNUNET_free (ret); |
230 | errno = EMFILE; | 238 | errno = EMFILE; |
231 | return NULL; | 239 | return NULL; |
232 | } | 240 | } |
233 | #endif | 241 | #endif |
234 | if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) | 242 | if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) |
235 | 243 | ||
236 | { | 244 | { |
237 | 245 | ||
238 | /* we might want to treat this one as fatal... */ | 246 | /* we might want to treat this one as fatal... */ |
239 | GNUNET_break (0); | 247 | GNUNET_break (0); |
240 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); | 248 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); |
241 | return NULL; | 249 | return NULL; |
242 | } | 250 | } |
243 | 251 | ||
244 | #ifndef MINGW | 252 | #ifndef MINGW |
245 | if (GNUNET_OK != socket_set_inheritable (ret)) | 253 | if (GNUNET_OK != socket_set_inheritable (ret)) |
@@ -270,10 +278,11 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
270 | socklen_t address_len) | 278 | socklen_t address_len) |
271 | { | 279 | { |
272 | int ret; | 280 | int ret; |
273 | 281 | ||
274 | #ifdef IPV6_V6ONLY | 282 | #ifdef IPV6_V6ONLY |
275 | #ifdef IPPROTO_IPV6 | 283 | #ifdef IPPROTO_IPV6 |
276 | const int on = 1; | 284 | const int on = 1; |
285 | |||
277 | if (desc->af == AF_INET6) | 286 | if (desc->af == AF_INET6) |
278 | if (0 != setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on))) | 287 | if (0 != setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on))) |
279 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); | 288 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); |
@@ -287,10 +296,11 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
287 | #ifndef LINUX | 296 | #ifndef LINUX |
288 | #ifndef MINGW | 297 | #ifndef MINGW |
289 | if (address->sa_family == AF_UNIX) | 298 | if (address->sa_family == AF_UNIX) |
290 | { | 299 | { |
291 | const struct sockaddr_un *un = (const struct sockaddr_un*) address; | 300 | const struct sockaddr_un *un = (const struct sockaddr_un *) address; |
292 | (void) unlink (un->sun_path); | 301 | |
293 | } | 302 | (void) unlink (un->sun_path); |
303 | } | ||
294 | #endif | 304 | #endif |
295 | #endif | 305 | #endif |
296 | ret = bind (desc->fd, address, address_len); | 306 | ret = bind (desc->fd, address, address_len); |
@@ -323,29 +333,33 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | |||
323 | 333 | ||
324 | #ifdef MINGW | 334 | #ifdef MINGW |
325 | DWORD error = 0; | 335 | DWORD error = 0; |
336 | |||
326 | #if DEBUG_NETWORK | 337 | #if DEBUG_NETWORK |
327 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", "Closing 0x%x\n", desc->fd); | 338 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", |
339 | "Closing 0x%x\n", desc->fd); | ||
328 | #endif | 340 | #endif |
329 | SetLastError (0); | 341 | SetLastError (0); |
330 | ret = closesocket (desc->fd); | 342 | ret = closesocket (desc->fd); |
331 | error = WSAGetLastError (); | 343 | error = WSAGetLastError (); |
332 | SetErrnoFromWinsockError (error); | 344 | SetErrnoFromWinsockError (error); |
333 | #if DEBUG_NETWORK | 345 | #if DEBUG_NETWORK |
334 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", "Closed 0x%x, closesocket() returned %d, GLE is %u\n", desc->fd, ret, error); | 346 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", |
347 | "Closed 0x%x, closesocket() returned %d, GLE is %u\n", | ||
348 | desc->fd, ret, error); | ||
335 | #endif | 349 | #endif |
336 | #else | 350 | #else |
337 | ret = close (desc->fd); | 351 | ret = close (desc->fd); |
338 | #endif | 352 | #endif |
339 | #ifndef LINUX | 353 | #ifndef LINUX |
340 | #ifndef MINGW | 354 | #ifndef MINGW |
341 | if ( (desc->af == AF_UNIX) && (NULL != desc->addr) ) | 355 | if ((desc->af == AF_UNIX) && (NULL != desc->addr)) |
342 | { | 356 | { |
343 | const struct sockaddr_un *un = (const struct sockaddr_un*) desc->addr; | 357 | const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; |
344 | if (0 != unlink (un->sun_path)) | 358 | |
345 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 359 | if (0 != unlink (un->sun_path)) |
346 | "unlink", | 360 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
347 | un->sun_path); | 361 | "unlink", un->sun_path); |
348 | } | 362 | } |
349 | #endif | 363 | #endif |
350 | #endif | 364 | #endif |
351 | GNUNET_free_non_null (desc->addr); | 365 | GNUNET_free_non_null (desc->addr); |
@@ -369,8 +383,8 @@ GNUNET_NETWORK_socket_box_native (int fd) | |||
369 | struct GNUNET_NETWORK_Handle *ret; | 383 | struct GNUNET_NETWORK_Handle *ret; |
370 | 384 | ||
371 | if (fcntl (fd, F_GETFD) < 0) | 385 | if (fcntl (fd, F_GETFD) < 0) |
372 | return NULL; /* invalid FD */ | 386 | return NULL; /* invalid FD */ |
373 | ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); | 387 | ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); |
374 | ret->fd = fd; | 388 | ret->fd = fd; |
375 | ret->af = AF_UNSPEC; | 389 | ret->af = AF_UNSPEC; |
376 | return ret; | 390 | return ret; |
@@ -391,15 +405,16 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, | |||
391 | socklen_t address_len) | 405 | socklen_t address_len) |
392 | { | 406 | { |
393 | int ret; | 407 | int ret; |
408 | |||
394 | ret = connect (desc->fd, address, address_len); | 409 | ret = connect (desc->fd, address, address_len); |
395 | 410 | ||
396 | #ifdef MINGW | 411 | #ifdef MINGW |
397 | if (SOCKET_ERROR == ret) | 412 | if (SOCKET_ERROR == ret) |
398 | { | 413 | { |
399 | SetErrnoFromWinsockError (WSAGetLastError ()); | 414 | SetErrnoFromWinsockError (WSAGetLastError ()); |
400 | if (errno == EWOULDBLOCK) | 415 | if (errno == EWOULDBLOCK) |
401 | errno = EINPROGRESS; | 416 | errno = EINPROGRESS; |
402 | } | 417 | } |
403 | #endif | 418 | #endif |
404 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; | 419 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; |
405 | } | 420 | } |
@@ -421,6 +436,7 @@ GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, | |||
421 | socklen_t * optlen) | 436 | socklen_t * optlen) |
422 | { | 437 | { |
423 | int ret; | 438 | int ret; |
439 | |||
424 | ret = getsockopt (desc->fd, level, optname, optval, optlen); | 440 | ret = getsockopt (desc->fd, level, optname, optval, optlen); |
425 | 441 | ||
426 | #ifdef MINGW | 442 | #ifdef MINGW |
@@ -445,6 +461,7 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, | |||
445 | int backlog) | 461 | int backlog) |
446 | { | 462 | { |
447 | int ret; | 463 | int ret; |
464 | |||
448 | ret = listen (desc->fd, backlog); | 465 | ret = listen (desc->fd, backlog); |
449 | 466 | ||
450 | #ifdef MINGW | 467 | #ifdef MINGW |
@@ -464,17 +481,19 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, | |||
464 | */ | 481 | */ |
465 | ssize_t | 482 | ssize_t |
466 | GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle | 483 | GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle |
467 | *desc) | 484 | * desc) |
468 | { | 485 | { |
469 | int error; | 486 | int error; |
470 | 487 | ||
471 | /* How much is there to be read? */ | 488 | /* How much is there to be read? */ |
472 | #ifndef WINDOWS | 489 | #ifndef WINDOWS |
473 | int pending; | 490 | int pending; |
491 | |||
474 | error = ioctl (desc->fd, FIONREAD, &pending); | 492 | error = ioctl (desc->fd, FIONREAD, &pending); |
475 | if (error == 0) | 493 | if (error == 0) |
476 | #else | 494 | #else |
477 | u_long pending; | 495 | u_long pending; |
496 | |||
478 | error = ioctlsocket (desc->fd, FIONREAD, &pending); | 497 | error = ioctlsocket (desc->fd, FIONREAD, &pending); |
479 | if (error != SOCKET_ERROR) | 498 | if (error != SOCKET_ERROR) |
480 | #endif | 499 | #endif |
@@ -496,11 +515,11 @@ GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle | |||
496 | ssize_t | 515 | ssize_t |
497 | GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, | 516 | GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, |
498 | void *buffer, size_t length, | 517 | void *buffer, size_t length, |
499 | struct sockaddr * src_addr, | 518 | struct sockaddr * src_addr, socklen_t * addrlen) |
500 | socklen_t * addrlen) | ||
501 | { | 519 | { |
502 | int ret; | 520 | int ret; |
503 | int flags; | 521 | int flags; |
522 | |||
504 | flags = 0; | 523 | flags = 0; |
505 | 524 | ||
506 | #ifdef MSG_DONTWAIT | 525 | #ifdef MSG_DONTWAIT |
@@ -511,7 +530,7 @@ GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, | |||
511 | #ifdef MINGW | 530 | #ifdef MINGW |
512 | if (SOCKET_ERROR == ret) | 531 | if (SOCKET_ERROR == ret) |
513 | SetErrnoFromWinsockError (WSAGetLastError ()); | 532 | SetErrnoFromWinsockError (WSAGetLastError ()); |
514 | #endif | 533 | #endif |
515 | return ret; | 534 | return ret; |
516 | } | 535 | } |
517 | 536 | ||
@@ -528,6 +547,7 @@ GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, | |||
528 | { | 547 | { |
529 | int ret; | 548 | int ret; |
530 | int flags; | 549 | int flags; |
550 | |||
531 | flags = 0; | 551 | flags = 0; |
532 | 552 | ||
533 | #ifdef MSG_DONTWAIT | 553 | #ifdef MSG_DONTWAIT |
@@ -556,6 +576,7 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, | |||
556 | { | 576 | { |
557 | int ret; | 577 | int ret; |
558 | int flags; | 578 | int flags; |
579 | |||
559 | flags = 0; | 580 | flags = 0; |
560 | 581 | ||
561 | #ifdef MSG_DONTWAIT | 582 | #ifdef MSG_DONTWAIT |
@@ -596,6 +617,7 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, | |||
596 | { | 617 | { |
597 | int ret; | 618 | int ret; |
598 | int flags; | 619 | int flags; |
620 | |||
599 | flags = 0; | 621 | flags = 0; |
600 | 622 | ||
601 | #ifdef MSG_DONTWAIT | 623 | #ifdef MSG_DONTWAIT |
@@ -658,31 +680,31 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol) | |||
658 | ret->af = domain; | 680 | ret->af = domain; |
659 | ret->fd = socket (domain, type, protocol); | 681 | ret->fd = socket (domain, type, protocol); |
660 | if (INVALID_SOCKET == ret->fd) | 682 | if (INVALID_SOCKET == ret->fd) |
661 | { | 683 | { |
662 | #ifdef MINGW | 684 | #ifdef MINGW |
663 | SetErrnoFromWinsockError (WSAGetLastError ()); | 685 | SetErrnoFromWinsockError (WSAGetLastError ()); |
664 | #endif | 686 | #endif |
665 | GNUNET_free (ret); | 687 | GNUNET_free (ret); |
666 | return NULL; | 688 | return NULL; |
667 | } | 689 | } |
668 | 690 | ||
669 | #ifndef MINGW | 691 | #ifndef MINGW |
670 | if (ret->fd >= FD_SETSIZE) | 692 | if (ret->fd >= FD_SETSIZE) |
671 | { | 693 | { |
672 | GNUNET_break (0 == close (ret->fd)); | 694 | GNUNET_break (0 == close (ret->fd)); |
673 | GNUNET_free (ret); | 695 | GNUNET_free (ret); |
674 | errno = EMFILE; | 696 | errno = EMFILE; |
675 | return NULL; | 697 | return NULL; |
676 | } | 698 | } |
677 | 699 | ||
678 | #endif | 700 | #endif |
679 | if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) | 701 | if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) |
680 | { | 702 | { |
681 | /* we might want to treat this one as fatal... */ | 703 | /* we might want to treat this one as fatal... */ |
682 | GNUNET_break (0); | 704 | GNUNET_break (0); |
683 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); | 705 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); |
684 | return NULL; | 706 | return NULL; |
685 | } | 707 | } |
686 | 708 | ||
687 | #ifndef MINGW | 709 | #ifndef MINGW |
688 | if (GNUNET_OK != socket_set_inheritable (ret)) | 710 | if (GNUNET_OK != socket_set_inheritable (ret)) |
@@ -692,11 +714,11 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol) | |||
692 | #ifdef DARWIN | 714 | #ifdef DARWIN |
693 | socket_set_nosigpipe (ret); | 715 | socket_set_nosigpipe (ret); |
694 | #endif | 716 | #endif |
695 | if ( (type == SOCK_STREAM) | 717 | if ((type == SOCK_STREAM) |
696 | #ifdef AF_UNIX | 718 | #ifdef AF_UNIX |
697 | && (domain != AF_UNIX) | 719 | && (domain != AF_UNIX) |
698 | #endif | 720 | #endif |
699 | ) | 721 | ) |
700 | socket_set_nodelay (ret); | 722 | socket_set_nodelay (ret); |
701 | return ret; | 723 | return ret; |
702 | } | 724 | } |
@@ -736,15 +758,26 @@ GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc) | |||
736 | { | 758 | { |
737 | int value = 0; | 759 | int value = 0; |
738 | int ret = 0; | 760 | int ret = 0; |
761 | |||
739 | #if WINDOWS | 762 | #if WINDOWS |
740 | if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value, sizeof (value)))) | 763 | if (0 != |
764 | (ret = | ||
765 | setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value, | ||
766 | sizeof (value)))) | ||
741 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 767 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
742 | if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value, sizeof (value)))) | 768 | if (0 != |
769 | (ret = | ||
770 | setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value, | ||
771 | sizeof (value)))) | ||
743 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 772 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
744 | #else | 773 | #else |
745 | if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof (value)))) | 774 | if (0 != |
775 | (ret = | ||
776 | setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof (value)))) | ||
746 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 777 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
747 | if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof (value)))) | 778 | if (0 != |
779 | (ret = | ||
780 | setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof (value)))) | ||
748 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 781 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
749 | #endif | 782 | #endif |
750 | 783 | ||
@@ -805,14 +838,15 @@ GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, | |||
805 | const struct GNUNET_NETWORK_FDSet *src) | 838 | const struct GNUNET_NETWORK_FDSet *src) |
806 | { | 839 | { |
807 | int nfds; | 840 | int nfds; |
841 | |||
808 | for (nfds = src->nsds; nfds > 0; nfds--) | 842 | for (nfds = src->nsds; nfds > 0; nfds--) |
809 | if (FD_ISSET (nfds, &src->sds)) | 843 | if (FD_ISSET (nfds, &src->sds)) |
810 | 844 | ||
811 | { | 845 | { |
812 | FD_SET (nfds, &dst->sds); | 846 | FD_SET (nfds, &dst->sds); |
813 | if (nfds + 1 > dst->nsds) | 847 | if (nfds + 1 > dst->nsds) |
814 | dst->nsds = nfds + 1; | 848 | dst->nsds = nfds + 1; |
815 | } | 849 | } |
816 | #ifdef MINGW | 850 | #ifdef MINGW |
817 | GNUNET_CONTAINER_slist_append (dst->handles, src->handles); | 851 | GNUNET_CONTAINER_slist_append (dst->handles, src->handles); |
818 | #endif | 852 | #endif |
@@ -874,10 +908,10 @@ GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, | |||
874 | * @param to destination | 908 | * @param to destination |
875 | * @param nfd native FD to set | 909 | * @param nfd native FD to set |
876 | */ | 910 | */ |
877 | void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, | 911 | void |
878 | int nfd) | 912 | GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, int nfd) |
879 | { | 913 | { |
880 | GNUNET_assert((nfd >= 0) && (nfd < FD_SETSIZE)); | 914 | GNUNET_assert ((nfd >= 0) && (nfd < FD_SETSIZE)); |
881 | FD_SET (nfd, &to->sds); | 915 | FD_SET (nfd, &to->sds); |
882 | to->nsds = GNUNET_MAX (nfd + 1, to->nsds); | 916 | to->nsds = GNUNET_MAX (nfd + 1, to->nsds); |
883 | } | 917 | } |
@@ -890,11 +924,11 @@ void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, | |||
890 | * @param nfd native FD to test, or -1 for none | 924 | * @param nfd native FD to test, or -1 for none |
891 | * @return GNUNET_YES if FD is set in the set | 925 | * @return GNUNET_YES if FD is set in the set |
892 | */ | 926 | */ |
893 | int | 927 | int |
894 | GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to, | 928 | GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to, |
895 | int nfd) | 929 | int nfd) |
896 | { | 930 | { |
897 | if ( (nfd == -1) || (to == NULL) ) | 931 | if ((nfd == -1) || (to == NULL)) |
898 | return GNUNET_NO; | 932 | return GNUNET_NO; |
899 | return FD_ISSET (nfd, &to->sds) ? GNUNET_YES : GNUNET_NO; | 933 | return FD_ISSET (nfd, &to->sds) ? GNUNET_YES : GNUNET_NO; |
900 | } | 934 | } |
@@ -916,6 +950,7 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, | |||
916 | 950 | ||
917 | #else | 951 | #else |
918 | int fd; | 952 | int fd; |
953 | |||
919 | GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int)); | 954 | GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int)); |
920 | FD_SET (fd, &fds->sds); | 955 | FD_SET (fd, &fds->sds); |
921 | if (fd + 1 > fds->nsds) | 956 | if (fd + 1 > fds->nsds) |
@@ -938,7 +973,8 @@ GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, | |||
938 | 973 | ||
939 | #ifdef MINGW | 974 | #ifdef MINGW |
940 | return GNUNET_CONTAINER_slist_contains (fds->handles, h, | 975 | return GNUNET_CONTAINER_slist_contains (fds->handles, h, |
941 | sizeof (struct GNUNET_DISK_FileHandle)); | 976 | sizeof (struct |
977 | GNUNET_DISK_FileHandle)); | ||
942 | #else | 978 | #else |
943 | return FD_ISSET (h->fd, &fds->sds); | 979 | return FD_ISSET (h->fd, &fds->sds); |
944 | #endif | 980 | #endif |
@@ -962,11 +998,11 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, | |||
962 | if (nfds > fds2->nsds) | 998 | if (nfds > fds2->nsds) |
963 | nfds = fds2->nsds; | 999 | nfds = fds2->nsds; |
964 | while (nfds > 0) | 1000 | while (nfds > 0) |
965 | { | 1001 | { |
966 | nfds--; | 1002 | nfds--; |
967 | if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) | 1003 | if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) |
968 | return GNUNET_YES; | 1004 | return GNUNET_YES; |
969 | } | 1005 | } |
970 | #else | 1006 | #else |
971 | struct GNUNET_CONTAINER_SList_Iterator *it; | 1007 | struct GNUNET_CONTAINER_SList_Iterator *it; |
972 | struct GNUNET_DISK_FileHandle *h; | 1008 | struct GNUNET_DISK_FileHandle *h; |
@@ -974,7 +1010,7 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, | |||
974 | int j; | 1010 | int j; |
975 | 1011 | ||
976 | /*This code is somewhat hacky, we are not supposed to know what's | 1012 | /*This code is somewhat hacky, we are not supposed to know what's |
977 | inside of fd_set; also the O(n^2) is really bad... */ | 1013 | * inside of fd_set; also the O(n^2) is really bad... */ |
978 | 1014 | ||
979 | for (i = 0; i < fds1->sds.fd_count; i++) | 1015 | for (i = 0; i < fds1->sds.fd_count; i++) |
980 | { | 1016 | { |
@@ -986,33 +1022,36 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, | |||
986 | } | 1022 | } |
987 | it = GNUNET_CONTAINER_slist_begin (fds1->handles); | 1023 | it = GNUNET_CONTAINER_slist_begin (fds1->handles); |
988 | while (GNUNET_CONTAINER_slist_end (it) != GNUNET_YES) | 1024 | while (GNUNET_CONTAINER_slist_end (it) != GNUNET_YES) |
989 | { | 1025 | { |
990 | #if DEBUG_NETWORK | 1026 | #if DEBUG_NETWORK |
991 | struct GNUNET_CONTAINER_SList_Iterator *t; | 1027 | struct GNUNET_CONTAINER_SList_Iterator *t; |
992 | #endif | 1028 | #endif |
993 | h = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (it, NULL); | 1029 | h = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (it, NULL); |
994 | #if DEBUG_NETWORK | 1030 | #if DEBUG_NETWORK |
995 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking that FD 0x%x is in another set:\n", h->h); | 1031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
996 | for (t = GNUNET_CONTAINER_slist_begin (fds2->handles); | 1032 | "Checking that FD 0x%x is in another set:\n", h->h); |
997 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | 1033 | for (t = GNUNET_CONTAINER_slist_begin (fds2->handles); |
998 | GNUNET_CONTAINER_slist_next (t)) | 1034 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; |
999 | { | 1035 | GNUNET_CONTAINER_slist_next (t)) |
1000 | struct GNUNET_DISK_FileHandle *fh; | 1036 | { |
1001 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); | 1037 | struct GNUNET_DISK_FileHandle *fh; |
1002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h); | 1038 | |
1003 | } | 1039 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, |
1040 | NULL); | ||
1041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h); | ||
1042 | } | ||
1004 | #endif | 1043 | #endif |
1005 | if (GNUNET_CONTAINER_slist_contains | 1044 | if (GNUNET_CONTAINER_slist_contains |
1006 | (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle))) | 1045 | (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle))) |
1007 | { | 1046 | { |
1008 | #if DEBUG_NETWORK | 1047 | #if DEBUG_NETWORK |
1009 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Match!\n"); | 1048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Match!\n"); |
1010 | #endif | 1049 | #endif |
1011 | GNUNET_CONTAINER_slist_iter_destroy (it); | 1050 | GNUNET_CONTAINER_slist_iter_destroy (it); |
1012 | return GNUNET_YES; | 1051 | return GNUNET_YES; |
1013 | } | ||
1014 | GNUNET_CONTAINER_slist_next (it); | ||
1015 | } | 1052 | } |
1053 | GNUNET_CONTAINER_slist_next (it); | ||
1054 | } | ||
1016 | GNUNET_CONTAINER_slist_iter_destroy (it); | 1055 | GNUNET_CONTAINER_slist_iter_destroy (it); |
1017 | #endif | 1056 | #endif |
1018 | return GNUNET_NO; | 1057 | return GNUNET_NO; |
@@ -1027,6 +1066,7 @@ struct GNUNET_NETWORK_FDSet * | |||
1027 | GNUNET_NETWORK_fdset_create () | 1066 | GNUNET_NETWORK_fdset_create () |
1028 | { | 1067 | { |
1029 | struct GNUNET_NETWORK_FDSet *fds; | 1068 | struct GNUNET_NETWORK_FDSet *fds; |
1069 | |||
1030 | fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet)); | 1070 | fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet)); |
1031 | #ifdef MINGW | 1071 | #ifdef MINGW |
1032 | fds->handles = GNUNET_CONTAINER_slist_create (); | 1072 | fds->handles = GNUNET_CONTAINER_slist_create (); |
@@ -1064,6 +1104,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1064 | const struct GNUNET_TIME_Relative timeout) | 1104 | const struct GNUNET_TIME_Relative timeout) |
1065 | { | 1105 | { |
1066 | int nfds = 0; | 1106 | int nfds = 0; |
1107 | |||
1067 | #ifdef MINGW | 1108 | #ifdef MINGW |
1068 | int handles = 0; | 1109 | int handles = 0; |
1069 | int ex_handles = 0; | 1110 | int ex_handles = 0; |
@@ -1093,6 +1134,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1093 | struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except; | 1134 | struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except; |
1094 | 1135 | ||
1095 | fd_set aread, awrite, aexcept; | 1136 | fd_set aread, awrite, aexcept; |
1137 | |||
1096 | #if DEBUG_NETWORK | 1138 | #if DEBUG_NETWORK |
1097 | fd_set bread, bwrite, bexcept; | 1139 | fd_set bread, bwrite, bexcept; |
1098 | #endif | 1140 | #endif |
@@ -1103,62 +1145,67 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1103 | struct timeval tv; | 1145 | struct timeval tv; |
1104 | #endif | 1146 | #endif |
1105 | if (NULL != rfds) | 1147 | if (NULL != rfds) |
1106 | { | 1148 | { |
1107 | nfds = rfds->nsds; | 1149 | nfds = rfds->nsds; |
1108 | #ifdef MINGW | 1150 | #ifdef MINGW |
1109 | handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles); | 1151 | handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles); |
1110 | #if DEBUG_NETWORK | 1152 | #if DEBUG_NETWORK |
1153 | { | ||
1154 | struct GNUNET_CONTAINER_SList_Iterator *t; | ||
1155 | |||
1156 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); | ||
1157 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | ||
1158 | GNUNET_CONTAINER_slist_next (t)) | ||
1111 | { | 1159 | { |
1112 | struct GNUNET_CONTAINER_SList_Iterator *t; | 1160 | struct GNUNET_DISK_FileHandle *fh; |
1113 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); | 1161 | |
1114 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | 1162 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, |
1115 | GNUNET_CONTAINER_slist_next (t)) | 1163 | NULL); |
1116 | { | 1164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n", |
1117 | struct GNUNET_DISK_FileHandle *fh; | 1165 | fh->h, fh); |
1118 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); | ||
1119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n", fh->h, fh); | ||
1120 | } | ||
1121 | } | 1166 | } |
1167 | } | ||
1122 | #endif | 1168 | #endif |
1123 | #endif | 1169 | #endif |
1124 | } | 1170 | } |
1125 | if (NULL != wfds) | 1171 | if (NULL != wfds) |
1126 | { | 1172 | { |
1127 | nfds = GNUNET_MAX (nfds, wfds->nsds); | 1173 | nfds = GNUNET_MAX (nfds, wfds->nsds); |
1128 | #ifdef MINGW | 1174 | #ifdef MINGW |
1129 | handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles); | 1175 | handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles); |
1130 | #endif | 1176 | #endif |
1131 | } | 1177 | } |
1132 | if (NULL != efds) | 1178 | if (NULL != efds) |
1133 | { | 1179 | { |
1134 | nfds = GNUNET_MAX (nfds, efds->nsds); | 1180 | nfds = GNUNET_MAX (nfds, efds->nsds); |
1135 | #ifdef MINGW | 1181 | #ifdef MINGW |
1136 | handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles); | 1182 | handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles); |
1137 | #endif | 1183 | #endif |
1138 | } | 1184 | } |
1139 | 1185 | ||
1140 | if ((nfds == 0) && (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 1186 | if ((nfds == 0) && |
1187 | (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | ||
1141 | #ifdef MINGW | 1188 | #ifdef MINGW |
1142 | && handles == 0 | 1189 | && handles == 0 |
1143 | #endif | 1190 | #endif |
1144 | ) | 1191 | ) |
1145 | { | 1192 | { |
1146 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1193 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1147 | _ | 1194 | _ |
1148 | ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), | 1195 | ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), |
1149 | "select"); | 1196 | "select"); |
1150 | GNUNET_break (0); | 1197 | GNUNET_break (0); |
1151 | } | 1198 | } |
1152 | #ifndef MINGW | 1199 | #ifndef MINGW |
1153 | tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value; | 1200 | tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value; |
1154 | tv.tv_usec = | 1201 | tv.tv_usec = |
1155 | 1000 * (timeout.rel_value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value)); | 1202 | 1000 * (timeout.rel_value - |
1156 | return select (nfds, | 1203 | (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value)); |
1157 | (rfds != NULL) ? &rfds->sds : NULL, | 1204 | return select (nfds, (rfds != NULL) ? &rfds->sds : NULL, |
1158 | (wfds != NULL) ? &wfds->sds : NULL, | 1205 | (wfds != NULL) ? &wfds->sds : NULL, |
1159 | (efds != NULL) ? &efds->sds : NULL, | 1206 | (efds != NULL) ? &efds->sds : NULL, |
1160 | (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 1207 | (timeout.rel_value == |
1161 | ? NULL : &tv); | 1208 | GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ? NULL : &tv); |
1162 | 1209 | ||
1163 | #else | 1210 | #else |
1164 | #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) | 1211 | #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) |
@@ -1169,10 +1216,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1169 | ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value; | 1216 | ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value; |
1170 | /* select() may be used as a portable way to sleep */ | 1217 | /* select() may be used as a portable way to sleep */ |
1171 | if (!(rfds || wfds || efds)) | 1218 | if (!(rfds || wfds || efds)) |
1172 | { | 1219 | { |
1173 | Sleep (ms_total); | 1220 | Sleep (ms_total); |
1174 | return 0; | 1221 | return 0; |
1175 | } | 1222 | } |
1176 | 1223 | ||
1177 | /* Events for sockets */ | 1224 | /* Events for sockets */ |
1178 | if (!hEventRead) | 1225 | if (!hEventRead) |
@@ -1195,7 +1242,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1195 | hEventPipeWrite = CreateEvent (NULL, TRUE, TRUE, NULL); | 1242 | hEventPipeWrite = CreateEvent (NULL, TRUE, TRUE, NULL); |
1196 | readPipes = 0; | 1243 | readPipes = 0; |
1197 | writePipePos = -1; | 1244 | writePipePos = -1; |
1198 | 1245 | ||
1199 | handles_read = GNUNET_CONTAINER_slist_create (); | 1246 | handles_read = GNUNET_CONTAINER_slist_create (); |
1200 | handles_write = GNUNET_CONTAINER_slist_create (); | 1247 | handles_write = GNUNET_CONTAINER_slist_create (); |
1201 | handles_except = GNUNET_CONTAINER_slist_create (); | 1248 | handles_except = GNUNET_CONTAINER_slist_create (); |
@@ -1233,40 +1280,49 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1233 | if (rfds && read_handles) | 1280 | if (rfds && read_handles) |
1234 | { | 1281 | { |
1235 | struct GNUNET_CONTAINER_SList_Iterator *i; | 1282 | struct GNUNET_CONTAINER_SList_Iterator *i; |
1283 | |||
1236 | for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); | 1284 | for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); |
1237 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; | 1285 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; |
1238 | GNUNET_CONTAINER_slist_next (i)) | 1286 | GNUNET_CONTAINER_slist_next (i)) |
1239 | { | 1287 | { |
1240 | struct GNUNET_DISK_FileHandle *fh; | 1288 | struct GNUNET_DISK_FileHandle *fh; |
1241 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (i, NULL); | 1289 | |
1290 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (i, | ||
1291 | NULL); | ||
1242 | if (fh->type == GNUNET_PIPE) | 1292 | if (fh->type == GNUNET_PIPE) |
1243 | { | 1293 | { |
1244 | /* Read zero bytes to check the status of the pipe */ | 1294 | /* Read zero bytes to check the status of the pipe */ |
1245 | #if DEBUG_NETWORK | 1295 | #if DEBUG_NETWORK |
1246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reading 0 bytes from the pipe 0x%x\n", fh->h); | 1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1297 | "Reading 0 bytes from the pipe 0x%x\n", fh->h); | ||
1247 | #endif | 1298 | #endif |
1248 | if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead)) | 1299 | if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead)) |
1249 | { | 1300 | { |
1250 | DWORD error_code = GetLastError(); | 1301 | DWORD error_code = GetLastError (); |
1302 | |||
1251 | if (error_code == ERROR_IO_PENDING) | 1303 | if (error_code == ERROR_IO_PENDING) |
1252 | { | 1304 | { |
1253 | #if DEBUG_NETWORK | 1305 | #if DEBUG_NETWORK |
1254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the pipe's 0x%x overlapped event to the array as %d\n", fh->h, nhandles); | 1306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1307 | "Adding the pipe's 0x%x overlapped event to the array as %d\n", | ||
1308 | fh->h, nhandles); | ||
1255 | #endif | 1309 | #endif |
1256 | handle_array[nhandles++] = fh->oOverlapRead->hEvent; | 1310 | handle_array[nhandles++] = fh->oOverlapRead->hEvent; |
1257 | readArray[readPipes++] = fh; | 1311 | readArray[readPipes++] = fh; |
1258 | } | 1312 | } |
1259 | /* | 1313 | /* |
1260 | else | 1314 | * else |
1261 | { | 1315 | * { |
1262 | SetErrnoFromWinError (error_code); | 1316 | * SetErrnoFromWinError (error_code); |
1263 | } | 1317 | * } |
1264 | */ | 1318 | */ |
1265 | } | 1319 | } |
1266 | else | 1320 | else |
1267 | { | 1321 | { |
1268 | #if DEBUG_NETWORK | 1322 | #if DEBUG_NETWORK |
1269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the read ready event to the array as %d\n", nhandles); | 1323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1324 | "Adding the read ready event to the array as %d\n", | ||
1325 | nhandles); | ||
1270 | #endif | 1326 | #endif |
1271 | handle_array[nhandles++] = hEventReadReady; | 1327 | handle_array[nhandles++] = hEventReadReady; |
1272 | readArray[readPipes++] = fh; | 1328 | readArray[readPipes++] = fh; |
@@ -1275,8 +1331,8 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1275 | else | 1331 | else |
1276 | { | 1332 | { |
1277 | GNUNET_CONTAINER_slist_add (handles_read, | 1333 | GNUNET_CONTAINER_slist_add (handles_read, |
1278 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 1334 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
1279 | fh, sizeof (struct GNUNET_DISK_FileHandle)); | 1335 | fh, sizeof (struct GNUNET_DISK_FileHandle)); |
1280 | } | 1336 | } |
1281 | } | 1337 | } |
1282 | GNUNET_CONTAINER_slist_iter_destroy (i); | 1338 | GNUNET_CONTAINER_slist_iter_destroy (i); |
@@ -1284,7 +1340,8 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1284 | if (wfds && write_handles) | 1340 | if (wfds && write_handles) |
1285 | { | 1341 | { |
1286 | #if DEBUG_NETWORK | 1342 | #if DEBUG_NETWORK |
1287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the write ready event to the array as %d\n", nhandles); | 1343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1344 | "Adding the write ready event to the array as %d\n", nhandles); | ||
1288 | #endif | 1345 | #endif |
1289 | handle_array[nhandles++] = hEventPipeWrite; | 1346 | handle_array[nhandles++] = hEventPipeWrite; |
1290 | writePipePos = nhandles; | 1347 | writePipePos = nhandles; |
@@ -1292,21 +1349,24 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1292 | if (efds && ex_handles) | 1349 | if (efds && ex_handles) |
1293 | { | 1350 | { |
1294 | struct GNUNET_CONTAINER_SList_Iterator *i; | 1351 | struct GNUNET_CONTAINER_SList_Iterator *i; |
1352 | |||
1295 | for (i = GNUNET_CONTAINER_slist_begin (efds->handles); | 1353 | for (i = GNUNET_CONTAINER_slist_begin (efds->handles); |
1296 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; | 1354 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; |
1297 | GNUNET_CONTAINER_slist_next (i)) | 1355 | GNUNET_CONTAINER_slist_next (i)) |
1298 | { | 1356 | { |
1299 | struct GNUNET_DISK_FileHandle *fh; | 1357 | struct GNUNET_DISK_FileHandle *fh; |
1300 | DWORD dwBytes; | 1358 | DWORD dwBytes; |
1301 | 1359 | ||
1302 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (i, NULL); | 1360 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (i, |
1361 | NULL); | ||
1303 | if (fh->type == GNUNET_PIPE) | 1362 | if (fh->type == GNUNET_PIPE) |
1304 | { | 1363 | { |
1305 | if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL)) | 1364 | if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL)) |
1306 | { | 1365 | { |
1307 | GNUNET_CONTAINER_slist_add (handles_except, | 1366 | GNUNET_CONTAINER_slist_add (handles_except, |
1308 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 1367 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
1309 | fh, sizeof (struct GNUNET_DISK_FileHandle)); | 1368 | fh, |
1369 | sizeof (struct GNUNET_DISK_FileHandle)); | ||
1310 | newretcode++; | 1370 | newretcode++; |
1311 | } | 1371 | } |
1312 | } | 1372 | } |
@@ -1318,21 +1378,27 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1318 | if (rfds) | 1378 | if (rfds) |
1319 | { | 1379 | { |
1320 | #if DEBUG_NETWORK | 1380 | #if DEBUG_NETWORK |
1321 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket read event to the array as %d\n", nhandles); | 1381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1382 | "Adding the socket read event to the array as %d\n", | ||
1383 | nhandles); | ||
1322 | #endif | 1384 | #endif |
1323 | handle_array[nhandles++] = hEventRead; | 1385 | handle_array[nhandles++] = hEventRead; |
1324 | nSockEvents++; | 1386 | nSockEvents++; |
1325 | for (i = 0; i < rfds->sds.fd_count; i++) | 1387 | for (i = 0; i < rfds->sds.fd_count; i++) |
1326 | { | 1388 | { |
1327 | WSAEventSelect (rfds->sds.fd_array[i], hEventRead, FD_ACCEPT | FD_READ | FD_CLOSE); | 1389 | WSAEventSelect (rfds->sds.fd_array[i], hEventRead, |
1390 | FD_ACCEPT | FD_READ | FD_CLOSE); | ||
1328 | nsock++; | 1391 | nsock++; |
1329 | } | 1392 | } |
1330 | } | 1393 | } |
1331 | if (wfds) | 1394 | if (wfds) |
1332 | { | 1395 | { |
1333 | int wakeup = 0; | 1396 | int wakeup = 0; |
1397 | |||
1334 | #if DEBUG_NETWORK | 1398 | #if DEBUG_NETWORK |
1335 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket write event to the array as %d\n", nhandles); | 1399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1400 | "Adding the socket write event to the array as %d\n", | ||
1401 | nhandles); | ||
1336 | #endif | 1402 | #endif |
1337 | handle_array[nhandles++] = hEventWrite; | 1403 | handle_array[nhandles++] = hEventWrite; |
1338 | nSockEvents++; | 1404 | nSockEvents++; |
@@ -1340,14 +1406,18 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1340 | { | 1406 | { |
1341 | DWORD error; | 1407 | DWORD error; |
1342 | int status; | 1408 | int status; |
1409 | |||
1343 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); | 1410 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); |
1344 | error = GetLastError (); | 1411 | error = GetLastError (); |
1345 | #if DEBUG_NETWORK | 1412 | #if DEBUG_NETWORK |
1346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pre-send to the socket %d returned %d (%u)\n", i, status, error); | 1413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1414 | "pre-send to the socket %d returned %d (%u)\n", i, status, | ||
1415 | error); | ||
1347 | #endif | 1416 | #endif |
1348 | if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) | 1417 | if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) |
1349 | wakeup = 1; | 1418 | wakeup = 1; |
1350 | WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, FD_WRITE | FD_CONNECT | FD_CLOSE); | 1419 | WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, |
1420 | FD_WRITE | FD_CONNECT | FD_CLOSE); | ||
1351 | nsock++; | 1421 | nsock++; |
1352 | } | 1422 | } |
1353 | if (wakeup) | 1423 | if (wakeup) |
@@ -1356,13 +1426,16 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1356 | if (efds) | 1426 | if (efds) |
1357 | { | 1427 | { |
1358 | #if DEBUG_NETWORK | 1428 | #if DEBUG_NETWORK |
1359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket error event to the array as %d\n", nhandles); | 1429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1430 | "Adding the socket error event to the array as %d\n", | ||
1431 | nhandles); | ||
1360 | #endif | 1432 | #endif |
1361 | handle_array[nhandles++] = hEventException; | 1433 | handle_array[nhandles++] = hEventException; |
1362 | nSockEvents++; | 1434 | nSockEvents++; |
1363 | for (i = 0; i < efds->sds.fd_count; i++) | 1435 | for (i = 0; i < efds->sds.fd_count; i++) |
1364 | { | 1436 | { |
1365 | WSAEventSelect (efds->sds.fd_array[i], hEventException, FD_OOB | FD_CLOSE); | 1437 | WSAEventSelect (efds->sds.fd_array[i], hEventException, |
1438 | FD_OOB | FD_CLOSE); | ||
1366 | nsock++; | 1439 | nsock++; |
1367 | } | 1440 | } |
1368 | } | 1441 | } |
@@ -1378,11 +1451,13 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1378 | #endif | 1451 | #endif |
1379 | 1452 | ||
1380 | if (nhandles) | 1453 | if (nhandles) |
1381 | returncode = WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total); | 1454 | returncode = |
1455 | WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total); | ||
1382 | #if DEBUG_NETWORK | 1456 | #if DEBUG_NETWORK |
1383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n", returncode); | 1457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n", |
1458 | returncode); | ||
1384 | #endif | 1459 | #endif |
1385 | 1460 | ||
1386 | returnedpos = returncode - WAIT_OBJECT_0; | 1461 | returnedpos = returncode - WAIT_OBJECT_0; |
1387 | #if DEBUG_NETWORK | 1462 | #if DEBUG_NETWORK |
1388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "return pos is : %d\n", returnedpos); | 1463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "return pos is : %d\n", returnedpos); |
@@ -1390,16 +1465,18 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1390 | 1465 | ||
1391 | /* FIXME: THIS LINE IS WRONG !! We should add to handles only handles that fired the events, not all ! */ | 1466 | /* FIXME: THIS LINE IS WRONG !! We should add to handles only handles that fired the events, not all ! */ |
1392 | /* | 1467 | /* |
1393 | if(rfds) | 1468 | * if(rfds) |
1394 | GNUNET_CONTAINER_slist_append (handles_read, rfds->handles); | 1469 | * GNUNET_CONTAINER_slist_append (handles_read, rfds->handles); |
1395 | */ | 1470 | */ |
1396 | if (nhandles && (returnedpos < nhandles)) | 1471 | if (nhandles && (returnedpos < nhandles)) |
1397 | { | 1472 | { |
1398 | DWORD waitstatus; | 1473 | DWORD waitstatus; |
1474 | |||
1399 | /* Do the select */ | 1475 | /* Do the select */ |
1400 | if (nfds) | 1476 | if (nfds) |
1401 | { | 1477 | { |
1402 | struct timeval tvslice; | 1478 | struct timeval tvslice; |
1479 | |||
1403 | tvslice.tv_sec = 0; | 1480 | tvslice.tv_sec = 0; |
1404 | tvslice.tv_usec = 10; | 1481 | tvslice.tv_usec = 10; |
1405 | retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice); | 1482 | retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice); |
@@ -1423,48 +1500,55 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1423 | #endif | 1500 | #endif |
1424 | /* We have some pipes ready for read. */ | 1501 | /* We have some pipes ready for read. */ |
1425 | /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */ | 1502 | /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */ |
1426 | 1503 | ||
1427 | if (returnedpos < readPipes) | 1504 | if (returnedpos < readPipes) |
1428 | { | 1505 | { |
1429 | /* | 1506 | /* |
1430 | for (i = 0; i < readPipes; i++) | 1507 | * for (i = 0; i < readPipes; i++) |
1431 | { | 1508 | * { |
1432 | waitstatus = WaitForSingleObject (handle_array[i], 0); | 1509 | * waitstatus = WaitForSingleObject (handle_array[i], 0); |
1433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus); | 1510 | * GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus); |
1434 | if (waitstatus != WAIT_OBJECT_0) | 1511 | * if (waitstatus != WAIT_OBJECT_0) |
1435 | continue; | 1512 | * continue; |
1436 | GNUNET_CONTAINER_slist_add (handles_read, | 1513 | * GNUNET_CONTAINER_slist_add (handles_read, |
1437 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 1514 | * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
1438 | readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); | 1515 | * readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); |
1439 | retcode++; | 1516 | * retcode++; |
1440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n"); | 1517 | * GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n"); |
1441 | } | 1518 | * } |
1442 | */ | 1519 | */ |
1443 | for (i = 0; i < readPipes; i++) | 1520 | for (i = 0; i < readPipes; i++) |
1444 | { | 1521 | { |
1445 | DWORD error; | 1522 | DWORD error; |
1446 | BOOL bret; | 1523 | BOOL bret; |
1524 | |||
1447 | SetLastError (0); | 1525 | SetLastError (0); |
1448 | waitstatus = 0; | 1526 | waitstatus = 0; |
1449 | bret = PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, NULL); | 1527 | bret = |
1528 | PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, NULL); | ||
1450 | error = GetLastError (); | 1529 | error = GetLastError (); |
1451 | #if DEBUG_NETWORK | 1530 | #if DEBUG_NETWORK |
1452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n", i, readArray[i]->h, bret, waitstatus, error); | 1531 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1532 | "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n", | ||
1533 | i, readArray[i]->h, bret, waitstatus, error); | ||
1453 | #endif | 1534 | #endif |
1454 | if (bret == 0 || waitstatus <= 0) | 1535 | if (bret == 0 || waitstatus <= 0) |
1455 | continue; | 1536 | continue; |
1456 | GNUNET_CONTAINER_slist_add (handles_read, | 1537 | GNUNET_CONTAINER_slist_add (handles_read, |
1457 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 1538 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
1458 | readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); | 1539 | readArray[i], |
1540 | sizeof (struct GNUNET_DISK_FileHandle)); | ||
1459 | retcode++; | 1541 | retcode++; |
1460 | #if DEBUG_NETWORK | 1542 | #if DEBUG_NETWORK |
1461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n", readArray[i], readArray[i]->h); | 1543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n", |
1544 | readArray[i], readArray[i]->h); | ||
1462 | #endif | 1545 | #endif |
1463 | } | 1546 | } |
1464 | } | 1547 | } |
1465 | waitstatus = WaitForSingleObject (hEventWrite, 0); | 1548 | waitstatus = WaitForSingleObject (hEventWrite, 0); |
1466 | #if DEBUG_NETWORK | 1549 | #if DEBUG_NETWORK |
1467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Wait for the write event returned %d\n", waitstatus); | 1550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1551 | "Wait for the write event returned %d\n", waitstatus); | ||
1468 | #endif | 1552 | #endif |
1469 | if (waitstatus == WAIT_OBJECT_0) | 1553 | if (waitstatus == WAIT_OBJECT_0) |
1470 | { | 1554 | { |
@@ -1474,15 +1558,21 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1474 | int status; | 1558 | int status; |
1475 | int so_error = 0; | 1559 | int so_error = 0; |
1476 | int sizeof_so_error = sizeof (so_error); | 1560 | int sizeof_so_error = sizeof (so_error); |
1477 | int gso_result = getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR, (char *) &so_error, &sizeof_so_error); | 1561 | int gso_result = |
1562 | getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR, | ||
1563 | (char *) &so_error, &sizeof_so_error); | ||
1564 | |||
1478 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); | 1565 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); |
1479 | error = GetLastError (); | 1566 | error = GetLastError (); |
1480 | #if DEBUG_NETWORK | 1567 | #if DEBUG_NETWORK |
1481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send to the socket %d returned %d (%u)\n", i, status, error); | 1568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1569 | "send to the socket %d returned %d (%u)\n", i, status, | ||
1570 | error); | ||
1482 | #endif | 1571 | #endif |
1483 | if (status == 0 | 1572 | if (status == 0 |
1484 | || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) | 1573 | || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) |
1485 | || (status == -1 && gso_result == 0 && error == WSAENOTCONN && so_error == WSAECONNREFUSED)) | 1574 | || (status == -1 && gso_result == 0 && error == WSAENOTCONN && |
1575 | so_error == WSAECONNREFUSED)) | ||
1486 | { | 1576 | { |
1487 | FD_SET (wfds->sds.fd_array[i], &awrite); | 1577 | FD_SET (wfds->sds.fd_array[i], &awrite); |
1488 | retcode += 1; | 1578 | retcode += 1; |
@@ -1492,22 +1582,26 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1492 | } | 1582 | } |
1493 | #if DEBUG_NETWORK | 1583 | #if DEBUG_NETWORK |
1494 | if (!nhandles || (returnedpos >= nhandles)) | 1584 | if (!nhandles || (returnedpos >= nhandles)) |
1495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n"); | 1585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1586 | "Returning from _select() with nothing!\n"); | ||
1496 | #endif | 1587 | #endif |
1497 | if (rfds) | 1588 | if (rfds) |
1498 | { | 1589 | { |
1499 | struct GNUNET_CONTAINER_SList_Iterator *t; | 1590 | struct GNUNET_CONTAINER_SList_Iterator *t; |
1591 | |||
1500 | for (i = 0; i < rfds->sds.fd_count; i++) | 1592 | for (i = 0; i < rfds->sds.fd_count; i++) |
1501 | { | 1593 | { |
1502 | WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0); | 1594 | WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0); |
1503 | nsock++; | 1595 | nsock++; |
1504 | } | 1596 | } |
1505 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); | 1597 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); |
1506 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | 1598 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; |
1507 | GNUNET_CONTAINER_slist_next (t)) | 1599 | GNUNET_CONTAINER_slist_next (t)) |
1508 | { | 1600 | { |
1509 | struct GNUNET_DISK_FileHandle *fh; | 1601 | struct GNUNET_DISK_FileHandle *fh; |
1510 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); | 1602 | |
1603 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, | ||
1604 | NULL); | ||
1511 | if (fh->type == GNUNET_PIPE) | 1605 | if (fh->type == GNUNET_PIPE) |
1512 | { | 1606 | { |
1513 | CancelIo (fh->h); | 1607 | CancelIo (fh->h); |
@@ -1559,17 +1653,23 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1559 | if (rfds) | 1653 | if (rfds) |
1560 | { | 1654 | { |
1561 | struct GNUNET_CONTAINER_SList_Iterator *t; | 1655 | struct GNUNET_CONTAINER_SList_Iterator *t; |
1656 | |||
1562 | for (i = 0; i < bread.fd_count; i++) | 1657 | for (i = 0; i < bread.fd_count; i++) |
1563 | { | 1658 | { |
1564 | if (bread.fd_array[i] != 0) | 1659 | if (bread.fd_array[i] != 0) |
1565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n", bread.fd_array[i], (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" : "NOT SET"); | 1660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n", |
1661 | bread.fd_array[i], | ||
1662 | (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" : | ||
1663 | "NOT SET"); | ||
1566 | } | 1664 | } |
1567 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); | 1665 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); |
1568 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | 1666 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; |
1569 | GNUNET_CONTAINER_slist_next (t)) | 1667 | GNUNET_CONTAINER_slist_next (t)) |
1570 | { | 1668 | { |
1571 | struct GNUNET_DISK_FileHandle *fh; | 1669 | struct GNUNET_DISK_FileHandle *fh; |
1572 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); | 1670 | |
1671 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, | ||
1672 | NULL); | ||
1573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h); | 1673 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h); |
1574 | } | 1674 | } |
1575 | } | 1675 | } |
@@ -1578,7 +1678,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1578 | for (i = 0; i < bwrite.fd_count; i++) | 1678 | for (i = 0; i < bwrite.fd_count; i++) |
1579 | { | 1679 | { |
1580 | if (bwrite.fd_array[i] != 0) | 1680 | if (bwrite.fd_array[i] != 0) |
1581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n", bwrite.fd_array[i], (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" : "NOT SET"); | 1681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n", |
1682 | bwrite.fd_array[i], | ||
1683 | (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" : | ||
1684 | "NOT SET"); | ||
1582 | } | 1685 | } |
1583 | } | 1686 | } |
1584 | if (efds) | 1687 | if (efds) |
@@ -1586,7 +1689,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1586 | for (i = 0; i < bexcept.fd_count; i++) | 1689 | for (i = 0; i < bexcept.fd_count; i++) |
1587 | { | 1690 | { |
1588 | if (bexcept.fd_array[i] != 0) | 1691 | if (bexcept.fd_array[i] != 0) |
1589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n", bexcept.fd_array[i], (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" : "NOT SET"); | 1692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n", |
1693 | bexcept.fd_array[i], | ||
1694 | (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" : | ||
1695 | "NOT SET"); | ||
1590 | } | 1696 | } |
1591 | } | 1697 | } |
1592 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode); | 1698 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode); |