+ /* Check for closed sockets */
+ for (i = 0; i < nfds; i++)
+
+ {
+ if (SAFE_FD_ISSET (i, &sock_read))
+
+ {
+ struct sockaddr addr;
+ int len;
+ if (getpeername (i, &addr, &len) == SOCKET_ERROR)
+
+ {
+ int err, len;
+ len = sizeof (err);
+ if (getsockopt
+ (i, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == 0
+ && err == WSAENOTCONN)
+
+ {
+ if (!SAFE_FD_ISSET (i, &aread))
+
+ {
+ FD_SET (i, &aread);
+ retcode++;
+ }
+ }
+ }
+ }
+ }
+ select_loop_end:
+ if (retcode == 0 && nfds == 0)
+ Sleep (GNUNET_MIN (100, limit - GetTickCount ()));
+ }
+ while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit));
+
+ if (retcode != -1)
+ {
+ if (rfds)
+ {
+ GNUNET_NETWORK_fdset_zero (rfds);
+ GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode);
+ GNUNET_CONTAINER_slist_clear (rfds->handles);
+ GNUNET_CONTAINER_slist_append (rfds->handles, handles_read);
+ }
+ if (wfds)
+ {
+ GNUNET_NETWORK_fdset_zero (wfds);
+ GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode);
+ GNUNET_CONTAINER_slist_clear (wfds->handles);
+ GNUNET_CONTAINER_slist_append (wfds->handles, handles_write);
+ }
+ if (efds)
+ {
+ GNUNET_NETWORK_fdset_zero (efds);
+ GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode);
+ GNUNET_CONTAINER_slist_clear (efds->handles);
+ GNUNET_CONTAINER_slist_append (efds->handles, handles_except);
+ }
+ }
+
+ GNUNET_CONTAINER_slist_destroy (handles_read);
+ GNUNET_CONTAINER_slist_destroy (handles_write);
+ GNUNET_CONTAINER_slist_destroy (handles_except);
+
+ return retcode;