diff options
Diffstat (limited to 'src/lib/eventloop.c')
-rw-r--r-- | src/lib/eventloop.c | 338 |
1 files changed, 169 insertions, 169 deletions
diff --git a/src/lib/eventloop.c b/src/lib/eventloop.c index 19e0647c..36367f00 100644 --- a/src/lib/eventloop.c +++ b/src/lib/eventloop.c | |||
@@ -323,192 +323,192 @@ gnunet_gtk_select (void *cls, | |||
323 | gboolean need_realloc = FALSE; | 323 | gboolean need_realloc = FALSE; |
324 | for (i = 0; !need_realloc && i < max_nfds; i += 1) | 324 | for (i = 0; !need_realloc && i < max_nfds; i += 1) |
325 | { | 325 | { |
326 | int isset[3]; | 326 | int isset[3]; |
327 | 327 | ||
328 | isset[0] = (rfds == NULL) ? 0 : FD_ISSET (i, &rfds->sds); | 328 | isset[0] = (rfds == NULL) ? 0 : FD_ISSET (i, &rfds->sds); |
329 | isset[1] = (wfds == NULL) ? 0 : FD_ISSET (i, &wfds->sds); | 329 | isset[1] = (wfds == NULL) ? 0 : FD_ISSET (i, &wfds->sds); |
330 | isset[2] = (efds == NULL) ? 0 : FD_ISSET (i, &efds->sds); | 330 | isset[2] = (efds == NULL) ? 0 : FD_ISSET (i, &efds->sds); |
331 | if (!isset[0] && !isset[1] && !isset[2]) | 331 | if (!isset[0] && !isset[1] && !isset[2]) |
332 | continue; | 332 | continue; |
333 | if (fd_counter >= ml->cached_poll_array_size) | 333 | if (fd_counter >= ml->cached_poll_array_size) |
334 | { | 334 | { |
335 | need_realloc = TRUE; | 335 | need_realloc = TRUE; |
336 | break; | 336 | break; |
337 | } | 337 | } |
338 | ml->cached_poll_array[fd_counter].fd = i; | 338 | ml->cached_poll_array[fd_counter].fd = i; |
339 | ml->cached_poll_array[fd_counter].events = (isset[0] ? G_IO_IN | G_IO_HUP | G_IO_ERR : 0) | 339 | ml->cached_poll_array[fd_counter].events = (isset[0] ? G_IO_IN | G_IO_HUP | G_IO_ERR : 0) |
340 | | (isset[1] ? G_IO_OUT | G_IO_ERR : 0) | (isset[2] ? G_IO_ERR : 0); | 340 | | (isset[1] ? G_IO_OUT | G_IO_ERR : 0) | (isset[2] ? G_IO_ERR : 0); |
341 | fd_counter += 1; | 341 | fd_counter += 1; |
342 | } | 342 | } |
343 | if (need_realloc) | 343 | if (need_realloc) |
344 | { | 344 | { |
345 | resize_cached_poll_array (ml, ml->cached_poll_array_size * 2); | 345 | resize_cached_poll_array (ml, ml->cached_poll_array_size * 2); |
346 | fd_counter = 0; | 346 | fd_counter = 0; |
347 | need_realloc = FALSE; | 347 | need_realloc = FALSE; |
348 | } | 348 | } |
349 | else | 349 | else |
350 | break; | 350 | break; |
351 | #else | 351 | #else |
352 | struct GNUNET_CONTAINER_SList_Iterator *t; | 352 | struct GNUNET_CONTAINER_SList_Iterator *t; |
353 | /* We might overshoot a little, but that won't hurt very much */ | 353 | /* We might overshoot a little, but that won't hurt very much */ |
354 | int need_nfds = (rfds->sds.fd_count + rfds->sds.fd_count + rfds->sds.fd_count > 0 ? 3 : 0) | 354 | int need_nfds = (rfds->sds.fd_count + rfds->sds.fd_count + rfds->sds.fd_count > 0 ? 3 : 0) |
355 | + (rfds == NULL ? 0 : GNUNET_CONTAINER_slist_count (rfds->handles)) | 355 | + (rfds == NULL ? 0 : GNUNET_CONTAINER_slist_count (rfds->handles)) |
356 | + (wfds == NULL ? 0 : 1) | 356 | + (wfds == NULL ? 0 : 1) |
357 | + 1; | 357 | + 1; |
358 | if (need_nfds >= ml->cached_poll_array_size) | 358 | if (need_nfds >= ml->cached_poll_array_size) |
359 | { | 359 | { |
360 | /* Since there are also gmainloop's own fds, just need_nfds won't be | 360 | /* Since there are also gmainloop's own fds, just need_nfds won't be |
361 | * enough, so make it twice as long. | 361 | * enough, so make it twice as long. |
362 | */ | 362 | */ |
363 | ml->cached_poll_array = ml->cached_poll_array = g_renew (GPollFD, ml->cached_poll_array, need_nfds * 2); | 363 | ml->cached_poll_array = ml->cached_poll_array = g_renew (GPollFD, ml->cached_poll_array, need_nfds * 2); |
364 | ml->cached_poll_array_size = ml->cached_poll_array_size = need_nfds * 2; | 364 | ml->cached_poll_array_size = ml->cached_poll_array_size = need_nfds * 2; |
365 | } | 365 | } |
366 | if (ml->read_array_length < GNUNET_CONTAINER_slist_count (rfds->handles)) | 366 | if (ml->read_array_length < GNUNET_CONTAINER_slist_count (rfds->handles)) |
367 | { | 367 | { |
368 | ml->read_array = GNUNET_realloc (ml->read_array, GNUNET_CONTAINER_slist_count (rfds->handles) * sizeof (struct GNUNET_DISK_FileHandle *)); | 368 | ml->read_array = GNUNET_realloc (ml->read_array, GNUNET_CONTAINER_slist_count (rfds->handles) * sizeof (struct GNUNET_DISK_FileHandle *)); |
369 | ml->read_array_length = GNUNET_CONTAINER_slist_count (rfds->handles); | 369 | ml->read_array_length = GNUNET_CONTAINER_slist_count (rfds->handles); |
370 | } | 370 | } |
371 | if (rfds != NULL) | 371 | if (rfds != NULL) |
372 | { | 372 | { |
373 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles), i = 0; | 373 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles), i = 0; |
374 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | 374 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; |
375 | GNUNET_CONTAINER_slist_next (t), i += 1) | 375 | GNUNET_CONTAINER_slist_next (t), i += 1) |
376 | { | 376 | { |
377 | struct GNUNET_DISK_FileHandle *fh; | 377 | struct GNUNET_DISK_FileHandle *fh; |
378 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); | 378 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); |
379 | if (fh->type == GNUNET_PIPE) | 379 | if (fh->type == GNUNET_PIPE) |
380 | { | 380 | { |
381 | if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead)) | 381 | if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead)) |
382 | { | 382 | { |
383 | DWORD error_code = GetLastError(); | 383 | DWORD error_code = GetLastError(); |
384 | if (error_code == ERROR_IO_PENDING) | 384 | if (error_code == ERROR_IO_PENDING) |
385 | { | 385 | { |
386 | #if DEBUG_NETWORK | 386 | #if DEBUG_NETWORK |
387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the pipe's 0x%x overlapped event to the array as %d\n", fh->h, nhandles); | 387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the pipe's 0x%x overlapped event to the array as %d\n", fh->h, nhandles); |
388 | #endif | 388 | #endif |
389 | ml->cached_poll_array[fd_counter].fd = (intptr_t) fh->oOverlapRead->hEvent; | 389 | ml->cached_poll_array[fd_counter].fd = (intptr_t) fh->oOverlapRead->hEvent; |
390 | /* On W32 .events makes no sense - g_poll will just OR its | 390 | /* On W32 .events makes no sense - g_poll will just OR its |
391 | * contents into .revents when the .fd event fires. | 391 | * contents into .revents when the .fd event fires. |
392 | * So we'll use it in the way that suits us the best. | 392 | * So we'll use it in the way that suits us the best. |
393 | */ | 393 | */ |
394 | ml->cached_poll_array[fd_counter].events = G_IO_IN; | 394 | ml->cached_poll_array[fd_counter].events = G_IO_IN; |
395 | fd_counter += 1; | 395 | fd_counter += 1; |
396 | ml->read_array[read_handles] = fh; | 396 | ml->read_array[read_handles] = fh; |
397 | read_handles += 1; | 397 | read_handles += 1; |
398 | } | 398 | } |
399 | else | 399 | else |
400 | { | 400 | { |
401 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventReadReady; | 401 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventReadReady; |
402 | ml->cached_poll_array[fd_counter].events = G_IO_HUP; | 402 | ml->cached_poll_array[fd_counter].events = G_IO_HUP; |
403 | fd_counter += 1; | 403 | fd_counter += 1; |
404 | ml->read_array[read_handles] = fh; | 404 | ml->read_array[read_handles] = fh; |
405 | read_handles += 1; | 405 | read_handles += 1; |
406 | } | 406 | } |
407 | } | 407 | } |
408 | else | 408 | else |
409 | { | 409 | { |
410 | #if DEBUG_NETWORK | 410 | #if DEBUG_NETWORK |
411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the read ready event to the array as %d\n", nhandles); | 411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the read ready event to the array as %d\n", nhandles); |
412 | #endif | 412 | #endif |
413 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventReadReady; | 413 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventReadReady; |
414 | ml->cached_poll_array[fd_counter].events = G_IO_IN; | 414 | ml->cached_poll_array[fd_counter].events = G_IO_IN; |
415 | fd_counter += 1; | 415 | fd_counter += 1; |
416 | ml->read_array[read_handles] = fh; | 416 | ml->read_array[read_handles] = fh; |
417 | read_handles += 1; | 417 | read_handles += 1; |
418 | } | 418 | } |
419 | } | 419 | } |
420 | else | 420 | else |
421 | { | 421 | { |
422 | GNUNET_CONTAINER_slist_add (ml->handles_read, | 422 | GNUNET_CONTAINER_slist_add (ml->handles_read, |
423 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 423 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
424 | fh, sizeof (struct GNUNET_DISK_FileHandle)); | 424 | fh, sizeof (struct GNUNET_DISK_FileHandle)); |
425 | pre_ret += 1; | 425 | pre_ret += 1; |
426 | } | 426 | } |
427 | } | 427 | } |
428 | } | 428 | } |
429 | if (wfds != NULL && GNUNET_CONTAINER_slist_count (wfds->handles) > 0) | 429 | if (wfds != NULL && GNUNET_CONTAINER_slist_count (wfds->handles) > 0) |
430 | { | 430 | { |
431 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventPipeWrite; | 431 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventPipeWrite; |
432 | ml->cached_poll_array[fd_counter].events = G_IO_OUT; | 432 | ml->cached_poll_array[fd_counter].events = G_IO_OUT; |
433 | always_ready_write_fd = fd_counter; | 433 | always_ready_write_fd = fd_counter; |
434 | fd_counter += 1; | 434 | fd_counter += 1; |
435 | } | 435 | } |
436 | if (efds != NULL) | 436 | if (efds != NULL) |
437 | { | 437 | { |
438 | for (t = GNUNET_CONTAINER_slist_begin (efds->handles), i = 0; | 438 | for (t = GNUNET_CONTAINER_slist_begin (efds->handles), i = 0; |
439 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | 439 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; |
440 | GNUNET_CONTAINER_slist_next (t), i += 1) | 440 | GNUNET_CONTAINER_slist_next (t), i += 1) |
441 | { | 441 | { |
442 | struct GNUNET_DISK_FileHandle *fh; | 442 | struct GNUNET_DISK_FileHandle *fh; |
443 | DWORD dwBytes; | 443 | DWORD dwBytes; |
444 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); | 444 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); |
445 | if (fh->type == GNUNET_PIPE) | 445 | if (fh->type == GNUNET_PIPE) |
446 | { | 446 | { |
447 | if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL)) | 447 | if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL)) |
448 | { | 448 | { |
449 | GNUNET_CONTAINER_slist_add (ml->handles_except, | 449 | GNUNET_CONTAINER_slist_add (ml->handles_except, |
450 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 450 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
451 | fh, sizeof (struct GNUNET_DISK_FileHandle)); | 451 | fh, sizeof (struct GNUNET_DISK_FileHandle)); |
452 | pre_ret += 1; | 452 | pre_ret += 1; |
453 | } | 453 | } |
454 | } | 454 | } |
455 | } | 455 | } |
456 | } | 456 | } |
457 | GNUNET_CONTAINER_slist_iter_destroy (t); | 457 | GNUNET_CONTAINER_slist_iter_destroy (t); |
458 | 458 | ||
459 | if (rfds != NULL && rfds->sds.fd_count > 0) | 459 | if (rfds != NULL && rfds->sds.fd_count > 0) |
460 | { | 460 | { |
461 | #if DEBUG_NETWORK | 461 | #if DEBUG_NETWORK |
462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket read event to the array as %d\n", fd_counter); | 462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket read event to the array as %d\n", fd_counter); |
463 | #endif | 463 | #endif |
464 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventRead; | 464 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventRead; |
465 | ml->cached_poll_array[fd_counter].events = G_IO_IN; | 465 | ml->cached_poll_array[fd_counter].events = G_IO_IN; |
466 | for (i = 0; i < rfds->sds.fd_count; i++) | 466 | for (i = 0; i < rfds->sds.fd_count; i++) |
467 | WSAEventSelect (rfds->sds.fd_array[i], ml->hEventRead, FD_ACCEPT | FD_READ | FD_CLOSE); | 467 | WSAEventSelect (rfds->sds.fd_array[i], ml->hEventRead, FD_ACCEPT | FD_READ | FD_CLOSE); |
468 | fd_counter += 1; | 468 | fd_counter += 1; |
469 | sock_read = rfds->sds.fd_count; | 469 | sock_read = rfds->sds.fd_count; |
470 | } | 470 | } |
471 | if (wfds != NULL && wfds->sds.fd_count > 0) | 471 | if (wfds != NULL && wfds->sds.fd_count > 0) |
472 | { | 472 | { |
473 | int wakeup = 0; | 473 | int wakeup = 0; |
474 | #if DEBUG_NETWORK | 474 | #if DEBUG_NETWORK |
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket write event to the array as %d\n", fd_counter); | 475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket write event to the array as %d\n", fd_counter); |
476 | #endif | 476 | #endif |
477 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventWrite; | 477 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventWrite; |
478 | ml->cached_poll_array[fd_counter].events = G_IO_OUT; | 478 | ml->cached_poll_array[fd_counter].events = G_IO_OUT; |
479 | for (i = 0; i < wfds->sds.fd_count; i++) | 479 | for (i = 0; i < wfds->sds.fd_count; i++) |
480 | { | 480 | { |
481 | DWORD error; | 481 | DWORD error; |
482 | int status; | 482 | int status; |
483 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); | 483 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); |
484 | error = GetLastError (); | 484 | error = GetLastError (); |
485 | #if DEBUG_NETWORK | 485 | #if DEBUG_NETWORK |
486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pre-send to the socket %d returned %d (%u)\n", i, status, error); | 486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pre-send to the socket %d returned %d (%u)\n", i, status, error); |
487 | #endif | 487 | #endif |
488 | if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) | 488 | if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) |
489 | wakeup = 1; | 489 | wakeup = 1; |
490 | WSAEventSelect (wfds->sds.fd_array[i], ml->hEventWrite, FD_WRITE | FD_CONNECT | FD_CLOSE); | 490 | WSAEventSelect (wfds->sds.fd_array[i], ml->hEventWrite, FD_WRITE | FD_CONNECT | FD_CLOSE); |
491 | } | 491 | } |
492 | if (wakeup) | 492 | if (wakeup) |
493 | SetEvent (ml->hEventWrite); | 493 | SetEvent (ml->hEventWrite); |
494 | fd_counter += 1; | 494 | fd_counter += 1; |
495 | sock_write = wfds->sds.fd_count; | 495 | sock_write = wfds->sds.fd_count; |
496 | } | 496 | } |
497 | if (efds != NULL && efds->sds.fd_count > 0) | 497 | if (efds != NULL && efds->sds.fd_count > 0) |
498 | { | 498 | { |
499 | #if DEBUG_NETWORK | 499 | #if DEBUG_NETWORK |
500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket error event to the array as %d\n", fd_counter); | 500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket error event to the array as %d\n", fd_counter); |
501 | #endif | 501 | #endif |
502 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventException; | 502 | ml->cached_poll_array[fd_counter].fd = (intptr_t) ml->hEventException; |
503 | ml->cached_poll_array[fd_counter].events = G_IO_ERR; | 503 | ml->cached_poll_array[fd_counter].events = G_IO_ERR; |
504 | for (i = 0; i < efds->sds.fd_count; i++) | 504 | for (i = 0; i < efds->sds.fd_count; i++) |
505 | WSAEventSelect (efds->sds.fd_array[i], ml->hEventException, FD_OOB | FD_CLOSE); | 505 | WSAEventSelect (efds->sds.fd_array[i], ml->hEventException, FD_OOB | FD_CLOSE); |
506 | fd_counter += 1; | 506 | fd_counter += 1; |
507 | sock_err = efds->sds.fd_count; | 507 | sock_err = efds->sds.fd_count; |
508 | } | 508 | } |
509 | break; | 509 | break; |
510 | #endif | 510 | #endif |
511 | } | 511 | } |
512 | socks = sock_read + sock_write + sock_err; | 512 | socks = sock_read + sock_write + sock_err; |
513 | 513 | ||
514 | g_main_context_prepare (ml->gmc, &ml->max_priority); | 514 | g_main_context_prepare (ml->gmc, &ml->max_priority); |