aboutsummaryrefslogtreecommitdiff
path: root/src/util/network.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/network.c')
-rw-r--r--src/util/network.c1072
1 files changed, 523 insertions, 549 deletions
diff --git a/src/util/network.c b/src/util/network.c
index 3fc71e666..180adc164 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -90,11 +90,11 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock)
90 mode = !doBlock; 90 mode = !doBlock;
91 if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR) 91 if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR)
92 92
93 { 93 {
94 SetErrnoFromWinsockError (WSAGetLastError ()); 94 SetErrnoFromWinsockError (WSAGetLastError ());
95 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); 95 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket");
96 return GNUNET_SYSERR; 96 return GNUNET_SYSERR;
97 } 97 }
98 return GNUNET_OK; 98 return GNUNET_OK;
99 99
100#else 100#else
@@ -103,10 +103,10 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock)
103 103
104 if (flags == -1) 104 if (flags == -1)
105 105
106 { 106 {
107 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl"); 107 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl");
108 return GNUNET_SYSERR; 108 return GNUNET_SYSERR;
109 } 109 }
110 if (doBlock) 110 if (doBlock)
111 flags &= ~O_NONBLOCK; 111 flags &= ~O_NONBLOCK;
112 112
@@ -114,10 +114,10 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock)
114 flags |= O_NONBLOCK; 114 flags |= O_NONBLOCK;
115 if (0 != fcntl (fd->fd, F_SETFL, flags)) 115 if (0 != fcntl (fd->fd, F_SETFL, flags))
116 116
117 { 117 {
118 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl"); 118 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl");
119 return GNUNET_SYSERR; 119 return GNUNET_SYSERR;
120 } 120 }
121 return GNUNET_OK; 121 return GNUNET_OK;
122#endif 122#endif
123} 123}
@@ -162,7 +162,7 @@ socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h)
162 162
163 if (0 != 163 if (0 !=
164 setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value, 164 setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value,
165 sizeof (abs_value))) 165 sizeof (abs_value)))
166 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 166 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
167} 167}
168#endif 168#endif
@@ -181,15 +181,14 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
181#ifndef WINDOWS 181#ifndef WINDOWS
182 int value = 1; 182 int value = 1;
183 183
184 if (0 != 184 if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value)))
185 setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value)))
186 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 185 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
187#else 186#else
188 const char *abs_value = "1"; 187 const char *abs_value = "1";
189 188
190 if (0 != 189 if (0 !=
191 setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value, 190 setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value,
192 sizeof (abs_value))) 191 sizeof (abs_value)))
193 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 192 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
194#endif 193#endif
195} 194}
@@ -205,8 +204,7 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
205 */ 204 */
206struct GNUNET_NETWORK_Handle * 205struct GNUNET_NETWORK_Handle *
207GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, 206GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
208 struct sockaddr *address, 207 struct sockaddr *address, socklen_t * address_len)
209 socklen_t * address_len)
210{ 208{
211 struct GNUNET_NETWORK_Handle *ret; 209 struct GNUNET_NETWORK_Handle *ret;
212 210
@@ -219,7 +217,7 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
219 217
220 if (gsn == 0) 218 if (gsn == 0)
221 LOG (GNUNET_ERROR_TYPE_DEBUG, "Accepting connection on `%s'\n", 219 LOG (GNUNET_ERROR_TYPE_DEBUG, "Accepting connection on `%s'\n",
222 GNUNET_a2s (&name, namelen)); 220 GNUNET_a2s (&name, namelen));
223 } 221 }
224#endif 222#endif
225 ret->fd = accept (desc->fd, address, address_len); 223 ret->fd = accept (desc->fd, address, address_len);
@@ -228,36 +226,36 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
228 else 226 else
229 ret->af = desc->af; 227 ret->af = desc->af;
230 if (ret->fd == INVALID_SOCKET) 228 if (ret->fd == INVALID_SOCKET)
231 { 229 {
232#ifdef MINGW 230#ifdef MINGW
233 SetErrnoFromWinsockError (WSAGetLastError ()); 231 SetErrnoFromWinsockError (WSAGetLastError ());
234#endif 232#endif
235 GNUNET_free (ret); 233 GNUNET_free (ret);
236 return NULL; 234 return NULL;
237 } 235 }
238#ifndef MINGW 236#ifndef MINGW
239 if (ret->fd >= FD_SETSIZE) 237 if (ret->fd >= FD_SETSIZE)
240 { 238 {
241 GNUNET_break (0 == close (ret->fd)); 239 GNUNET_break (0 == close (ret->fd));
242 GNUNET_free (ret); 240 GNUNET_free (ret);
243 errno = EMFILE; 241 errno = EMFILE;
244 return NULL; 242 return NULL;
245 } 243 }
246#endif 244#endif
247 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) 245 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
248 246
249 { 247 {
250 248
251 /* we might want to treat this one as fatal... */ 249 /* we might want to treat this one as fatal... */
252 GNUNET_break (0); 250 GNUNET_break (0);
253 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); 251 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
254 return NULL; 252 return NULL;
255 } 253 }
256 254
257#ifndef MINGW 255#ifndef MINGW
258 if (GNUNET_OK != socket_set_inheritable (ret)) 256 if (GNUNET_OK != socket_set_inheritable (ret))
259 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 257 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
260 "socket_set_inheritable"); 258 "socket_set_inheritable");
261#endif 259#endif
262#ifdef DARWIN 260#ifdef DARWIN
263 socket_set_nosigpipe (ret); 261 socket_set_nosigpipe (ret);
@@ -279,8 +277,8 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
279 */ 277 */
280int 278int
281GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, 279GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
282 const struct sockaddr *address, 280 const struct sockaddr *address,
283 socklen_t address_len) 281 socklen_t address_len)
284{ 282{
285 int ret; 283 int ret;
286 284
@@ -289,8 +287,7 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
289 const int on = 1; 287 const int on = 1;
290 288
291 if (desc->af == AF_INET6) 289 if (desc->af == AF_INET6)
292 if (0 != 290 if (0 != setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)))
293 setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)))
294 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); 291 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt");
295#endif 292#endif
296#endif 293#endif
@@ -302,11 +299,11 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
302#ifndef LINUX 299#ifndef LINUX
303#ifndef MINGW 300#ifndef MINGW
304 if (address->sa_family == AF_UNIX) 301 if (address->sa_family == AF_UNIX)
305 { 302 {
306 const struct sockaddr_un *un = (const struct sockaddr_un *) address; 303 const struct sockaddr_un *un = (const struct sockaddr_un *) address;
307 304
308 (void) unlink (un->sun_path); 305 (void) unlink (un->sun_path);
309 } 306 }
310#endif 307#endif
311#endif 308#endif
312 ret = bind (desc->fd, address, address_len); 309 ret = bind (desc->fd, address, address_len);
@@ -341,8 +338,8 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
341 DWORD error = 0; 338 DWORD error = 0;
342 339
343#if DEBUG_NETWORK 340#if DEBUG_NETWORK
344 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", 341 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", "Closing 0x%x\n",
345 "Closing 0x%x\n", desc->fd); 342 desc->fd);
346#endif 343#endif
347 SetLastError (0); 344 SetLastError (0);
348 ret = closesocket (desc->fd); 345 ret = closesocket (desc->fd);
@@ -350,8 +347,8 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
350 SetErrnoFromWinsockError (error); 347 SetErrnoFromWinsockError (error);
351#if DEBUG_NETWORK 348#if DEBUG_NETWORK
352 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", 349 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close",
353 "Closed 0x%x, closesocket() returned %d, GLE is %u\n", 350 "Closed 0x%x, closesocket() returned %d, GLE is %u\n", desc->fd, ret,
354 desc->fd, ret, error); 351 error);
355#endif 352#endif
356#else 353#else
357 ret = close (desc->fd); 354 ret = close (desc->fd);
@@ -359,12 +356,12 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
359#ifndef LINUX 356#ifndef LINUX
360#ifndef MINGW 357#ifndef MINGW
361 if ((desc->af == AF_UNIX) && (NULL != desc->addr)) 358 if ((desc->af == AF_UNIX) && (NULL != desc->addr))
362 { 359 {
363 const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; 360 const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr;
364 361
365 if (0 != unlink (un->sun_path)) 362 if (0 != unlink (un->sun_path))
366 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path); 363 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path);
367 } 364 }
368#endif 365#endif
369#endif 366#endif
370 GNUNET_free_non_null (desc->addr); 367 GNUNET_free_non_null (desc->addr);
@@ -388,7 +385,7 @@ GNUNET_NETWORK_socket_box_native (int fd)
388 struct GNUNET_NETWORK_Handle *ret; 385 struct GNUNET_NETWORK_Handle *ret;
389 386
390 if (fcntl (fd, F_GETFD) < 0) 387 if (fcntl (fd, F_GETFD) < 0)
391 return NULL; /* invalid FD */ 388 return NULL; /* invalid FD */
392 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); 389 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
393 ret->fd = fd; 390 ret->fd = fd;
394 ret->af = AF_UNSPEC; 391 ret->af = AF_UNSPEC;
@@ -406,8 +403,8 @@ GNUNET_NETWORK_socket_box_native (int fd)
406 */ 403 */
407int 404int
408GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, 405GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
409 const struct sockaddr *address, 406 const struct sockaddr *address,
410 socklen_t address_len) 407 socklen_t address_len)
411{ 408{
412 int ret; 409 int ret;
413 410
@@ -415,11 +412,11 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
415 412
416#ifdef MINGW 413#ifdef MINGW
417 if (SOCKET_ERROR == ret) 414 if (SOCKET_ERROR == ret)
418 { 415 {
419 SetErrnoFromWinsockError (WSAGetLastError ()); 416 SetErrnoFromWinsockError (WSAGetLastError ());
420 if (errno == EWOULDBLOCK) 417 if (errno == EWOULDBLOCK)
421 errno = EINPROGRESS; 418 errno = EINPROGRESS;
422 } 419 }
423#endif 420#endif
424 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 421 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
425} 422}
@@ -437,8 +434,8 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
437 */ 434 */
438int 435int
439GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, 436GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc,
440 int level, int optname, void *optval, 437 int level, int optname, void *optval,
441 socklen_t * optlen) 438 socklen_t * optlen)
442{ 439{
443 int ret; 440 int ret;
444 441
@@ -463,7 +460,7 @@ GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc,
463 */ 460 */
464int 461int
465GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, 462GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
466 int backlog) 463 int backlog)
467{ 464{
468 int ret; 465 int ret;
469 466
@@ -486,7 +483,7 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
486 */ 483 */
487ssize_t 484ssize_t
488GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle * 485GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle *
489 desc) 486 desc)
490{ 487{
491 int error; 488 int error;
492 489
@@ -519,9 +516,8 @@ GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle *
519 */ 516 */
520ssize_t 517ssize_t
521GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, 518GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc,
522 void *buffer, size_t length, 519 void *buffer, size_t length,
523 struct sockaddr * src_addr, 520 struct sockaddr * src_addr, socklen_t * addrlen)
524 socklen_t * addrlen)
525{ 521{
526 int ret; 522 int ret;
527 int flags; 523 int flags;
@@ -549,7 +545,7 @@ GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc,
549 */ 545 */
550ssize_t 546ssize_t
551GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, 547GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc,
552 void *buffer, size_t length) 548 void *buffer, size_t length)
553{ 549{
554 int ret; 550 int ret;
555 int flags; 551 int flags;
@@ -578,7 +574,7 @@ GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc,
578 */ 574 */
579ssize_t 575ssize_t
580GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, 576GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc,
581 const void *buffer, size_t length) 577 const void *buffer, size_t length)
582{ 578{
583 int ret; 579 int ret;
584 int flags; 580 int flags;
@@ -617,9 +613,9 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc,
617 */ 613 */
618ssize_t 614ssize_t
619GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, 615GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
620 const void *message, size_t length, 616 const void *message, size_t length,
621 const struct sockaddr * dest_addr, 617 const struct sockaddr * dest_addr,
622 socklen_t dest_len) 618 socklen_t dest_len)
623{ 619{
624 int ret; 620 int ret;
625 int flags; 621 int flags;
@@ -652,8 +648,8 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
652 */ 648 */
653int 649int
654GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level, 650GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level,
655 int option_name, const void *option_value, 651 int option_name, const void *option_value,
656 socklen_t option_len) 652 socklen_t option_len)
657{ 653{
658 int ret; 654 int ret;
659 655
@@ -685,36 +681,36 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol)
685 ret->af = domain; 681 ret->af = domain;
686 ret->fd = socket (domain, type, protocol); 682 ret->fd = socket (domain, type, protocol);
687 if (INVALID_SOCKET == ret->fd) 683 if (INVALID_SOCKET == ret->fd)
688 { 684 {
689#ifdef MINGW 685#ifdef MINGW
690 SetErrnoFromWinsockError (WSAGetLastError ()); 686 SetErrnoFromWinsockError (WSAGetLastError ());
691#endif 687#endif
692 GNUNET_free (ret); 688 GNUNET_free (ret);
693 return NULL; 689 return NULL;
694 } 690 }
695 691
696#ifndef MINGW 692#ifndef MINGW
697 if (ret->fd >= FD_SETSIZE) 693 if (ret->fd >= FD_SETSIZE)
698 { 694 {
699 GNUNET_break (0 == close (ret->fd)); 695 GNUNET_break (0 == close (ret->fd));
700 GNUNET_free (ret); 696 GNUNET_free (ret);
701 errno = EMFILE; 697 errno = EMFILE;
702 return NULL; 698 return NULL;
703 } 699 }
704 700
705#endif 701#endif
706 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) 702 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
707 { 703 {
708 /* we might want to treat this one as fatal... */ 704 /* we might want to treat this one as fatal... */
709 GNUNET_break (0); 705 GNUNET_break (0);
710 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); 706 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
711 return NULL; 707 return NULL;
712 } 708 }
713 709
714#ifndef MINGW 710#ifndef MINGW
715 if (GNUNET_OK != socket_set_inheritable (ret)) 711 if (GNUNET_OK != socket_set_inheritable (ret))
716 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 712 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
717 "socket_set_inheritable"); 713 "socket_set_inheritable");
718#endif 714#endif
719#ifdef DARWIN 715#ifdef DARWIN
720 socket_set_nosigpipe (ret); 716 socket_set_nosigpipe (ret);
@@ -723,7 +719,7 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol)
723#ifdef AF_UNIX 719#ifdef AF_UNIX
724 && (domain != AF_UNIX) 720 && (domain != AF_UNIX)
725#endif 721#endif
726 ) 722 )
727 socket_set_nodelay (ret); 723 socket_set_nodelay (ret);
728 return ret; 724 return ret;
729} 725}
@@ -762,18 +758,19 @@ int
762GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc) 758GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc)
763{ 759{
764 int ret = 0; 760 int ret = 0;
761
765#if WINDOWS 762#if WINDOWS
766 int value = 0; 763 int value = 0;
767 764
768 if (0 != 765 if (0 !=
769 (ret = 766 (ret =
770 setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value, 767 setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value,
771 sizeof (value)))) 768 sizeof (value))))
772 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 769 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
773 if (0 != 770 if (0 !=
774 (ret = 771 (ret =
775 setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value, 772 setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value,
776 sizeof (value)))) 773 sizeof (value))))
777 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 774 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
778#elif LINUX 775#elif LINUX
779 int value = 0; 776 int value = 0;
@@ -812,7 +809,7 @@ GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds)
812 */ 809 */
813void 810void
814GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, 811GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds,
815 const struct GNUNET_NETWORK_Handle *desc) 812 const struct GNUNET_NETWORK_Handle *desc)
816{ 813{
817 FD_SET (desc->fd, &fds->sds); 814 FD_SET (desc->fd, &fds->sds);
818 if (desc->fd + 1 > fds->nsds) 815 if (desc->fd + 1 > fds->nsds)
@@ -828,7 +825,7 @@ GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds,
828 */ 825 */
829int 826int
830GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, 827GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
831 const struct GNUNET_NETWORK_Handle *desc) 828 const struct GNUNET_NETWORK_Handle *desc)
832{ 829{
833 return FD_ISSET (desc->fd, &fds->sds); 830 return FD_ISSET (desc->fd, &fds->sds);
834} 831}
@@ -841,18 +838,18 @@ GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
841 */ 838 */
842void 839void
843GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, 840GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
844 const struct GNUNET_NETWORK_FDSet *src) 841 const struct GNUNET_NETWORK_FDSet *src)
845{ 842{
846 int nfds; 843 int nfds;
847 844
848 for (nfds = src->nsds; nfds > 0; nfds--) 845 for (nfds = src->nsds; nfds > 0; nfds--)
849 if (FD_ISSET (nfds, &src->sds)) 846 if (FD_ISSET (nfds, &src->sds))
850 847
851 { 848 {
852 FD_SET (nfds, &dst->sds); 849 FD_SET (nfds, &dst->sds);
853 if (nfds + 1 > dst->nsds) 850 if (nfds + 1 > dst->nsds)
854 dst->nsds = nfds + 1; 851 dst->nsds = nfds + 1;
855 } 852 }
856#ifdef MINGW 853#ifdef MINGW
857 GNUNET_CONTAINER_slist_append (dst->handles, src->handles); 854 GNUNET_CONTAINER_slist_append (dst->handles, src->handles);
858#endif 855#endif
@@ -867,7 +864,7 @@ GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
867 */ 864 */
868void 865void
869GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, 866GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
870 const struct GNUNET_NETWORK_FDSet *from) 867 const struct GNUNET_NETWORK_FDSet *from)
871{ 868{
872 FD_COPY (&from->sds, &to->sds); 869 FD_COPY (&from->sds, &to->sds);
873 to->nsds = from->nsds; 870 to->nsds = from->nsds;
@@ -901,7 +898,7 @@ GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc)
901 */ 898 */
902void 899void
903GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, 900GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to,
904 const fd_set * from, int nfds) 901 const fd_set * from, int nfds)
905{ 902{
906 FD_COPY (from, &to->sds); 903 FD_COPY (from, &to->sds);
907 to->nsds = nfds; 904 to->nsds = nfds;
@@ -932,7 +929,7 @@ GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, int nfd)
932 */ 929 */
933int 930int
934GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to, 931GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to,
935 int nfd) 932 int nfd)
936{ 933{
937 if ((nfd == -1) || (to == NULL)) 934 if ((nfd == -1) || (to == NULL))
938 return GNUNET_NO; 935 return GNUNET_NO;
@@ -947,12 +944,12 @@ GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to,
947 */ 944 */
948void 945void
949GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, 946GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
950 const struct GNUNET_DISK_FileHandle *h) 947 const struct GNUNET_DISK_FileHandle *h)
951{ 948{
952#ifdef MINGW 949#ifdef MINGW
953 GNUNET_CONTAINER_slist_add (fds->handles, 950 GNUNET_CONTAINER_slist_add (fds->handles,
954 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, h, 951 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, h,
955 sizeof (struct GNUNET_DISK_FileHandle)); 952 sizeof (struct GNUNET_DISK_FileHandle));
956 953
957#else 954#else
958 int fd; 955 int fd;
@@ -974,13 +971,13 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
974 */ 971 */
975int 972int
976GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, 973GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
977 const struct GNUNET_DISK_FileHandle *h) 974 const struct GNUNET_DISK_FileHandle *h)
978{ 975{
979 976
980#ifdef MINGW 977#ifdef MINGW
981 return GNUNET_CONTAINER_slist_contains (fds->handles, h, 978 return GNUNET_CONTAINER_slist_contains (fds->handles, h,
982 sizeof (struct 979 sizeof (struct
983 GNUNET_DISK_FileHandle)); 980 GNUNET_DISK_FileHandle));
984#else 981#else
985 return FD_ISSET (h->fd, &fds->sds); 982 return FD_ISSET (h->fd, &fds->sds);
986#endif 983#endif
@@ -995,7 +992,7 @@ GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
995 */ 992 */
996int 993int
997GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, 994GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
998 const struct GNUNET_NETWORK_FDSet *fds2) 995 const struct GNUNET_NETWORK_FDSet *fds2)
999{ 996{
1000#ifndef MINGW 997#ifndef MINGW
1001 int nfds; 998 int nfds;
@@ -1004,11 +1001,11 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
1004 if (nfds > fds2->nsds) 1001 if (nfds > fds2->nsds)
1005 nfds = fds2->nsds; 1002 nfds = fds2->nsds;
1006 while (nfds > 0) 1003 while (nfds > 0)
1007 { 1004 {
1008 nfds--; 1005 nfds--;
1009 if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) 1006 if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds))
1010 return GNUNET_YES; 1007 return GNUNET_YES;
1011 } 1008 }
1012#else 1009#else
1013 struct GNUNET_CONTAINER_SList_Iterator it; 1010 struct GNUNET_CONTAINER_SList_Iterator it;
1014 struct GNUNET_DISK_FileHandle *h; 1011 struct GNUNET_DISK_FileHandle *h;
@@ -1019,47 +1016,45 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
1019 * inside of fd_set; also the O(n^2) is really bad... */ 1016 * inside of fd_set; also the O(n^2) is really bad... */
1020 1017
1021 for (i = 0; i < fds1->sds.fd_count; i++) 1018 for (i = 0; i < fds1->sds.fd_count; i++)
1019 {
1020 for (j = 0; j < fds2->sds.fd_count; j++)
1022 { 1021 {
1023 for (j = 0; j < fds2->sds.fd_count; j++) 1022 if (fds1->sds.fd_array[i] == fds2->sds.fd_array[j])
1024 { 1023 return GNUNET_YES;
1025 if (fds1->sds.fd_array[i] == fds2->sds.fd_array[j])
1026 return GNUNET_YES;
1027 }
1028 } 1024 }
1025 }
1029 it = GNUNET_CONTAINER_slist_begin (fds1->handles); 1026 it = GNUNET_CONTAINER_slist_begin (fds1->handles);
1030 while (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES) 1027 while (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES)
1031 { 1028 {
1032#if DEBUG_NETWORK 1029#if DEBUG_NETWORK
1033 struct GNUNET_CONTAINER_SList_Iterator t; 1030 struct GNUNET_CONTAINER_SList_Iterator t;
1034#endif 1031#endif
1035 h = 1032 h = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&it,
1036 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&it, 1033 NULL);
1037 NULL);
1038#if DEBUG_NETWORK 1034#if DEBUG_NETWORK
1039 LOG (GNUNET_ERROR_TYPE_DEBUG, 1035 LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking that FD 0x%x is in another set:\n",
1040 "Checking that FD 0x%x is in another set:\n", h->h); 1036 h->h);
1041 for (t = GNUNET_CONTAINER_slist_begin (fds2->handles); 1037 for (t = GNUNET_CONTAINER_slist_begin (fds2->handles);
1042 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; 1038 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1043 GNUNET_CONTAINER_slist_next (&t)) 1039 GNUNET_CONTAINER_slist_next (&t))
1044 { 1040 {
1045 struct GNUNET_DISK_FileHandle *fh; 1041 struct GNUNET_DISK_FileHandle *fh;
1046 1042
1047 fh = 1043 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1048 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, 1044 NULL);
1049 NULL); 1045 LOG (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h);
1050 LOG (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h); 1046 }
1051 } 1047#endif
1052#endif 1048 if (GNUNET_CONTAINER_slist_contains
1053 if (GNUNET_CONTAINER_slist_contains 1049 (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle)))
1054 (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle))) 1050 {
1055 {
1056#if DEBUG_NETWORK 1051#if DEBUG_NETWORK
1057 LOG (GNUNET_ERROR_TYPE_DEBUG, "Match!\n"); 1052 LOG (GNUNET_ERROR_TYPE_DEBUG, "Match!\n");
1058#endif 1053#endif
1059 return GNUNET_YES; 1054 return GNUNET_YES;
1060 }
1061 GNUNET_CONTAINER_slist_next (&it);
1062 } 1055 }
1056 GNUNET_CONTAINER_slist_next (&it);
1057 }
1063#endif 1058#endif
1064 return GNUNET_NO; 1059 return GNUNET_NO;
1065} 1060}
@@ -1106,9 +1101,9 @@ GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds)
1106 */ 1101 */
1107int 1102int
1108GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, 1103GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1109 struct GNUNET_NETWORK_FDSet *wfds, 1104 struct GNUNET_NETWORK_FDSet *wfds,
1110 struct GNUNET_NETWORK_FDSet *efds, 1105 struct GNUNET_NETWORK_FDSet *efds,
1111 const struct GNUNET_TIME_Relative timeout) 1106 const struct GNUNET_TIME_Relative timeout)
1112{ 1107{
1113 int nfds = 0; 1108 int nfds = 0;
1114 1109
@@ -1138,8 +1133,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1138 DWORD newretcode = 0; 1133 DWORD newretcode = 0;
1139 int returnedpos = 0; 1134 int returnedpos = 0;
1140 1135
1141 struct GNUNET_CONTAINER_SList *handles_read, *handles_write, 1136 struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except;
1142 *handles_except;
1143 1137
1144 fd_set aread, awrite, aexcept; 1138 fd_set aread, awrite, aexcept;
1145 1139
@@ -1153,68 +1147,67 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1153 struct timeval tv; 1147 struct timeval tv;
1154#endif 1148#endif
1155 if (NULL != rfds) 1149 if (NULL != rfds)
1156 { 1150 {
1157 nfds = rfds->nsds; 1151 nfds = rfds->nsds;
1158#ifdef MINGW 1152#ifdef MINGW
1159 handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles); 1153 handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles);
1160#if DEBUG_NETWORK 1154#if DEBUG_NETWORK
1155 {
1156 struct GNUNET_CONTAINER_SList_Iterator t;
1157
1158 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1159 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1160 GNUNET_CONTAINER_slist_next (&t))
1161 { 1161 {
1162 struct GNUNET_CONTAINER_SList_Iterator t; 1162 struct GNUNET_DISK_FileHandle *fh;
1163 1163
1164 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); 1164 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1165 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; 1165 NULL);
1166 GNUNET_CONTAINER_slist_next (&t)) 1166 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n", fh->h,
1167 { 1167 fh);
1168 struct GNUNET_DISK_FileHandle *fh;
1169
1170 fh =
1171 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1172 NULL);
1173 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n",
1174 fh->h, fh);
1175 }
1176 } 1168 }
1169 }
1177#endif 1170#endif
1178#endif 1171#endif
1179 } 1172 }
1180 if (NULL != wfds) 1173 if (NULL != wfds)
1181 { 1174 {
1182 nfds = GNUNET_MAX (nfds, wfds->nsds); 1175 nfds = GNUNET_MAX (nfds, wfds->nsds);
1183#ifdef MINGW 1176#ifdef MINGW
1184 handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles); 1177 handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles);
1185#endif 1178#endif
1186 } 1179 }
1187 if (NULL != efds) 1180 if (NULL != efds)
1188 { 1181 {
1189 nfds = GNUNET_MAX (nfds, efds->nsds); 1182 nfds = GNUNET_MAX (nfds, efds->nsds);
1190#ifdef MINGW 1183#ifdef MINGW
1191 handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles); 1184 handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles);
1192#endif 1185#endif
1193 } 1186 }
1194 1187
1195 if ((nfds == 0) && 1188 if ((nfds == 0) &&
1196 (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) 1189 (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
1197#ifdef MINGW 1190#ifdef MINGW
1198 && handles == 0 1191 && handles == 0
1199#endif 1192#endif
1200 ) 1193 )
1201 { 1194 {
1202 LOG (GNUNET_ERROR_TYPE_ERROR, 1195 LOG (GNUNET_ERROR_TYPE_ERROR,
1203 _ 1196 _
1204 ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), 1197 ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"),
1205 "select"); 1198 "select");
1206 GNUNET_break (0); 1199 GNUNET_break (0);
1207 } 1200 }
1208#ifndef MINGW 1201#ifndef MINGW
1209 tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value; 1202 tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value;
1210 tv.tv_usec = 1203 tv.tv_usec =
1211 1000 * (timeout.rel_value - 1204 1000 * (timeout.rel_value -
1212 (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value)); 1205 (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value));
1213 return select (nfds, (rfds != NULL) ? &rfds->sds : NULL, 1206 return select (nfds, (rfds != NULL) ? &rfds->sds : NULL,
1214 (wfds != NULL) ? &wfds->sds : NULL, 1207 (wfds != NULL) ? &wfds->sds : NULL,
1215 (efds != NULL) ? &efds->sds : NULL, 1208 (efds != NULL) ? &efds->sds : NULL,
1216 (timeout.rel_value == 1209 (timeout.rel_value ==
1217 GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ? NULL : &tv); 1210 GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ? NULL : &tv);
1218 1211
1219#else 1212#else
1220#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) 1213#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
@@ -1225,10 +1218,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1225 ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value; 1218 ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value;
1226 /* select() may be used as a portable way to sleep */ 1219 /* select() may be used as a portable way to sleep */
1227 if (!(rfds || wfds || efds)) 1220 if (!(rfds || wfds || efds))
1228 { 1221 {
1229 Sleep (ms_total); 1222 Sleep (ms_total);
1230 return 0; 1223 return 0;
1231 } 1224 }
1232 1225
1233 /* Events for sockets */ 1226 /* Events for sockets */
1234 if (!hEventRead) 1227 if (!hEventRead)
@@ -1264,194 +1257,184 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1264 FD_ZERO (&bexcept); 1257 FD_ZERO (&bexcept);
1265#endif 1258#endif
1266 if (rfds) 1259 if (rfds)
1267 { 1260 {
1268 FD_COPY (&rfds->sds, &aread); 1261 FD_COPY (&rfds->sds, &aread);
1269#if DEBUG_NETWORK 1262#if DEBUG_NETWORK
1270 FD_COPY (&rfds->sds, &bread); 1263 FD_COPY (&rfds->sds, &bread);
1271#endif 1264#endif
1272 } 1265 }
1273 if (wfds) 1266 if (wfds)
1274 { 1267 {
1275 FD_COPY (&wfds->sds, &awrite); 1268 FD_COPY (&wfds->sds, &awrite);
1276#if DEBUG_NETWORK 1269#if DEBUG_NETWORK
1277 FD_COPY (&wfds->sds, &bwrite); 1270 FD_COPY (&wfds->sds, &bwrite);
1278#endif 1271#endif
1279 } 1272 }
1280 if (efds) 1273 if (efds)
1281 { 1274 {
1282 FD_COPY (&efds->sds, &aexcept); 1275 FD_COPY (&efds->sds, &aexcept);
1283#if DEBUG_NETWORK 1276#if DEBUG_NETWORK
1284 FD_COPY (&efds->sds, &bexcept); 1277 FD_COPY (&efds->sds, &bexcept);
1285#endif 1278#endif
1286 } 1279 }
1287 /* We will first Add the PIPES to the events */ 1280 /* We will first Add the PIPES to the events */
1288 /* Read Pipes */ 1281 /* Read Pipes */
1289 if (rfds && read_handles) 1282 if (rfds && read_handles)
1283 {
1284 struct GNUNET_CONTAINER_SList_Iterator i;
1285
1286 for (i = GNUNET_CONTAINER_slist_begin (rfds->handles);
1287 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
1288 GNUNET_CONTAINER_slist_next (&i))
1290 { 1289 {
1291 struct GNUNET_CONTAINER_SList_Iterator i; 1290 struct GNUNET_DISK_FileHandle *fh;
1292 1291
1293 for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); 1292 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
1294 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES; 1293 NULL);
1295 GNUNET_CONTAINER_slist_next (&i)) 1294 if (fh->type == GNUNET_PIPE)
1296 { 1295 {
1297 struct GNUNET_DISK_FileHandle *fh; 1296 /* Read zero bytes to check the status of the pipe */
1298
1299 fh =
1300 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
1301 NULL);
1302 if (fh->type == GNUNET_PIPE)
1303 {
1304 /* Read zero bytes to check the status of the pipe */
1305#if DEBUG_NETWORK 1297#if DEBUG_NETWORK
1306 LOG (GNUNET_ERROR_TYPE_DEBUG, 1298 LOG (GNUNET_ERROR_TYPE_DEBUG, "Reading 0 bytes from the pipe 0x%x\n",
1307 "Reading 0 bytes from the pipe 0x%x\n", fh->h); 1299 fh->h);
1308#endif 1300#endif
1309 if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead)) 1301 if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead))
1310 { 1302 {
1311 DWORD error_code = GetLastError (); 1303 DWORD error_code = GetLastError ();
1312 1304
1313 if (error_code == ERROR_IO_PENDING) 1305 if (error_code == ERROR_IO_PENDING)
1314 { 1306 {
1315#if DEBUG_NETWORK 1307#if DEBUG_NETWORK
1316 LOG (GNUNET_ERROR_TYPE_DEBUG, 1308 LOG (GNUNET_ERROR_TYPE_DEBUG,
1317 "Adding the pipe's 0x%x overlapped event to the array as %d\n", 1309 "Adding the pipe's 0x%x overlapped event to the array as %d\n",
1318 fh->h, nhandles); 1310 fh->h, nhandles);
1319#endif 1311#endif
1320 handle_array[nhandles++] = fh->oOverlapRead->hEvent; 1312 handle_array[nhandles++] = fh->oOverlapRead->hEvent;
1321 readArray[readPipes++] = fh; 1313 readArray[readPipes++] = fh;
1322 } 1314 }
1323 /* 1315 /*
1324 * else 1316 * else
1325 * { 1317 * {
1326 * SetErrnoFromWinError (error_code); 1318 * SetErrnoFromWinError (error_code);
1327 * } 1319 * }
1328 */ 1320 */
1329 } 1321 }
1330 else 1322 else
1331 { 1323 {
1332#if DEBUG_NETWORK 1324#if DEBUG_NETWORK
1333 LOG (GNUNET_ERROR_TYPE_DEBUG, 1325 LOG (GNUNET_ERROR_TYPE_DEBUG,
1334 "Adding the read ready event to the array as %d\n", 1326 "Adding the read ready event to the array as %d\n", nhandles);
1335 nhandles); 1327#endif
1336#endif 1328 handle_array[nhandles++] = hEventReadReady;
1337 handle_array[nhandles++] = hEventReadReady; 1329 readArray[readPipes++] = fh;
1338 readArray[readPipes++] = fh; 1330 }
1339 } 1331 }
1340 } 1332 else
1341 else 1333 {
1342 { 1334 GNUNET_CONTAINER_slist_add (handles_read,
1343 GNUNET_CONTAINER_slist_add (handles_read, 1335 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1344 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 1336 fh, sizeof (struct GNUNET_DISK_FileHandle));
1345 fh, 1337 }
1346 sizeof (struct
1347 GNUNET_DISK_FileHandle));
1348 }
1349 }
1350 } 1338 }
1339 }
1351 if (wfds && write_handles) 1340 if (wfds && write_handles)
1352 { 1341 {
1353#if DEBUG_NETWORK 1342#if DEBUG_NETWORK
1354 LOG (GNUNET_ERROR_TYPE_DEBUG, 1343 LOG (GNUNET_ERROR_TYPE_DEBUG,
1355 "Adding the write ready event to the array as %d\n", nhandles); 1344 "Adding the write ready event to the array as %d\n", nhandles);
1356#endif 1345#endif
1357 handle_array[nhandles++] = hEventPipeWrite; 1346 handle_array[nhandles++] = hEventPipeWrite;
1358 writePipePos = nhandles; 1347 writePipePos = nhandles;
1359 } 1348 }
1360 if (efds && ex_handles) 1349 if (efds && ex_handles)
1350 {
1351 struct GNUNET_CONTAINER_SList_Iterator i;
1352
1353 for (i = GNUNET_CONTAINER_slist_begin (efds->handles);
1354 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
1355 GNUNET_CONTAINER_slist_next (&i))
1361 { 1356 {
1362 struct GNUNET_CONTAINER_SList_Iterator i; 1357 struct GNUNET_DISK_FileHandle *fh;
1363 1358 DWORD dwBytes;
1364 for (i = GNUNET_CONTAINER_slist_begin (efds->handles); 1359
1365 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES; 1360 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
1366 GNUNET_CONTAINER_slist_next (&i)) 1361 NULL);
1367 { 1362 if (fh->type == GNUNET_PIPE)
1368 struct GNUNET_DISK_FileHandle *fh; 1363 {
1369 DWORD dwBytes; 1364 if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL))
1370 1365 {
1371 fh = 1366 GNUNET_CONTAINER_slist_add (handles_except,
1372 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i, 1367 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1373 NULL); 1368 fh,
1374 if (fh->type == GNUNET_PIPE) 1369 sizeof (struct GNUNET_DISK_FileHandle));
1375 { 1370 newretcode++;
1376 if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL)) 1371 }
1377 { 1372 }
1378 GNUNET_CONTAINER_slist_add (handles_except,
1379 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1380 fh,
1381 sizeof (struct
1382 GNUNET_DISK_FileHandle));
1383 newretcode++;
1384 }
1385 }
1386 }
1387 } 1373 }
1374 }
1388 if (nfds > 0) 1375 if (nfds > 0)
1376 {
1377 if (rfds)
1389 { 1378 {
1390 if (rfds)
1391 {
1392#if DEBUG_NETWORK 1379#if DEBUG_NETWORK
1393 LOG (GNUNET_ERROR_TYPE_DEBUG, 1380 LOG (GNUNET_ERROR_TYPE_DEBUG,
1394 "Adding the socket read event to the array as %d\n", nhandles); 1381 "Adding the socket read event to the array as %d\n", nhandles);
1395#endif 1382#endif
1396 handle_array[nhandles++] = hEventRead; 1383 handle_array[nhandles++] = hEventRead;
1397 nSockEvents++; 1384 nSockEvents++;
1398 for (i = 0; i < rfds->sds.fd_count; i++) 1385 for (i = 0; i < rfds->sds.fd_count; i++)
1399 { 1386 {
1400 WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 1387 WSAEventSelect (rfds->sds.fd_array[i], hEventRead,
1401 FD_ACCEPT | FD_READ | FD_CLOSE); 1388 FD_ACCEPT | FD_READ | FD_CLOSE);
1402 nsock++; 1389 nsock++;
1403 } 1390 }
1404 } 1391 }
1405 if (wfds) 1392 if (wfds)
1406 { 1393 {
1407 int wakeup = 0; 1394 int wakeup = 0;
1408 1395
1409#if DEBUG_NETWORK 1396#if DEBUG_NETWORK
1410 LOG (GNUNET_ERROR_TYPE_DEBUG, 1397 LOG (GNUNET_ERROR_TYPE_DEBUG,
1411 "Adding the socket write event to the array as %d\n", 1398 "Adding the socket write event to the array as %d\n", nhandles);
1412 nhandles); 1399#endif
1413#endif 1400 handle_array[nhandles++] = hEventWrite;
1414 handle_array[nhandles++] = hEventWrite; 1401 nSockEvents++;
1415 nSockEvents++; 1402 for (i = 0; i < wfds->sds.fd_count; i++)
1416 for (i = 0; i < wfds->sds.fd_count; i++) 1403 {
1417 { 1404 DWORD error;
1418 DWORD error; 1405 int status;
1419 int status; 1406
1420 1407 status = send (wfds->sds.fd_array[i], NULL, 0, 0);
1421 status = send (wfds->sds.fd_array[i], NULL, 0, 0); 1408 error = GetLastError ();
1422 error = GetLastError ();
1423#if DEBUG_NETWORK 1409#if DEBUG_NETWORK
1424 LOG (GNUNET_ERROR_TYPE_DEBUG, 1410 LOG (GNUNET_ERROR_TYPE_DEBUG,
1425 "pre-send to the socket %d returned %d (%u)\n", i, status, 1411 "pre-send to the socket %d returned %d (%u)\n", i, status, error);
1426 error); 1412#endif
1427#endif 1413 if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN))
1428 if (status == 0 1414 wakeup = 1;
1429 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) 1415 WSAEventSelect (wfds->sds.fd_array[i], hEventWrite,
1430 wakeup = 1; 1416 FD_WRITE | FD_CONNECT | FD_CLOSE);
1431 WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 1417 nsock++;
1432 FD_WRITE | FD_CONNECT | FD_CLOSE); 1418 }
1433 nsock++; 1419 if (wakeup)
1434 } 1420 SetEvent (hEventWrite);
1435 if (wakeup) 1421 }
1436 SetEvent (hEventWrite); 1422 if (efds)
1437 } 1423 {
1438 if (efds)
1439 {
1440#if DEBUG_NETWORK 1424#if DEBUG_NETWORK
1441 LOG (GNUNET_ERROR_TYPE_DEBUG, 1425 LOG (GNUNET_ERROR_TYPE_DEBUG,
1442 "Adding the socket error event to the array as %d\n", 1426 "Adding the socket error event to the array as %d\n", nhandles);
1443 nhandles); 1427#endif
1444#endif 1428 handle_array[nhandles++] = hEventException;
1445 handle_array[nhandles++] = hEventException; 1429 nSockEvents++;
1446 nSockEvents++; 1430 for (i = 0; i < efds->sds.fd_count; i++)
1447 for (i = 0; i < efds->sds.fd_count; i++) 1431 {
1448 { 1432 WSAEventSelect (efds->sds.fd_array[i], hEventException,
1449 WSAEventSelect (efds->sds.fd_array[i], hEventException, 1433 FD_OOB | FD_CLOSE);
1450 FD_OOB | FD_CLOSE); 1434 nsock++;
1451 nsock++; 1435 }
1452 }
1453 }
1454 } 1436 }
1437 }
1455 1438
1456 handle_array[nhandles] = NULL; 1439 handle_array[nhandles] = NULL;
1457 1440
@@ -1464,7 +1447,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1464 1447
1465 if (nhandles) 1448 if (nhandles)
1466 returncode = 1449 returncode =
1467 WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total); 1450 WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total);
1468#if DEBUG_NETWORK 1451#if DEBUG_NETWORK
1469 LOG (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n", 1452 LOG (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n",
1470 returncode); 1453 returncode);
@@ -1481,239 +1464,230 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1481 * GNUNET_CONTAINER_slist_append (handles_read, rfds->handles); 1464 * GNUNET_CONTAINER_slist_append (handles_read, rfds->handles);
1482 */ 1465 */
1483 if (nhandles && (returnedpos < nhandles)) 1466 if (nhandles && (returnedpos < nhandles))
1467 {
1468 DWORD waitstatus;
1469
1470 /* Do the select */
1471 if (nfds)
1484 { 1472 {
1485 DWORD waitstatus; 1473 struct timeval tvslice;
1486 1474
1487 /* Do the select */ 1475 tvslice.tv_sec = 0;
1488 if (nfds) 1476 tvslice.tv_usec = 10;
1489 { 1477 retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice);
1490 struct timeval tvslice; 1478 if (retcode == -1)
1491 1479 retcode = 0;
1492 tvslice.tv_sec = 0;
1493 tvslice.tv_usec = 10;
1494 retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice);
1495 if (retcode == -1)
1496 retcode = 0;
1497#if DEBUG_NETWORK 1480#if DEBUG_NETWORK
1498 LOG (GNUNET_ERROR_TYPE_DEBUG, "Select retcode : %d\n", retcode); 1481 LOG (GNUNET_ERROR_TYPE_DEBUG, "Select retcode : %d\n", retcode);
1499#endif 1482#endif
1500 } 1483 }
1501 /* FIXME: <= writePipePos? Really? */ 1484 /* FIXME: <= writePipePos? Really? */
1502 if ((writePipePos != -1) && (returnedpos <= writePipePos)) 1485 if ((writePipePos != -1) && (returnedpos <= writePipePos))
1503 { 1486 {
1504 GNUNET_CONTAINER_slist_append (handles_write, wfds->handles); 1487 GNUNET_CONTAINER_slist_append (handles_write, wfds->handles);
1505 retcode += write_handles; 1488 retcode += write_handles;
1506#if DEBUG_NETWORK 1489#if DEBUG_NETWORK
1507 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n"); 1490 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n");
1508#endif 1491#endif
1509 } 1492 }
1510#if DEBUG_NETWORK 1493#if DEBUG_NETWORK
1511 LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes); 1494 LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes);
1512#endif 1495#endif
1513 /* We have some pipes ready for read. */ 1496 /* We have some pipes ready for read. */
1514 /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */ 1497 /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */
1515 1498
1516 if (returnedpos < readPipes) 1499 if (returnedpos < readPipes)
1517 { 1500 {
1518 /* 1501 /*
1519 * for (i = 0; i < readPipes; i++) 1502 * for (i = 0; i < readPipes; i++)
1520 * { 1503 * {
1521 * waitstatus = WaitForSingleObject (handle_array[i], 0); 1504 * waitstatus = WaitForSingleObject (handle_array[i], 0);
1522 * LOG (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus); 1505 * LOG (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus);
1523 * if (waitstatus != WAIT_OBJECT_0) 1506 * if (waitstatus != WAIT_OBJECT_0)
1524 * continue; 1507 * continue;
1525 * GNUNET_CONTAINER_slist_add (handles_read, 1508 * GNUNET_CONTAINER_slist_add (handles_read,
1526 * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 1509 * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1527 * readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); 1510 * readArray[i], sizeof (struct GNUNET_DISK_FileHandle));
1528 * retcode++; 1511 * retcode++;
1529 * LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n"); 1512 * LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n");
1530 * } 1513 * }
1531 */ 1514 */
1532 for (i = 0; i < readPipes; i++) 1515 for (i = 0; i < readPipes; i++)
1533 { 1516 {
1534 DWORD error; 1517 DWORD error;
1535 BOOL bret; 1518 BOOL bret;
1536 1519
1537 SetLastError (0); 1520 SetLastError (0);
1538 waitstatus = 0; 1521 waitstatus = 0;
1539 bret = 1522 bret =
1540 PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, 1523 PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, NULL);
1541 NULL); 1524 error = GetLastError ();
1542 error = GetLastError ();
1543#if DEBUG_NETWORK 1525#if DEBUG_NETWORK
1544 LOG (GNUNET_ERROR_TYPE_DEBUG, 1526 LOG (GNUNET_ERROR_TYPE_DEBUG,
1545 "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n", 1527 "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n",
1546 i, readArray[i]->h, bret, waitstatus, error); 1528 i, readArray[i]->h, bret, waitstatus, error);
1547#endif 1529#endif
1548 if (bret == 0) 1530 if (bret == 0)
1549 { 1531 {
1550 if (error != ERROR_BROKEN_PIPE) 1532 if (error != ERROR_BROKEN_PIPE)
1551 continue; 1533 continue;
1552 } 1534 }
1553 else if (waitstatus <= 0) 1535 else if (waitstatus <= 0)
1554 continue; 1536 continue;
1555 GNUNET_CONTAINER_slist_add (handles_read, 1537 GNUNET_CONTAINER_slist_add (handles_read,
1556 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 1538 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1557 readArray[i], 1539 readArray[i],
1558 sizeof (struct 1540 sizeof (struct GNUNET_DISK_FileHandle));
1559 GNUNET_DISK_FileHandle)); 1541 retcode++;
1560 retcode++;
1561#if DEBUG_NETWORK 1542#if DEBUG_NETWORK
1562 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n", 1543 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n",
1563 readArray[i], readArray[i]->h); 1544 readArray[i], readArray[i]->h);
1564#endif 1545#endif
1565 } 1546 }
1566 } 1547 }
1567 waitstatus = WaitForSingleObject (hEventWrite, 0); 1548 waitstatus = WaitForSingleObject (hEventWrite, 0);
1568#if DEBUG_NETWORK 1549#if DEBUG_NETWORK
1569 LOG (GNUNET_ERROR_TYPE_DEBUG, 1550 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wait for the write event returned %d\n",
1570 "Wait for the write event returned %d\n", waitstatus); 1551 waitstatus);
1571#endif 1552#endif
1572 if (waitstatus == WAIT_OBJECT_0) 1553 if (waitstatus == WAIT_OBJECT_0)
1573 { 1554 {
1574 for (i = 0; i < wfds->sds.fd_count; i++) 1555 for (i = 0; i < wfds->sds.fd_count; i++)
1575 { 1556 {
1576 DWORD error; 1557 DWORD error;
1577 int status; 1558 int status;
1578 int so_error = 0; 1559 int so_error = 0;
1579 int sizeof_so_error = sizeof (so_error); 1560 int sizeof_so_error = sizeof (so_error);
1580 int gso_result = 1561 int gso_result =
1581 getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR, 1562 getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR,
1582 (char *) &so_error, &sizeof_so_error); 1563 (char *) &so_error, &sizeof_so_error);
1583 1564
1584 status = send (wfds->sds.fd_array[i], NULL, 0, 0); 1565 status = send (wfds->sds.fd_array[i], NULL, 0, 0);
1585 error = GetLastError (); 1566 error = GetLastError ();
1586#if DEBUG_NETWORK 1567#if DEBUG_NETWORK
1587 LOG (GNUNET_ERROR_TYPE_DEBUG, 1568 LOG (GNUNET_ERROR_TYPE_DEBUG,
1588 "send to the socket %d returned %d (%u)\n", i, status, 1569 "send to the socket %d returned %d (%u)\n", i, status, error);
1589 error); 1570#endif
1590#endif 1571 if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) ||
1591 if (status == 0 1572 (status == -1 && gso_result == 0 && error == WSAENOTCONN &&
1592 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) 1573 so_error == WSAECONNREFUSED))
1593 || (status == -1 && gso_result == 0 && error == WSAENOTCONN 1574 {
1594 && so_error == WSAECONNREFUSED)) 1575 FD_SET (wfds->sds.fd_array[i], &awrite);
1595 { 1576 retcode += 1;
1596 FD_SET (wfds->sds.fd_array[i], &awrite); 1577 }
1597 retcode += 1; 1578 }
1598 }
1599 }
1600 }
1601 } 1579 }
1580 }
1602#if DEBUG_NETWORK 1581#if DEBUG_NETWORK
1603 if (!nhandles || (returnedpos >= nhandles)) 1582 if (!nhandles || (returnedpos >= nhandles))
1604 LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n"); 1583 LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n");
1605#endif 1584#endif
1606 if (rfds) 1585 if (rfds)
1586 {
1587 struct GNUNET_CONTAINER_SList_Iterator t;
1588
1589 for (i = 0; i < rfds->sds.fd_count; i++)
1607 { 1590 {
1608 struct GNUNET_CONTAINER_SList_Iterator t; 1591 WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0);
1592 nsock++;
1593 }
1594 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1595 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1596 GNUNET_CONTAINER_slist_next (&t))
1597 {
1598 struct GNUNET_DISK_FileHandle *fh;
1609 1599
1610 for (i = 0; i < rfds->sds.fd_count; i++) 1600 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1611 { 1601 NULL);
1612 WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0); 1602 if (fh->type == GNUNET_PIPE)
1613 nsock++; 1603 {
1614 } 1604 CancelIo (fh->h);
1615 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); 1605 }
1616 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; 1606 }
1617 GNUNET_CONTAINER_slist_next (&t))
1618 {
1619 struct GNUNET_DISK_FileHandle *fh;
1620
1621 fh =
1622 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1623 NULL);
1624 if (fh->type == GNUNET_PIPE)
1625 {
1626 CancelIo (fh->h);
1627 }
1628 }
1629#if DEBUG_NETWORK 1607#if DEBUG_NETWORK
1630 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n"); 1608 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n");
1631#endif 1609#endif
1632 GNUNET_NETWORK_fdset_zero (rfds); 1610 GNUNET_NETWORK_fdset_zero (rfds);
1633 if (retcode != -1 && nhandles && (returnedpos < nhandles)) 1611 if (retcode != -1 && nhandles && (returnedpos < nhandles))
1634 GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); 1612 GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode);
1635 GNUNET_CONTAINER_slist_append (rfds->handles, handles_read); 1613 GNUNET_CONTAINER_slist_append (rfds->handles, handles_read);
1636 } 1614 }
1637 if (wfds) 1615 if (wfds)
1616 {
1617 for (i = 0; i < wfds->sds.fd_count; i++)
1638 { 1618 {
1639 for (i = 0; i < wfds->sds.fd_count; i++) 1619 WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 0);
1640 { 1620 nsock++;
1641 WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 0); 1621 }
1642 nsock++;
1643 }
1644#if DEBUG_NETWORK 1622#if DEBUG_NETWORK
1645 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing wfds\n"); 1623 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing wfds\n");
1646#endif 1624#endif
1647 GNUNET_NETWORK_fdset_zero (wfds); 1625 GNUNET_NETWORK_fdset_zero (wfds);
1648 if (retcode != -1 && nhandles && (returnedpos < nhandles)) 1626 if (retcode != -1 && nhandles && (returnedpos < nhandles))
1649 GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); 1627 GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode);
1650 GNUNET_CONTAINER_slist_append (wfds->handles, handles_write); 1628 GNUNET_CONTAINER_slist_append (wfds->handles, handles_write);
1651 } 1629 }
1652 if (efds) 1630 if (efds)
1631 {
1632 for (i = 0; i < efds->sds.fd_count; i++)
1653 { 1633 {
1654 for (i = 0; i < efds->sds.fd_count; i++) 1634 WSAEventSelect (efds->sds.fd_array[i], hEventException, 0);
1655 { 1635 nsock++;
1656 WSAEventSelect (efds->sds.fd_array[i], hEventException, 0); 1636 }
1657 nsock++;
1658 }
1659#if DEBUG_NETWORK 1637#if DEBUG_NETWORK
1660 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing efds\n"); 1638 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing efds\n");
1661#endif 1639#endif
1662 GNUNET_NETWORK_fdset_zero (efds); 1640 GNUNET_NETWORK_fdset_zero (efds);
1663 if (retcode != -1 && nhandles && (returnedpos < nhandles)) 1641 if (retcode != -1 && nhandles && (returnedpos < nhandles))
1664 GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); 1642 GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode);
1665 GNUNET_CONTAINER_slist_append (efds->handles, handles_except); 1643 GNUNET_CONTAINER_slist_append (efds->handles, handles_except);
1666 } 1644 }
1667 GNUNET_CONTAINER_slist_destroy (handles_read); 1645 GNUNET_CONTAINER_slist_destroy (handles_read);
1668 GNUNET_CONTAINER_slist_destroy (handles_write); 1646 GNUNET_CONTAINER_slist_destroy (handles_write);
1669 GNUNET_CONTAINER_slist_destroy (handles_except); 1647 GNUNET_CONTAINER_slist_destroy (handles_except);
1670#if DEBUG_NETWORK 1648#if DEBUG_NETWORK
1671 if (rfds) 1649 if (rfds)
1650 {
1651 struct GNUNET_CONTAINER_SList_Iterator t;
1652
1653 for (i = 0; i < bread.fd_count; i++)
1672 { 1654 {
1673 struct GNUNET_CONTAINER_SList_Iterator t; 1655 if (bread.fd_array[i] != 0)
1656 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n",
1657 bread.fd_array[i],
1658 (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" : "NOT SET");
1659 }
1660 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1661 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1662 GNUNET_CONTAINER_slist_next (&t))
1663 {
1664 struct GNUNET_DISK_FileHandle *fh;
1674 1665
1675 for (i = 0; i < bread.fd_count; i++) 1666 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1676 { 1667 NULL);
1677 if (bread.fd_array[i] != 0) 1668 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h);
1678 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n",
1679 bread.fd_array[i],
1680 (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" :
1681 "NOT SET");
1682 }
1683 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1684 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1685 GNUNET_CONTAINER_slist_next (&t))
1686 {
1687 struct GNUNET_DISK_FileHandle *fh;
1688
1689 fh =
1690 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1691 NULL);
1692 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h);
1693 }
1694 } 1669 }
1670 }
1695 if (wfds) 1671 if (wfds)
1672 {
1673 for (i = 0; i < bwrite.fd_count; i++)
1696 { 1674 {
1697 for (i = 0; i < bwrite.fd_count; i++) 1675 if (bwrite.fd_array[i] != 0)
1698 { 1676 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n",
1699 if (bwrite.fd_array[i] != 0) 1677 bwrite.fd_array[i],
1700 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n", 1678 (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" : "NOT SET");
1701 bwrite.fd_array[i],
1702 (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" :
1703 "NOT SET");
1704 }
1705 } 1679 }
1680 }
1706 if (efds) 1681 if (efds)
1682 {
1683 for (i = 0; i < bexcept.fd_count; i++)
1707 { 1684 {
1708 for (i = 0; i < bexcept.fd_count; i++) 1685 if (bexcept.fd_array[i] != 0)
1709 { 1686 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n",
1710 if (bexcept.fd_array[i] != 0) 1687 bexcept.fd_array[i],
1711 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n", 1688 (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" : "NOT SET");
1712 bexcept.fd_array[i],
1713 (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" :
1714 "NOT SET");
1715 }
1716 } 1689 }
1690 }
1717 LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode); 1691 LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode);
1718#endif 1692#endif
1719 if (nhandles && (returnedpos < nhandles)) 1693 if (nhandles && (returnedpos < nhandles))