2 This file is part of GNUnet.
\r
3 (C) 2009 Christian Grothoff (and other contributing authors)
\r
5 GNUnet is free software; you can redistribute it and/or modify
\r
6 it under the terms of the GNU General Public License as published
\r
7 by the Free Software Foundation; either version 2, or (at your
\r
8 option) any later version.
\r
10 GNUnet is distributed in the hope that it will be useful, but
\r
11 WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
13 General Public License for more details.
\r
15 You should have received a copy of the GNU General Public License
\r
16 along with GNUnet; see the file COPYING. If not, write to the
\r
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
\r
18 Boston, MA 02111-1307, USA.
\r
22 * @file util/network.c
\r
23 * @brief basic, low-level networking interface
\r
24 * @author Nils Durner
\r
27 #include "platform.h"
\r
28 #include "gnunet_disk_lib.h"
\r
30 #include "gnunet_container_lib.h"
\r
32 #define DEBUG_SOCK GNUNET_NO
\r
34 #ifndef INVALID_SOCKET
\r
35 #define INVALID_SOCKET -1
\r
38 struct GNUNET_NETWORK_Handle
\r
43 struct GNUNET_NETWORK_FDSet
\r
45 /* socket descriptors */
\r
50 struct GNUNET_CONTAINER_SList *handles;
\r
55 #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set)))
\r
61 * Set if a socket should use blocking or non-blocking IO.
\r
63 * @param doBlock blocking mode
\r
64 * @return GNUNET_OK on success, GNUNET_SYSERR on error
\r
67 socket_set_blocking (struct GNUNET_NETWORK_Handle *fd,
\r
73 if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR)
\r
75 SetErrnoFromWinsockError (WSAGetLastError ());
\r
76 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket");
\r
77 return GNUNET_SYSERR;
\r
83 int flags = fcntl (fd->fd, F_GETFL);
\r
86 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
\r
87 return GNUNET_SYSERR;
\r
90 flags &= ~O_NONBLOCK;
\r
92 flags |= O_NONBLOCK;
\r
93 if (0 != fcntl (fd->fd, F_SETFL, flags))
\r
95 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
\r
96 return GNUNET_SYSERR;
\r
105 * Make a non-inheritable to child processes
\r
107 * @param h the socket to make non-inheritable
\r
108 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
\r
109 * @warning Not implemented on Windows
\r
112 socket_set_inheritable (const struct GNUNET_NETWORK_Handle
\r
117 i = fcntl (h->fd, F_GETFD);
\r
118 if (i == (i | FD_CLOEXEC))
\r
120 return (fcntl (h->fd, F_SETFD, i | FD_CLOEXEC) == 0)
\r
121 ? GNUNET_OK : GNUNET_SYSERR;
\r
128 * accept a new connection on a socket
\r
130 * @param desc bound socket
\r
131 * @param address address of the connecting peer, may be NULL
\r
132 * @param address_len length of address
\r
133 * @return client socket
\r
135 struct GNUNET_NETWORK_Handle *
\r
136 GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
\r
137 struct sockaddr *address,
\r
138 socklen_t * address_len)
\r
140 struct GNUNET_NETWORK_Handle *ret;
\r
142 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
\r
143 ret->fd = accept (desc->fd, address, address_len);
\r
144 if (ret->fd == INVALID_SOCKET)
\r
147 SetErrnoFromWinsockError (WSAGetLastError ());
\r
153 if (ret->fd >= FD_SETSIZE)
\r
161 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
\r
163 /* we might want to treat this one as fatal... */
\r
165 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
\r
169 if (GNUNET_OK != socket_set_inheritable (ret))
\r
170 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
\r
171 "socket_set_inheritable");
\r
177 * Bind to a connected socket
\r
178 * @param desc socket
\r
179 * @param address address to be bound
\r
180 * @param address_len length of address
\r
181 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
\r
184 GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
\r
185 const struct sockaddr *address,
\r
186 socklen_t address_len)
\r
190 ret = bind (desc->fd, address, address_len);
\r
192 if (SOCKET_ERROR == ret)
\r
193 SetErrnoFromWinsockError (WSAGetLastError ());
\r
195 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
\r
201 * @param desc socket
\r
202 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
\r
205 GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
\r
211 ret = closesocket (desc->fd);
\r
212 SetErrnoFromWinsockError (WSAGetLastError ());
\r
214 ret = close (desc->fd);
\r
217 GNUNET_free (desc);
\r
219 return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
\r
224 * @param desc socket
\r
225 * @param address peer address
\r
226 * @param address_len length of address
\r
227 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
\r
230 GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
\r
231 const struct sockaddr *address,
\r
232 socklen_t address_len)
\r
236 ret = connect (desc->fd, address, address_len);
\r
238 if (SOCKET_ERROR == ret)
\r
240 SetErrnoFromWinsockError (WSAGetLastError ());
\r
241 if (errno == EWOULDBLOCK)
\r
242 errno = EINPROGRESS;
\r
245 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
\r
249 * Get socket options
\r
251 * @param desc socket
\r
252 * @param level protocol level of the option
\r
253 * @param optname identifier of the option
\r
254 * @param optval options
\r
255 * @param optlen length of optval
\r
256 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
\r
259 GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc,
\r
260 int level, int optname, void *optval,
\r
261 socklen_t * optlen)
\r
265 ret = getsockopt (desc->fd, level, optname, optval, optlen);
\r
267 if (ret == 0 && level == SOL_SOCKET && optname == SO_ERROR)
\r
268 *((int *) optval) = GetErrnoFromWinsockError (*((int *) optval));
\r
269 else if (SOCKET_ERROR == ret)
\r
270 SetErrnoFromWinsockError (WSAGetLastError ());
\r
272 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
\r
276 * Listen on a socket
\r
277 * @param desc socket
\r
278 * @param backlog length of the listen queue
\r
279 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
\r
282 GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
\r
287 ret = listen (desc->fd, backlog);
\r
289 if (SOCKET_ERROR == ret)
\r
290 SetErrnoFromWinsockError (WSAGetLastError ());
\r
293 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
\r
297 * Read data from a connected socket (always non-blocking).
\r
298 * @param desc socket
\r
299 * @param buffer buffer
\r
300 * @param length length of buffer
\r
303 GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc,
\r
304 void *buffer, size_t length)
\r
310 #ifdef MSG_DONTWAIT
\r
311 flags |= MSG_DONTWAIT;
\r
313 ret = recv (desc->fd, buffer, length, flags);
\r
315 if (SOCKET_ERROR == ret)
\r
316 SetErrnoFromWinsockError (WSAGetLastError ());
\r
323 * Send data (always non-blocking).
\r
325 * @param desc socket
\r
326 * @param buffer data to send
\r
327 * @param length size of the buffer
\r
328 * @return number of bytes sent, GNUNET_SYSERR on error
\r
331 GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc,
\r
332 const void *buffer, size_t length)
\r
339 /* shouldn't matter if this fails as there's a SIGPIPE handler */
\r
340 ret = setsockopt (desc->fd, SOL_SOCKET, SO_NOSIGPIPE,
\r
341 (void *) &no_sigpipe, sizeof (no_sigpipe));
\r
345 #ifdef MSG_DONTWAIT
\r
346 flags |= MSG_DONTWAIT;
\r
348 #ifdef MSG_NOSIGNAL
\r
349 flags |= MSG_NOSIGNAL;
\r
351 ret = send (desc->fd, buffer, length, flags);
\r
353 if (SOCKET_ERROR == ret)
\r
354 SetErrnoFromWinsockError (WSAGetLastError ());
\r
362 * Send data to a particular destination (always non-blocking).
\r
363 * This function only works for UDP sockets.
\r
365 * @param desc socket
\r
366 * @param message data to send
\r
367 * @param length size of the data
\r
368 * @param dest_addr destination address
\r
369 * @param dest_len length of address
\r
370 * @return number of bytes sent, GNUNET_SYSERR on error
\r
373 GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
\r
374 const void *message, size_t length,
\r
375 const struct sockaddr * dest_addr,
\r
376 socklen_t dest_len)
\r
383 /* shouldn't matter if this fails as there's a SIGPIPE handler */
\r
384 ret = setsockopt (desc->fd, SOL_SOCKET, SO_NOSIGPIPE,
\r
385 (void *) &no_sigpipe, sizeof (no_sigpipe));
\r
389 #ifdef MSG_DONTWAIT
\r
390 flags |= MSG_DONTWAIT;
\r
392 #ifdef MSG_NOSIGNAL
\r
393 flags |= MSG_NOSIGNAL;
\r
395 ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len);
\r
397 if (SOCKET_ERROR == ret)
\r
398 SetErrnoFromWinsockError (WSAGetLastError ());
\r
405 * Set socket option
\r
407 * @param level protocol level of the option
\r
408 * @param option_name option identifier
\r
409 * @param option_value value to set
\r
410 * @param option_len size of option_value
\r
411 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
\r
414 GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd,
\r
415 int level, int option_name,
\r
416 const void *option_value,
\r
417 socklen_t option_len)
\r
421 ret = setsockopt (fd->fd, level, option_name, option_value, option_len);
\r
423 if (SOCKET_ERROR == ret)
\r
424 SetErrnoFromWinsockError (WSAGetLastError ());
\r
427 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
\r
433 * Create a new socket. Configure it for non-blocking IO and
\r
434 * mark it as non-inheritable to child processes (set the
\r
435 * close-on-exec flag).
\r
437 * @param domain domain of the socket
\r
438 * @param type socket type
\r
439 * @param protocol network protocol
\r
440 * @return new socket, NULL on error
\r
442 struct GNUNET_NETWORK_Handle *
\r
443 GNUNET_NETWORK_socket_create (int domain, int type, int protocol)
\r
445 struct GNUNET_NETWORK_Handle *ret;
\r
447 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
\r
448 ret->fd = socket (domain, type, protocol);
\r
449 if (INVALID_SOCKET == ret->fd)
\r
452 SetErrnoFromWinsockError (WSAGetLastError ());
\r
458 if (ret->fd >= FD_SETSIZE)
\r
467 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
\r
469 /* we might want to treat this one as fatal... */
\r
471 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
\r
475 if (GNUNET_OK != socket_set_inheritable (ret))
\r
476 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
\r
477 "socket_set_inheritable");
\r
484 * Shut down socket operations
\r
485 * @param desc socket
\r
486 * @param how type of shutdown
\r
487 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
\r
490 GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc,
\r
495 ret = shutdown (desc->fd, how);
\r
498 SetErrnoFromWinsockError (WSAGetLastError ());
\r
501 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
\r
507 * @param fds fd set
\r
510 GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds)
\r
512 FD_ZERO (&fds->sds);
\r
515 GNUNET_CONTAINER_slist_clear (fds->handles);
\r
521 * Add a socket to the FD set
\r
522 * @param fds fd set
\r
523 * @param desc socket to add
\r
526 GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds,
\r
527 const struct GNUNET_NETWORK_Handle *desc)
\r
529 FD_SET (desc->fd, &fds->sds);
\r
531 if (desc->fd + 1 > fds->nsds)
\r
532 fds->nsds = desc->fd + 1;
\r
537 * Check whether a socket is part of the fd set
\r
538 * @param fds fd set
\r
539 * @param desc socket
\r
540 * @return 0 if the FD is not set
\r
543 GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
\r
544 const struct GNUNET_NETWORK_Handle *desc)
\r
546 return FD_ISSET (desc->fd, &fds->sds);
\r
551 * Add one fd set to another
\r
552 * @param dst the fd set to add to
\r
553 * @param src the fd set to add from
\r
556 GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
\r
557 const struct GNUNET_NETWORK_FDSet *src)
\r
561 for (nfds = src->nsds; nfds > 0; nfds--)
\r
562 if (FD_ISSET (nfds, &src->sds))
\r
564 FD_SET (nfds, &dst->sds);
\r
565 if (nfds + 1 > dst->nsds)
\r
566 dst->nsds = nfds + 1;
\r
572 * Copy one fd set to another
\r
573 * @param to destination
\r
574 * @param from source
\r
577 GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
\r
578 const struct GNUNET_NETWORK_FDSet *from)
\r
580 FD_COPY (&from->sds, &to->sds);
\r
581 to->nsds = from->nsds;
\r
583 struct GNUNET_CONTAINER_SList_Iterator *iter;
\r
586 GNUNET_CONTAINER_slist_clear (to->handles);
\r
588 for (iter = GNUNET_CONTAINER_slist_begin (from->handles);
\r
589 GNUNET_CONTAINER_slist_end (iter) != GNUNET_YES; GNUNET_CONTAINER_slist_next (iter))
\r
594 handle = GNUNET_CONTAINER_slist_get (iter, &len);
\r
595 GNUNET_CONTAINER_slist_add (to->handles, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, handle, len);
\r
602 * Copy a native fd set
\r
603 * @param to destination
\r
604 * @param from native source set
\r
605 * @param nfds the biggest socket number in from + 1
\r
608 GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to,
\r
609 const fd_set * from, int nfds)
\r
611 FD_COPY (from, &to->sds);
\r
617 * Add a file handle to the fd set
\r
618 * @param fds fd set
\r
619 * @param h the file handle to add
\r
622 GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
\r
623 const struct GNUNET_DISK_FileHandle *h)
\r
628 GNUNET_DISK_internal_file_handle_ (h, &hw, sizeof (HANDLE));
\r
629 GNUNET_CONTAINER_slist_add (fds->handles, GNUNET_NO, &hw, sizeof (HANDLE));
\r
633 GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int));
\r
634 FD_SET (fd, &fds->sds);
\r
635 if (fd + 1 > fds->nsds)
\r
636 fds->nsds = fd + 1;
\r
641 * Check if a file handle is part of an fd set
\r
642 * @param fds fd set
\r
643 * @param h file handle
\r
644 * @return GNUNET_YES if the file handle is part of the set
\r
647 GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
\r
648 const struct GNUNET_DISK_FileHandle *h)
\r
651 return GNUNET_CONTAINER_slist_contains (fds->handles, h->h, sizeof (HANDLE));
\r
653 return FD_ISSET (h->fd, &fds->sds);
\r
658 * Checks if two fd sets overlap
\r
659 * @param fds1 first fd set
\r
660 * @param fds2 second fd set
\r
661 * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise
\r
664 GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
\r
665 const struct GNUNET_NETWORK_FDSet *fds2)
\r
670 if (nfds < fds2->nsds)
\r
673 for (; nfds >= 0; nfds--)
\r
674 if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds))
\r
681 * Creates an fd set
\r
682 * @return a new fd set
\r
684 struct GNUNET_NETWORK_FDSet *
\r
685 GNUNET_NETWORK_fdset_create ()
\r
687 struct GNUNET_NETWORK_FDSet *fds;
\r
689 fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet));
\r
691 fds->handles = GNUNET_CONTAINER_slist_create ();
\r
693 GNUNET_NETWORK_fdset_zero (fds);
\r
699 * Releases the associated memory of an fd set
\r
700 * @param fds fd set
\r
703 GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds)
\r
706 GNUNET_CONTAINER_slist_destroy (fds->handles);
\r
713 * Check if sockets meet certain conditions
\r
714 * @param rfds set of sockets to be checked for readability
\r
715 * @param wfds set of sockets to be checked for writability
\r
716 * @param efds set of sockets to be checked for exceptions
\r
717 * @param timeout relative value when to return
\r
718 * @return number of selected sockets, GNUNET_SYSERR on error
\r
721 GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
\r
722 struct GNUNET_NETWORK_FDSet *wfds,
\r
723 struct GNUNET_NETWORK_FDSet *efds,
\r
724 const struct GNUNET_TIME_Relative timeout)
\r
732 nfds = GNUNET_MAX (nfds, wfds->nsds);
\r
734 nfds = GNUNET_MAX (nfds, efds->nsds);
\r
739 tv.tv_sec = timeout.value / GNUNET_TIME_UNIT_SECONDS.value;
\r
740 tv.tv_usec = 1000 * (timeout.value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.value));
\r
741 if ( (nfds == 0) &&
\r
742 (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value) )
\r
744 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
\r
745 _("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"),
\r
749 return select (nfds + 1,
\r
750 (rfds != NULL) ? &rfds->sds : NULL,
\r
751 (wfds != NULL) ? &wfds->sds : NULL,
\r
752 (efds != NULL) ? &efds->sds : NULL,
\r
753 (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
\r
758 fd_set sock_read, sock_write, sock_except;
\r
759 fd_set aread, awrite, aexcept;
\r
761 struct timeval tvslice;
\r
765 #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
\r
767 /* calculate how long we need to wait in milliseconds */
\r
768 if (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
\r
769 ms_total = INFINITE;
\r
771 ms_total = timeout.value / GNUNET_TIME_UNIT_MILLISECONDS.value;
\r
773 /* select() may be used as a portable way to sleep */
\r
774 if (!(rfds || wfds || efds))
\r
781 sock_read = rfds->sds;
\r
783 FD_ZERO(&sock_read);
\r
786 sock_write = wfds->sds;
\r
788 FD_ZERO(&sock_write);
\r
791 sock_except = efds->sds;
\r
793 FD_ZERO(&sock_except);
\r
795 /* multiplex between winsock select() and waiting on the handles */
\r
799 FD_ZERO (&aexcept);
\r
801 limit = GetTickCount () + ms_total;
\r
808 /* overwrite the zero'd sets here; the select call
\r
809 * will clear those that are not active */
\r
811 FD_COPY (&sock_read, &aread);
\r
812 FD_COPY (&sock_write, &awrite);
\r
813 FD_COPY (&sock_except, &aexcept);
\r
815 tvslice.tv_sec = 0;
\r
816 tvslice.tv_usec = 100000;
\r
819 select (nfds + 1, &aread, &awrite, &aexcept,
\r
820 &tvslice)) == SOCKET_ERROR)
\r
822 SetErrnoFromWinsockError (WSAGetLastError ());
\r
823 if (errno == ENOTSOCK)
\r
827 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select");
\r
830 goto select_loop_end;
\r
834 /* Poll read pipes */
\r
837 struct GNUNET_CONTAINER_SList_Iterator *i;
\r
840 on_next = GNUNET_NO;
\r
841 for (i = GNUNET_CONTAINER_slist_begin (rfds->handles);
\r
842 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES;
\r
843 on_next || GNUNET_CONTAINER_slist_next (i))
\r
848 h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL);
\r
849 on_next = GNUNET_NO;
\r
851 if (!PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL))
\r
853 GNUNET_CONTAINER_slist_erase (i);
\r
854 on_next = GNUNET_YES;
\r
857 SetErrnoFromWinError (GetLastError ());
\r
859 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "PeekNamedPipe");
\r
861 goto select_loop_end;
\r
869 GNUNET_CONTAINER_slist_erase (i);
\r
870 on_next = GNUNET_YES;
\r
875 /* Poll for faulty pipes */
\r
878 struct GNUNET_CONTAINER_SList_Iterator *i;
\r
881 on_next = GNUNET_NO;
\r
882 for (i = GNUNET_CONTAINER_slist_begin (efds->handles);
\r
883 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES;
\r
884 on_next || GNUNET_CONTAINER_slist_next (i))
\r
889 h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL);
\r
891 if (PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL))
\r
893 GNUNET_CONTAINER_slist_erase (i);
\r
894 on_next = GNUNET_YES;
\r
899 on_next = GNUNET_NO;
\r
905 GNUNET_assert (GNUNET_CONTAINER_slist_count (wfds->handles) == 0);
\r
907 /* Check for closed sockets */
\r
908 for (i = 0; i < nfds; i++)
\r
910 if (SAFE_FD_ISSET (i, &sock_read))
\r
912 struct sockaddr addr;
\r
915 if (getpeername (i, &addr, &len) == SOCKET_ERROR)
\r
919 len = sizeof (err);
\r
921 (i, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == 0
\r
922 && err == WSAENOTCONN)
\r
924 if (!SAFE_FD_ISSET (i, &aread))
\r
926 FD_SET (i, &aread);
\r
936 while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit));
\r
942 GNUNET_NETWORK_fdset_zero (rfds);
\r
943 GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode);
\r
948 GNUNET_NETWORK_fdset_zero (wfds);
\r
949 GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode);
\r
954 GNUNET_NETWORK_fdset_zero (efds);
\r
955 GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode);
\r
964 /* end of network.c */
\r