2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file util/network.c
23 * @brief basic, low-level networking interface
28 #include "gnunet_disk_lib.h"
30 #include "gnunet_container_lib.h"
32 #define DEBUG_NETWORK GNUNET_NO
34 #ifndef INVALID_SOCKET
35 #define INVALID_SOCKET -1
39 struct GNUNET_NETWORK_Handle
49 struct GNUNET_NETWORK_FDSet
53 * Maximum number of any socket socket descriptor in the set
58 * Bitset with the descriptors.
64 * Linked list of handles
66 struct GNUNET_CONTAINER_SList *handles;
72 #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set)))
77 * Set if a socket should use blocking or non-blocking IO.
79 * @param doBlock blocking mode
80 * @return GNUNET_OK on success, GNUNET_SYSERR on error
83 socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock)
89 if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR)
92 SetErrnoFromWinsockError (WSAGetLastError ());
93 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket");
100 int flags = fcntl (fd->fd, F_GETFL);
104 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
105 return GNUNET_SYSERR;
108 flags &= ~O_NONBLOCK;
112 if (0 != fcntl (fd->fd, F_SETFL, flags))
115 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
116 return GNUNET_SYSERR;
125 * Make a socket non-inheritable to child processes
127 * @param h the socket to make non-inheritable
128 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
129 * @warning Not implemented on Windows
132 socket_set_inheritable (const struct GNUNET_NETWORK_Handle *h)
135 i = fcntl (h->fd, F_GETFD);
136 if (i == (i | FD_CLOEXEC))
138 return (fcntl (h->fd, F_SETFD, i | FD_CLOEXEC) == 0)
139 ? GNUNET_OK : GNUNET_SYSERR;
146 * The MSG_NOSIGNAL equivalent on Mac OS X
148 * @param h the socket to make non-delaying
151 socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h)
155 setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof (value)))
156 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
162 * Disable delays when sending data via the socket.
163 * (GNUnet makes sure that messages are as big as
166 * @param h the socket to make non-delaying
169 socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
173 setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value)))
174 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
179 * accept a new connection on a socket
181 * @param desc bound socket
182 * @param address address of the connecting peer, may be NULL
183 * @param address_len length of address
184 * @return client socket
186 struct GNUNET_NETWORK_Handle *
187 GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
188 struct sockaddr *address,
189 socklen_t * address_len)
191 struct GNUNET_NETWORK_Handle *ret;
192 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
193 ret->fd = accept (desc->fd, address, address_len);
194 if (ret->fd == INVALID_SOCKET)
197 SetErrnoFromWinsockError (WSAGetLastError ());
203 if (ret->fd >= FD_SETSIZE)
205 GNUNET_break (0 == close (ret->fd));
211 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
215 /* we might want to treat this one as fatal... */
217 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
222 if (GNUNET_OK != socket_set_inheritable (ret))
223 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
224 "socket_set_inheritable");
227 socket_set_nosigpipe (ret);
229 socket_set_nodelay (ret);
235 * Bind to a connected socket
237 * @param address address to be bound
238 * @param address_len length of address
239 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
242 GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
243 const struct sockaddr *address,
244 socklen_t address_len)
248 ret = bind (desc->fd, address, address_len);
250 if (SOCKET_ERROR == ret)
251 SetErrnoFromWinsockError (WSAGetLastError ());
253 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
260 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
263 GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
269 ret = closesocket (desc->fd);
270 SetErrnoFromWinsockError (WSAGetLastError ());
272 ret = close (desc->fd);
277 return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
284 * @param address peer address
285 * @param address_len length of address
286 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
289 GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
290 const struct sockaddr *address,
291 socklen_t address_len)
294 ret = connect (desc->fd, address, address_len);
297 if (SOCKET_ERROR == ret)
300 SetErrnoFromWinsockError (WSAGetLastError ());
301 if (errno == EWOULDBLOCK)
305 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
313 * @param level protocol level of the option
314 * @param optname identifier of the option
315 * @param optval options
316 * @param optlen length of optval
317 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
320 GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc,
321 int level, int optname, void *optval,
325 ret = getsockopt (desc->fd, level, optname, optval, optlen);
328 if (ret == 0 && level == SOL_SOCKET && optname == SO_ERROR)
329 *((int *) optval) = GetErrnoFromWinsockError (*((int *) optval));
331 else if (SOCKET_ERROR == ret)
332 SetErrnoFromWinsockError (WSAGetLastError ());
335 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
342 * @param backlog length of the listen queue
343 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
346 GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
350 ret = listen (desc->fd, backlog);
353 if (SOCKET_ERROR == ret)
354 SetErrnoFromWinsockError (WSAGetLastError ());
357 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
362 * How much data is available to be read on this descriptor?
364 * Returns GNUNET_NO if no data is available, or on error!
368 GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle
374 /* How much is there to be read? */
376 error = ioctl (desc->fd, FIONREAD, &pending);
379 error = ioctlsocket (desc->fd, FIONREAD, &pending);
380 if (error != SOCKET_ERROR)
388 * Read data from a connected socket (always non-blocking).
390 * @param buffer buffer
391 * @param length length of buffer
392 * @param src_addr either the source to recv from, or all zeroes
393 * to be filled in by recvfrom
394 * @param addrlen length of the addr
397 GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc,
398 void *buffer, size_t length,
399 struct sockaddr * src_addr,
407 flags |= MSG_DONTWAIT;
410 ret = recvfrom (desc->fd, buffer, length, flags, src_addr, addrlen);
412 if (SOCKET_ERROR == ret)
413 SetErrnoFromWinsockError (WSAGetLastError ());
420 * Read data from a connected socket (always non-blocking).
422 * @param buffer buffer
423 * @param length length of buffer
426 GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc,
427 void *buffer, size_t length)
434 flags |= MSG_DONTWAIT;
436 ret = recv (desc->fd, buffer, length, flags);
438 if (SOCKET_ERROR == ret)
439 SetErrnoFromWinsockError (WSAGetLastError ());
446 * Send data (always non-blocking).
449 * @param buffer data to send
450 * @param length size of the buffer
451 * @return number of bytes sent, GNUNET_SYSERR on error
454 GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc,
455 const void *buffer, size_t length)
462 flags |= MSG_DONTWAIT;
466 flags |= MSG_NOSIGNAL;
469 ret = send (desc->fd, buffer, length, flags);
472 if (SOCKET_ERROR == ret)
473 SetErrnoFromWinsockError (WSAGetLastError ());
481 * Send data to a particular destination (always non-blocking).
482 * This function only works for UDP sockets.
485 * @param message data to send
486 * @param length size of the data
487 * @param dest_addr destination address
488 * @param dest_len length of address
489 * @return number of bytes sent, GNUNET_SYSERR on error
492 GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
493 const void *message, size_t length,
494 const struct sockaddr * dest_addr,
502 flags |= MSG_DONTWAIT;
505 flags |= MSG_NOSIGNAL;
507 ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len);
509 if (SOCKET_ERROR == ret)
510 SetErrnoFromWinsockError (WSAGetLastError ());
519 * @param level protocol level of the option
520 * @param option_name option identifier
521 * @param option_value value to set
522 * @param option_len size of option_value
523 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
526 GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd,
527 int level, int option_name,
528 const void *option_value,
529 socklen_t option_len)
533 ret = setsockopt (fd->fd, level, option_name, option_value, option_len);
535 if (SOCKET_ERROR == ret)
536 SetErrnoFromWinsockError (WSAGetLastError ());
538 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
543 * Create a new socket. Configure it for non-blocking IO and
544 * mark it as non-inheritable to child processes (set the
545 * close-on-exec flag).
547 * @param domain domain of the socket
548 * @param type socket type
549 * @param protocol network protocol
550 * @return new socket, NULL on error
552 struct GNUNET_NETWORK_Handle *
553 GNUNET_NETWORK_socket_create (int domain, int type, int protocol)
555 struct GNUNET_NETWORK_Handle *ret;
556 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
557 ret->fd = socket (domain, type, protocol);
558 if (INVALID_SOCKET == ret->fd)
561 SetErrnoFromWinsockError (WSAGetLastError ());
568 if (ret->fd >= FD_SETSIZE)
570 GNUNET_break (0 == close (ret->fd));
577 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
579 /* we might want to treat this one as fatal... */
581 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
586 if (GNUNET_OK != socket_set_inheritable (ret))
587 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
588 "socket_set_inheritable");
591 socket_set_nosigpipe (ret);
593 if (type == SOCK_STREAM)
594 socket_set_nodelay (ret);
600 * Shut down socket operations
602 * @param how type of shutdown
603 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
606 GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how)
610 ret = shutdown (desc->fd, how);
613 SetErrnoFromWinsockError (WSAGetLastError ());
615 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
624 GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds)
629 GNUNET_CONTAINER_slist_clear (fds->handles);
634 * Add a socket to the FD set
636 * @param desc socket to add
639 GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds,
640 const struct GNUNET_NETWORK_Handle *desc)
642 FD_SET (desc->fd, &fds->sds);
643 if (desc->fd + 1 > fds->nsds)
644 fds->nsds = desc->fd + 1;
649 * Check whether a socket is part of the fd set
652 * @return 0 if the FD is not set
655 GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
656 const struct GNUNET_NETWORK_Handle *desc)
658 return FD_ISSET (desc->fd, &fds->sds);
663 * Add one fd set to another
664 * @param dst the fd set to add to
665 * @param src the fd set to add from
668 GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
669 const struct GNUNET_NETWORK_FDSet *src)
672 for (nfds = src->nsds; nfds > 0; nfds--)
673 if (FD_ISSET (nfds, &src->sds))
676 FD_SET (nfds, &dst->sds);
677 if (nfds + 1 > dst->nsds)
678 dst->nsds = nfds + 1;
681 GNUNET_CONTAINER_slist_append (dst->handles, src->handles);
687 * Copy one fd set to another
689 * @param to destination
693 GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
694 const struct GNUNET_NETWORK_FDSet *from)
696 FD_COPY (&from->sds, &to->sds);
697 to->nsds = from->nsds;
700 GNUNET_CONTAINER_slist_clear (to->handles);
701 GNUNET_CONTAINER_slist_append (to->handles, from->handles);
706 GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc)
712 * Copy a native fd set
714 * @param to destination
715 * @param from native source set
716 * @param nfds the biggest socket number in from + 1
719 GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to,
720 const fd_set * from, int nfds)
722 FD_COPY (from, &to->sds);
728 * Set a native fd in a set
730 * @param to destination
731 * @param nfd native FD to set
733 void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to,
736 FD_SET (nfd, &to->sds);
737 to->nsds = GNUNET_MAX (nfd + 1, to->nsds);
742 * Add a file handle to the fd set
744 * @param h the file handle to add
747 GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
748 const struct GNUNET_DISK_FileHandle *h)
753 GNUNET_DISK_internal_file_handle_ (h, &hw, sizeof (HANDLE));
754 GNUNET_CONTAINER_slist_add (fds->handles,
755 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
756 &hw, sizeof (HANDLE));
760 GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int));
761 FD_SET (fd, &fds->sds);
762 if (fd + 1 > fds->nsds)
770 * Check if a file handle is part of an fd set
772 * @param h file handle
773 * @return GNUNET_YES if the file handle is part of the set
776 GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
777 const struct GNUNET_DISK_FileHandle *h)
781 return GNUNET_CONTAINER_slist_contains (fds->handles, &h->h,
784 return FD_ISSET (h->fd, &fds->sds);
790 * Checks if two fd sets overlap
791 * @param fds1 first fd set
792 * @param fds2 second fd set
793 * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise
796 GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
797 const struct GNUNET_NETWORK_FDSet *fds2)
801 if (nfds < fds2->nsds)
803 for (; nfds >= 0; nfds--)
804 if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds))
808 struct GNUNET_CONTAINER_SList_Iterator *it;
810 for (it = GNUNET_CONTAINER_slist_begin (fds1->handles);
811 GNUNET_CONTAINER_slist_end (it) != GNUNET_YES;
812 GNUNET_CONTAINER_slist_next (it))
816 h = GNUNET_CONTAINER_slist_get (it, NULL);
817 if (GNUNET_CONTAINER_slist_contains
818 (fds2->handles, h, sizeof (HANDLE)))
820 GNUNET_CONTAINER_slist_iter_destroy (it);
824 GNUNET_CONTAINER_slist_iter_destroy (it);
833 * @return a new fd set
835 struct GNUNET_NETWORK_FDSet *
836 GNUNET_NETWORK_fdset_create ()
838 struct GNUNET_NETWORK_FDSet *fds;
839 fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet));
841 fds->handles = GNUNET_CONTAINER_slist_create ();
843 GNUNET_NETWORK_fdset_zero (fds);
849 * Releases the associated memory of an fd set
853 GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds)
856 GNUNET_CONTAINER_slist_destroy (fds->handles);
862 * Check if sockets meet certain conditions
863 * @param rfds set of sockets to be checked for readability
864 * @param wfds set of sockets to be checked for writability
865 * @param efds set of sockets to be checked for exceptions
866 * @param timeout relative value when to return
867 * @return number of selected sockets, GNUNET_SYSERR on error
870 GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
871 struct GNUNET_NETWORK_FDSet *wfds,
872 struct GNUNET_NETWORK_FDSet *efds,
873 const struct GNUNET_TIME_Relative timeout)
887 handles = GNUNET_CONTAINER_slist_count (rfds->handles);
892 nfds = GNUNET_MAX (nfds, wfds->nsds);
894 handles += GNUNET_CONTAINER_slist_count (wfds->handles);
899 nfds = GNUNET_MAX (nfds, efds->nsds);
901 handles += GNUNET_CONTAINER_slist_count (efds->handles);
906 tv.tv_sec = timeout.value / GNUNET_TIME_UNIT_SECONDS.value;
908 1000 * (timeout.value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.value));
909 if ((nfds == 0) && (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
915 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
917 ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"),
922 return select (nfds + 1,
923 (rfds != NULL) ? &rfds->sds : NULL,
924 (wfds != NULL) ? &wfds->sds : NULL,
925 (efds != NULL) ? &efds->sds : NULL,
926 (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
931 fd_set sock_read, sock_write, sock_except;
932 fd_set aread, awrite, aexcept;
933 struct GNUNET_CONTAINER_SList *handles_read, *handles_write,
937 struct timeval tvslice;
941 #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
943 /* calculate how long we need to wait in milliseconds */
944 if (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
948 ms_total = timeout.value / GNUNET_TIME_UNIT_MILLISECONDS.value;
950 /* select() may be used as a portable way to sleep */
951 if (!(rfds || wfds || efds))
958 handles_read = GNUNET_CONTAINER_slist_create ();
959 handles_write = GNUNET_CONTAINER_slist_create ();
960 handles_except = GNUNET_CONTAINER_slist_create ();
963 sock_read = rfds->sds;
965 FD_ZERO (&sock_read);
967 sock_write = wfds->sds;
969 FD_ZERO (&sock_write);
971 sock_except = efds->sds;
973 FD_ZERO (&sock_except);
975 /* multiplex between winsock select() and waiting on the handles */
979 limit = GetTickCount () + ms_total;
988 /* overwrite the zero'd sets here; the select call
989 * will clear those that are not active */
990 FD_COPY (&sock_read, &aread);
991 FD_COPY (&sock_write, &awrite);
992 FD_COPY (&sock_except, &aexcept);
994 tvslice.tv_usec = 100000;
996 select (nfds + 1, &aread, &awrite, &aexcept,
997 &tvslice)) == SOCKET_ERROR)
1000 SetErrnoFromWinsockError (WSAGetLastError ());
1001 if (errno == ENOTSOCK)
1005 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select");
1008 goto select_loop_end;
1012 /* Poll read pipes */
1016 struct GNUNET_CONTAINER_SList_Iterator *i;
1017 for (i = GNUNET_CONTAINER_slist_begin (rfds->handles);
1018 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES;
1019 GNUNET_CONTAINER_slist_next (i))
1024 h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL);
1025 if (!PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL))
1028 SetErrnoFromWinError (GetLastError ());
1031 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
1035 goto select_loop_end;
1040 GNUNET_CONTAINER_slist_add (handles_read,
1041 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1042 &h, sizeof (HANDLE));
1046 GNUNET_CONTAINER_slist_iter_destroy (i);
1049 /* Poll for faulty pipes */
1053 struct GNUNET_CONTAINER_SList_Iterator *i;
1054 for (i = GNUNET_CONTAINER_slist_begin (efds->handles);
1055 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES;
1056 GNUNET_CONTAINER_slist_next (i))
1061 h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL);
1062 if (!PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL))
1065 GNUNET_CONTAINER_slist_add (handles_except,
1066 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1067 &h, sizeof (HANDLE));
1071 GNUNET_CONTAINER_slist_iter_destroy (i);
1076 GNUNET_CONTAINER_slist_append (handles_write, wfds->handles);
1077 retcode += GNUNET_CONTAINER_slist_count (wfds->handles);
1080 /* Check for closed sockets */
1081 for (i = 0; i < nfds; i++)
1084 if (SAFE_FD_ISSET (i, &sock_read))
1087 struct sockaddr addr;
1089 if (getpeername (i, &addr, &len) == SOCKET_ERROR)
1095 (i, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == 0
1096 && err == WSAENOTCONN)
1099 if (!SAFE_FD_ISSET (i, &aread))
1110 if (retcode == 0 && nfds == 0)
1111 Sleep (GNUNET_MIN (100, limit - GetTickCount ()));
1113 while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit));
1121 GNUNET_NETWORK_fdset_zero (rfds);
1122 GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode);
1123 GNUNET_CONTAINER_slist_clear (rfds->handles);
1124 GNUNET_CONTAINER_slist_append (rfds->handles, handles_read);
1130 GNUNET_NETWORK_fdset_zero (wfds);
1131 GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode);
1132 GNUNET_CONTAINER_slist_clear (wfds->handles);
1133 GNUNET_CONTAINER_slist_append (wfds->handles, handles_write);
1138 GNUNET_NETWORK_fdset_zero (efds);
1139 GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode);
1140 GNUNET_CONTAINER_slist_clear (efds->handles);
1141 GNUNET_CONTAINER_slist_append (efds->handles, handles_except);
1145 GNUNET_CONTAINER_slist_destroy (handles_read);
1146 GNUNET_CONTAINER_slist_destroy (handles_write);
1147 GNUNET_CONTAINER_slist_destroy (handles_except);
1154 /* end of network.c */