- /* FIXME: THIS LINE IS WRONG !! We should add to handles only handles that fired the events, not all ! */
- /*
- * if(rfds)
- * GNUNET_CONTAINER_slist_append (handles_read, rfds->handles);
- */
- if (nhandles && (returnedpos < nhandles))
- {
- DWORD waitstatus;
-
- /* Do the select */
- if (nfds)
- {
- struct timeval tvslice;
-
- tvslice.tv_sec = 0;
- tvslice.tv_usec = 10;
- retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice);
- if (retcode == -1)
- retcode = 0;
-#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Select retcode : %d\n", retcode);
-#endif
- }
- /* FIXME: <= writePipePos? Really? */
- if ((writePipePos != -1) && (returnedpos <= writePipePos))
- {
- GNUNET_CONTAINER_slist_append (handles_write, wfds->handles);
- retcode += write_handles;
-#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n");
-#endif
- }
-#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes);
-#endif
- /* We have some pipes ready for read. */
- /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */
-
- if (returnedpos < readPipes)
- {
- /*
- * for (i = 0; i < readPipes; i++)
- * {
- * waitstatus = WaitForSingleObject (handle_array[i], 0);
- * LOG (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus);
- * if (waitstatus != WAIT_OBJECT_0)
- * continue;
- * GNUNET_CONTAINER_slist_add (handles_read,
- * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- * readArray[i], sizeof (struct GNUNET_DISK_FileHandle));
- * retcode++;
- * LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n");
- * }
- */
- for (i = 0; i < readPipes; i++)
- {
- DWORD error;
- BOOL bret;
-
- SetLastError (0);
- waitstatus = 0;
- bret =
- PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus,
- NULL);
- error = GetLastError ();
-#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n",
- i, readArray[i]->h, bret, waitstatus, error);
-#endif
- if (bret == 0)
- {
- if (error != ERROR_BROKEN_PIPE)
- continue;
- }
- else if (waitstatus <= 0)
- continue;
- GNUNET_CONTAINER_slist_add (handles_read,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- readArray[i],
- sizeof (struct
- GNUNET_DISK_FileHandle));
- retcode++;
-#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n",
- readArray[i], readArray[i]->h);
-#endif
- }
- }
- waitstatus = WaitForSingleObject (hEventWrite, 0);
-#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Wait for the write event returned %d\n", waitstatus);
-#endif
- if (waitstatus == WAIT_OBJECT_0)
- {
- for (i = 0; i < wfds->sds.fd_count; i++)
- {
- DWORD error;
- int status;
- int so_error = 0;
- int sizeof_so_error = sizeof (so_error);
- int gso_result =
- getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR,
- (char *) &so_error, &sizeof_so_error);
-
- status = send (wfds->sds.fd_array[i], NULL, 0, 0);
- error = GetLastError ();
-#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "send to the socket %d returned %d (%u)\n", i, status,
- error);
-#endif
- if (status == 0
- || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)
- || (status == -1 && gso_result == 0 && error == WSAENOTCONN
- && so_error == WSAECONNREFUSED))
- {
- FD_SET (wfds->sds.fd_array[i], &awrite);
- retcode += 1;
- }
- }
- }
- }
-#if DEBUG_NETWORK
- if (!nhandles || (returnedpos >= nhandles))
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n");
-#endif
- if (rfds)