diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-07 07:05:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-07 07:05:01 +0000 |
commit | bf3c0179736ca876b87abe997312ad2ece34221b (patch) | |
tree | 7be0d5c4d1cd9f06c7e06708fd9a86598fff3856 /src | |
parent | 5a9341cd0b865ebb39dfb186a3069538c0322a33 (diff) | |
download | gnunet-bf3c0179736ca876b87abe997312ad2ece34221b.tar.gz gnunet-bf3c0179736ca876b87abe997312ad2ece34221b.zip |
LRN: new select wrapper for W32 which avoids busy-waiting
Diffstat (limited to 'src')
-rw-r--r-- | src/util/network.c | 339 |
1 files changed, 164 insertions, 175 deletions
diff --git a/src/util/network.c b/src/util/network.c index 972f93849..ed7e8be30 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -1087,13 +1087,47 @@ GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) | |||
1087 | GNUNET_free (fds); | 1087 | GNUNET_free (fds); |
1088 | } | 1088 | } |
1089 | 1089 | ||
1090 | #if MINGW | ||
1091 | struct _select_params | ||
1092 | { | ||
1093 | fd_set *r; | ||
1094 | fd_set *w; | ||
1095 | fd_set *e; | ||
1096 | struct timeval *tv; | ||
1097 | HANDLE wakeup; | ||
1098 | HANDLE standby; | ||
1099 | SOCKET wakeup_socket; | ||
1100 | int status; | ||
1101 | }; | ||
1102 | |||
1103 | static DWORD WINAPI | ||
1104 | _selector (LPVOID p) | ||
1105 | { | ||
1106 | struct _select_params *sp = p; | ||
1107 | int i; | ||
1108 | while (1) | ||
1109 | { | ||
1110 | WaitForSingleObject (sp->standby, INFINITE); | ||
1111 | ResetEvent (sp->standby); | ||
1112 | sp->status = select (1, sp->r, sp->w, sp->e, sp->tv); | ||
1113 | if (FD_ISSET (sp->wakeup_socket, sp->r)) | ||
1114 | { | ||
1115 | FD_CLR (sp->wakeup_socket, sp->r); | ||
1116 | sp->status -= 1; | ||
1117 | } | ||
1118 | SetEvent (sp->wakeup); | ||
1119 | } | ||
1120 | return 0; | ||
1121 | } | ||
1122 | #endif | ||
1123 | |||
1090 | /** | 1124 | /** |
1091 | * Check if sockets meet certain conditions | 1125 | * Check if sockets or pipes meet certain conditions |
1092 | * @param rfds set of sockets to be checked for readability | 1126 | * @param rfds set of sockets or pipes to be checked for readability |
1093 | * @param wfds set of sockets to be checked for writability | 1127 | * @param wfds set of sockets or pipes to be checked for writability |
1094 | * @param efds set of sockets to be checked for exceptions | 1128 | * @param efds set of sockets or pipes to be checked for exceptions |
1095 | * @param timeout relative value when to return | 1129 | * @param timeout relative value when to return |
1096 | * @return number of selected sockets, GNUNET_SYSERR on error | 1130 | * @return number of selected sockets or pipes, GNUNET_SYSERR on error |
1097 | */ | 1131 | */ |
1098 | int | 1132 | int |
1099 | GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | 1133 | GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, |
@@ -1112,22 +1146,24 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1112 | int retcode = 0; | 1146 | int retcode = 0; |
1113 | DWORD ms_total = 0; | 1147 | DWORD ms_total = 0; |
1114 | 1148 | ||
1115 | int nsock = 0; | ||
1116 | int nhandles = 0; | 1149 | int nhandles = 0; |
1117 | int nSockEvents = 0; | ||
1118 | 1150 | ||
1119 | static HANDLE hEventRead = 0; | ||
1120 | static HANDLE hEventWrite = 0; | ||
1121 | static HANDLE hEventException = 0; | ||
1122 | static HANDLE hEventPipeWrite = 0; | 1151 | static HANDLE hEventPipeWrite = 0; |
1123 | static HANDLE hEventReadReady = 0; | 1152 | static HANDLE hEventReadReady = 0; |
1124 | 1153 | ||
1154 | static struct _select_params sp; | ||
1155 | static HANDLE select_thread = NULL; | ||
1156 | static HANDLE select_finished_event = NULL; | ||
1157 | static HANDLE select_standby_event = NULL; | ||
1158 | static SOCKET select_wakeup_socket = -1; | ||
1159 | static SOCKET select_send_socket = -1; | ||
1160 | static struct timeval select_timeout; | ||
1161 | |||
1125 | int readPipes = 0; | 1162 | int readPipes = 0; |
1126 | int writePipePos = 0; | 1163 | int writePipePos = 0; |
1127 | 1164 | ||
1128 | HANDLE handle_array[FD_SETSIZE + 2]; | 1165 | HANDLE handle_array[FD_SETSIZE + 2]; |
1129 | int returncode = -1; | 1166 | int returncode = -1; |
1130 | DWORD newretcode = 0; | ||
1131 | int returnedpos = 0; | 1167 | int returnedpos = 0; |
1132 | 1168 | ||
1133 | struct GNUNET_CONTAINER_SList *handles_read; | 1169 | struct GNUNET_CONTAINER_SList *handles_read; |
@@ -1226,23 +1262,53 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1226 | return 0; | 1262 | return 0; |
1227 | } | 1263 | } |
1228 | 1264 | ||
1229 | /* Events for sockets */ | 1265 | if (select_thread == NULL) |
1230 | if (!hEventRead) | 1266 | { |
1231 | hEventRead = CreateEvent (NULL, TRUE, FALSE, NULL); | 1267 | SOCKET select_listening_socket = -1; |
1232 | else | 1268 | struct sockaddr_in s_in; |
1233 | ResetEvent (hEventRead); | 1269 | int alen; |
1270 | int res; | ||
1271 | unsigned long p; | ||
1272 | |||
1273 | select_standby_event = CreateEvent (NULL, TRUE, FALSE, NULL); | ||
1274 | select_finished_event = CreateEvent (NULL, TRUE, FALSE, NULL); | ||
1275 | |||
1276 | select_wakeup_socket = WSASocket (AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); | ||
1277 | |||
1278 | select_listening_socket = WSASocket (AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); | ||
1279 | |||
1280 | p = 1; | ||
1281 | res = ioctlsocket (select_wakeup_socket, FIONBIO, &p); | ||
1282 | |||
1283 | alen = sizeof (s_in); | ||
1284 | s_in.sin_family = AF_INET; | ||
1285 | s_in.sin_port = 0; | ||
1286 | s_in.sin_addr.S_un.S_un_b.s_b1 = 127; | ||
1287 | s_in.sin_addr.S_un.S_un_b.s_b2 = 0; | ||
1288 | s_in.sin_addr.S_un.S_un_b.s_b3 = 0; | ||
1289 | s_in.sin_addr.S_un.S_un_b.s_b4 = 1; | ||
1290 | res = bind (select_listening_socket, (const struct sockaddr *) &s_in, sizeof (s_in)); | ||
1291 | |||
1292 | res = getsockname (select_listening_socket, (struct sockaddr *) &s_in, &alen); | ||
1293 | |||
1294 | res = listen (select_listening_socket, SOMAXCONN); | ||
1295 | |||
1296 | res = connect (select_wakeup_socket, (const struct sockaddr *) &s_in, sizeof (s_in)); | ||
1297 | |||
1298 | select_send_socket = accept (select_listening_socket, (struct sockaddr *) &s_in, &alen); | ||
1299 | |||
1300 | closesocket (select_listening_socket); | ||
1301 | |||
1302 | sp.wakeup = select_finished_event; | ||
1303 | sp.standby = select_standby_event; | ||
1304 | sp.wakeup_socket = select_wakeup_socket; | ||
1305 | |||
1306 | select_thread = CreateThread (NULL, 0, _selector, &sp, 0, NULL); | ||
1307 | } | ||
1308 | |||
1309 | /* Events for pipes */ | ||
1234 | if (!hEventReadReady) | 1310 | if (!hEventReadReady) |
1235 | hEventReadReady = CreateEvent (NULL, TRUE, TRUE, NULL); | 1311 | hEventReadReady = CreateEvent (NULL, TRUE, TRUE, NULL); |
1236 | if (!hEventWrite) | ||
1237 | hEventWrite = CreateEvent (NULL, TRUE, FALSE, NULL); | ||
1238 | else | ||
1239 | ResetEvent (hEventWrite); | ||
1240 | if (!hEventException) | ||
1241 | hEventException = CreateEvent (NULL, TRUE, FALSE, NULL); | ||
1242 | else | ||
1243 | ResetEvent (hEventException); | ||
1244 | |||
1245 | /* Event for pipes */ | ||
1246 | if (!hEventPipeWrite) | 1312 | if (!hEventPipeWrite) |
1247 | hEventPipeWrite = CreateEvent (NULL, TRUE, TRUE, NULL); | 1313 | hEventPipeWrite = CreateEvent (NULL, TRUE, TRUE, NULL); |
1248 | readPipes = 0; | 1314 | readPipes = 0; |
@@ -1363,103 +1429,91 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1363 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 1429 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
1364 | fh, | 1430 | fh, |
1365 | sizeof (struct GNUNET_DISK_FileHandle)); | 1431 | sizeof (struct GNUNET_DISK_FileHandle)); |
1366 | newretcode++; | ||
1367 | } | 1432 | } |
1368 | } | 1433 | } |
1369 | } | 1434 | } |
1370 | } | 1435 | } |
1436 | |||
1437 | sp.status = 0; | ||
1438 | |||
1371 | if (nfds > 0) | 1439 | if (nfds > 0) |
1372 | { | 1440 | { |
1373 | if (rfds) | 1441 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1374 | { | 1442 | "Adding the socket event to the array as %d\n", nhandles); |
1375 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1443 | handle_array[nhandles++] = select_finished_event; |
1376 | "Adding the socket read event to the array as %d\n", nhandles); | 1444 | if (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) |
1377 | handle_array[nhandles++] = hEventRead; | 1445 | sp.tv = NULL; |
1378 | nSockEvents++; | 1446 | else |
1379 | for (i = 0; i < rfds->sds.fd_count; i++) | ||
1380 | { | ||
1381 | WSAEventSelect (rfds->sds.fd_array[i], hEventRead, | ||
1382 | FD_ACCEPT | FD_READ | FD_CLOSE); | ||
1383 | nsock++; | ||
1384 | } | ||
1385 | } | ||
1386 | if (wfds) | ||
1387 | { | 1447 | { |
1388 | int wakeup = 0; | 1448 | select_timeout.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value; |
1389 | 1449 | select_timeout.tv_usec = 1000 * (timeout.rel_value - | |
1390 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1450 | (select_timeout.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value)); |
1391 | "Adding the socket write event to the array as %d\n", nhandles); | 1451 | sp.tv = &select_timeout; |
1392 | handle_array[nhandles++] = hEventWrite; | ||
1393 | nSockEvents++; | ||
1394 | for (i = 0; i < wfds->sds.fd_count; i++) | ||
1395 | { | ||
1396 | DWORD error; | ||
1397 | int status; | ||
1398 | |||
1399 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); | ||
1400 | error = GetLastError (); | ||
1401 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1402 | "pre-send to the socket %d returned %d (%u)\n", i, status, error); | ||
1403 | if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) | ||
1404 | wakeup = 1; | ||
1405 | WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, | ||
1406 | FD_WRITE | FD_CONNECT | FD_CLOSE); | ||
1407 | nsock++; | ||
1408 | } | ||
1409 | if (wakeup) | ||
1410 | SetEvent (hEventWrite); | ||
1411 | } | 1452 | } |
1412 | if (efds) | 1453 | FD_SET (select_wakeup_socket, &aread); |
1454 | sp.r = &aread; | ||
1455 | sp.w = &awrite; | ||
1456 | sp.e = &aexcept; | ||
1457 | /* Failed connections cause sockets to be set in errorfds on W32, | ||
1458 | * but on POSIX it should set them in writefds. | ||
1459 | * First copy all awrite sockets to aexcept, later we'll | ||
1460 | * check aexcept and set its contents in awrite as well | ||
1461 | * Sockets are also set in errorfds when OOB data is available, | ||
1462 | * but we don't use OOB data. | ||
1463 | */ | ||
1464 | for (i = 0; i < awrite.fd_count; i++) | ||
1413 | { | 1465 | { |
1414 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1466 | if (awrite.fd_array[i] != 0 && awrite.fd_array[i] != -1) |
1415 | "Adding the socket error event to the array as %d\n", nhandles); | 1467 | FD_SET (awrite.fd_array[i], &aexcept); |
1416 | handle_array[nhandles++] = hEventException; | ||
1417 | nSockEvents++; | ||
1418 | for (i = 0; i < efds->sds.fd_count; i++) | ||
1419 | { | ||
1420 | WSAEventSelect (efds->sds.fd_array[i], hEventException, | ||
1421 | FD_OOB | FD_CLOSE); | ||
1422 | nsock++; | ||
1423 | } | ||
1424 | } | 1468 | } |
1469 | ResetEvent (select_finished_event); | ||
1470 | SetEvent (select_standby_event); | ||
1425 | } | 1471 | } |
1426 | 1472 | ||
1427 | handle_array[nhandles] = NULL; | 1473 | handle_array[nhandles] = NULL; |
1428 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1474 | LOG (GNUNET_ERROR_TYPE_DEBUG, "nfds: %d, handles: %d, will wait: %d ms\n", |
1429 | "Number nfds: %d, handles: %d, return code: %u will wait: %d ms\n", | 1475 | nfds, nhandles, ms_total); |
1430 | nfds, nhandles, newretcode, ms_total); | ||
1431 | if (nhandles) | 1476 | if (nhandles) |
1432 | returncode = | 1477 | returncode = |
1433 | WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total); | 1478 | WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total); |
1434 | LOG (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n", | 1479 | LOG (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n", |
1435 | returncode); | 1480 | returncode); |
1436 | 1481 | ||
1482 | if (nfds > 0) | ||
1483 | { | ||
1484 | /* Don't wake up select-thread when delay is 0, it should return immediately | ||
1485 | * and wake up by itself. | ||
1486 | */ | ||
1487 | if (ms_total != 0) | ||
1488 | i = send (select_send_socket, (const char *) &returnedpos, 1, 0); | ||
1489 | i = (int) WaitForSingleObject (select_finished_event, INFINITE); | ||
1490 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished waiting for the select thread: %d %d\n", i, sp.status); | ||
1491 | if (ms_total != 0) | ||
1492 | { | ||
1493 | do | ||
1494 | { | ||
1495 | i = recv (select_wakeup_socket, (char *) &returnedpos, 1, 0); | ||
1496 | } while (i == 1); | ||
1497 | } | ||
1498 | /* Check aexcept, add its contents to awrite */ | ||
1499 | for (i = 0; i < aexcept.fd_count; i++) | ||
1500 | { | ||
1501 | if (aexcept.fd_array[i] != 0 && aexcept.fd_array[i] != -1) | ||
1502 | FD_SET (aexcept.fd_array[i], &awrite); | ||
1503 | } | ||
1504 | } | ||
1505 | |||
1437 | returnedpos = returncode - WAIT_OBJECT_0; | 1506 | returnedpos = returncode - WAIT_OBJECT_0; |
1438 | LOG (GNUNET_ERROR_TYPE_DEBUG, "return pos is : %d\n", returnedpos); | 1507 | LOG (GNUNET_ERROR_TYPE_DEBUG, "return pos is : %d\n", returnedpos); |
1439 | 1508 | ||
1440 | /* FIXME: THIS LINE IS WRONG !! We should add to handles only handles that fired the events, not all ! */ | ||
1441 | /* | ||
1442 | * if(rfds) | ||
1443 | * GNUNET_CONTAINER_slist_append (handles_read, rfds->handles); | ||
1444 | */ | ||
1445 | if (nhandles && (returnedpos < nhandles)) | 1509 | if (nhandles && (returnedpos < nhandles)) |
1446 | { | 1510 | { |
1447 | DWORD waitstatus; | 1511 | DWORD waitstatus; |
1448 | 1512 | ||
1449 | /* Do the select */ | 1513 | if (sp.status > 0) |
1450 | if (nfds) | 1514 | retcode += sp.status; |
1451 | { | 1515 | |
1452 | struct timeval tvslice; | 1516 | if ((writePipePos != -1) && (returnedpos < writePipePos)) |
1453 | |||
1454 | tvslice.tv_sec = 0; | ||
1455 | tvslice.tv_usec = 0; | ||
1456 | retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice); | ||
1457 | if (retcode == -1) | ||
1458 | retcode = 0; | ||
1459 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Select retcode : %d\n", retcode); | ||
1460 | } | ||
1461 | /* FIXME: <= writePipePos? Really? */ | ||
1462 | if ((writePipePos != -1) && (returnedpos <= writePipePos)) | ||
1463 | { | 1517 | { |
1464 | GNUNET_CONTAINER_slist_append (handles_write, wfds->handles); | 1518 | GNUNET_CONTAINER_slist_append (handles_write, wfds->handles); |
1465 | retcode += write_handles; | 1519 | retcode += write_handles; |
@@ -1467,24 +1521,8 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1467 | } | 1521 | } |
1468 | LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes); | 1522 | LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes); |
1469 | /* We have some pipes ready for read. */ | 1523 | /* We have some pipes ready for read. */ |
1470 | /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */ | ||
1471 | |||
1472 | if (returnedpos < readPipes) | 1524 | if (returnedpos < readPipes) |
1473 | { | 1525 | { |
1474 | /* | ||
1475 | * for (i = 0; i < readPipes; i++) | ||
1476 | * { | ||
1477 | * waitstatus = WaitForSingleObject (handle_array[i], 0); | ||
1478 | * LOG (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus); | ||
1479 | * if (waitstatus != WAIT_OBJECT_0) | ||
1480 | * continue; | ||
1481 | * GNUNET_CONTAINER_slist_add (handles_read, | ||
1482 | * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | ||
1483 | * readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); | ||
1484 | * retcode++; | ||
1485 | * LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n"); | ||
1486 | * } | ||
1487 | */ | ||
1488 | for (i = 0; i < readPipes; i++) | 1526 | for (i = 0; i < readPipes; i++) |
1489 | { | 1527 | { |
1490 | DWORD error; | 1528 | DWORD error; |
@@ -1514,34 +1552,6 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1514 | readArray[i], readArray[i]->h); | 1552 | readArray[i], readArray[i]->h); |
1515 | } | 1553 | } |
1516 | } | 1554 | } |
1517 | waitstatus = WaitForSingleObject (hEventWrite, 0); | ||
1518 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Wait for the write event returned %d\n", | ||
1519 | waitstatus); | ||
1520 | if (waitstatus == WAIT_OBJECT_0) | ||
1521 | { | ||
1522 | for (i = 0; i < wfds->sds.fd_count; i++) | ||
1523 | { | ||
1524 | DWORD error; | ||
1525 | int status; | ||
1526 | int so_error = 0; | ||
1527 | int sizeof_so_error = sizeof (so_error); | ||
1528 | int gso_result = | ||
1529 | getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR, | ||
1530 | (char *) &so_error, &sizeof_so_error); | ||
1531 | |||
1532 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); | ||
1533 | error = GetLastError (); | ||
1534 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1535 | "send to the socket %d returned %d (%u)\n", i, status, error); | ||
1536 | if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) || | ||
1537 | (status == -1 && gso_result == 0 && error == WSAENOTCONN && | ||
1538 | so_error == WSAECONNREFUSED)) | ||
1539 | { | ||
1540 | FD_SET (wfds->sds.fd_array[i], &awrite); | ||
1541 | retcode += 1; | ||
1542 | } | ||
1543 | } | ||
1544 | } | ||
1545 | } | 1555 | } |
1546 | if (!nhandles || (returnedpos >= nhandles)) | 1556 | if (!nhandles || (returnedpos >= nhandles)) |
1547 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n"); | 1557 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n"); |
@@ -1549,11 +1559,6 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1549 | { | 1559 | { |
1550 | struct GNUNET_CONTAINER_SList_Iterator t; | 1560 | struct GNUNET_CONTAINER_SList_Iterator t; |
1551 | 1561 | ||
1552 | for (i = 0; i < rfds->sds.fd_count; i++) | ||
1553 | { | ||
1554 | WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0); | ||
1555 | nsock++; | ||
1556 | } | ||
1557 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); | 1562 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); |
1558 | GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; | 1563 | GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; |
1559 | GNUNET_CONTAINER_slist_next (&t)) | 1564 | GNUNET_CONTAINER_slist_next (&t)) |
@@ -1567,7 +1572,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1567 | CancelIo (fh->h); | 1572 | CancelIo (fh->h); |
1568 | } | 1573 | } |
1569 | } | 1574 | } |
1570 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n"); | 1575 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds%s\n", (retcode != -1 && nhandles && (returnedpos < nhandles)) ? ", copying fdset" : ""); |
1571 | GNUNET_NETWORK_fdset_zero (rfds); | 1576 | GNUNET_NETWORK_fdset_zero (rfds); |
1572 | if (retcode != -1 && nhandles && (returnedpos < nhandles)) | 1577 | if (retcode != -1 && nhandles && (returnedpos < nhandles)) |
1573 | GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); | 1578 | GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); |
@@ -1575,12 +1580,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1575 | } | 1580 | } |
1576 | if (wfds) | 1581 | if (wfds) |
1577 | { | 1582 | { |
1578 | for (i = 0; i < wfds->sds.fd_count; i++) | 1583 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing wfds%s\n", (retcode != -1 && nhandles && (returnedpos < nhandles)) ? ", copying fdset" : ""); |
1579 | { | ||
1580 | WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 0); | ||
1581 | nsock++; | ||
1582 | } | ||
1583 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing wfds\n"); | ||
1584 | GNUNET_NETWORK_fdset_zero (wfds); | 1584 | GNUNET_NETWORK_fdset_zero (wfds); |
1585 | if (retcode != -1 && nhandles && (returnedpos < nhandles)) | 1585 | if (retcode != -1 && nhandles && (returnedpos < nhandles)) |
1586 | GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); | 1586 | GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); |
@@ -1588,12 +1588,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1588 | } | 1588 | } |
1589 | if (efds) | 1589 | if (efds) |
1590 | { | 1590 | { |
1591 | for (i = 0; i < efds->sds.fd_count; i++) | 1591 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing efds%s\n", (retcode != -1 && nhandles && (returnedpos < nhandles)) ? ", copying fdset" : ""); |
1592 | { | ||
1593 | WSAEventSelect (efds->sds.fd_array[i], hEventException, 0); | ||
1594 | nsock++; | ||
1595 | } | ||
1596 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing efds\n"); | ||
1597 | GNUNET_NETWORK_fdset_zero (efds); | 1592 | GNUNET_NETWORK_fdset_zero (efds); |
1598 | if (retcode != -1 && nhandles && (returnedpos < nhandles)) | 1593 | if (retcode != -1 && nhandles && (returnedpos < nhandles)) |
1599 | GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); | 1594 | GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); |
@@ -1607,12 +1602,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1607 | { | 1602 | { |
1608 | struct GNUNET_CONTAINER_SList_Iterator t; | 1603 | struct GNUNET_CONTAINER_SList_Iterator t; |
1609 | 1604 | ||
1610 | for (i = 0; i < bread.fd_count; i++) | 1605 | LOG (GNUNET_ERROR_TYPE_DEBUG, "rfds:\n"); |
1606 | for (i = 0; i < rfds->sds.fd_count; i++) | ||
1611 | { | 1607 | { |
1612 | if (bread.fd_array[i] != 0) | 1608 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%d\n", rfds->sds.fd_array[i]); |
1613 | LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n", | ||
1614 | bread.fd_array[i], | ||
1615 | (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" : "NOT SET"); | ||
1616 | } | 1609 | } |
1617 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); | 1610 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); |
1618 | GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; | 1611 | GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; |
@@ -1622,27 +1615,23 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1622 | 1615 | ||
1623 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, | 1616 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, |
1624 | NULL); | 1617 | NULL); |
1625 | LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h); | 1618 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%d\n", fh->h); |
1626 | } | 1619 | } |
1627 | } | 1620 | } |
1628 | if (wfds) | 1621 | if (wfds) |
1629 | { | 1622 | { |
1630 | for (i = 0; i < bwrite.fd_count; i++) | 1623 | LOG (GNUNET_ERROR_TYPE_DEBUG, "wfds:\n"); |
1624 | for (i = 0; i < wfds->sds.fd_count; i++) | ||
1631 | { | 1625 | { |
1632 | if (bwrite.fd_array[i] != 0) | 1626 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%d\n", wfds->sds.fd_array[i]); |
1633 | LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n", | ||
1634 | bwrite.fd_array[i], | ||
1635 | (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" : "NOT SET"); | ||
1636 | } | 1627 | } |
1637 | } | 1628 | } |
1638 | if (efds) | 1629 | if (efds) |
1639 | { | 1630 | { |
1640 | for (i = 0; i < bexcept.fd_count; i++) | 1631 | LOG (GNUNET_ERROR_TYPE_DEBUG, "efds:\n"); |
1632 | for (i = 0; i < efds->sds.fd_count; i++) | ||
1641 | { | 1633 | { |
1642 | if (bexcept.fd_array[i] != 0) | 1634 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%d\n", efds->sds.fd_array[i]); |
1643 | LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n", | ||
1644 | bexcept.fd_array[i], | ||
1645 | (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" : "NOT SET"); | ||
1646 | } | 1635 | } |
1647 | } | 1636 | } |
1648 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode); | 1637 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode); |