aboutsummaryrefslogtreecommitdiff
path: root/src/lib/eventloop.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 13:17:59 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 13:17:59 +0000
commitd4d1ddd29caf14f7bb502abc133288b50b9d0ce1 (patch)
tree7b93ef58e97f7e66a9c7434b8b4da3a4aebfd888 /src/lib/eventloop.c
parent7a56e9e47132054fa8c527e1f6f35b6b2450f3f2 (diff)
downloadgnunet-gtk-d4d1ddd29caf14f7bb502abc133288b50b9d0ce1.tar.gz
gnunet-gtk-d4d1ddd29caf14f7bb502abc133288b50b9d0ce1.zip
indenting
Diffstat (limited to 'src/lib/eventloop.c')
-rw-r--r--src/lib/eventloop.c231
1 files changed, 120 insertions, 111 deletions
diff --git a/src/lib/eventloop.c b/src/lib/eventloop.c
index d1e8cd44..91010f67 100644
--- a/src/lib/eventloop.c
+++ b/src/lib/eventloop.c
@@ -599,146 +599,155 @@ gnunet_gtk_select (void *cls,
599 } 599 }
600#else 600#else
601 if (socks > 0) 601 if (socks > 0)
602 { 602 {
603 struct timeval tvslice; 603 struct timeval tvslice;
604 tvslice.tv_sec = 0; 604 tvslice.tv_sec = 0;
605 tvslice.tv_usec = 0; 605 tvslice.tv_usec = 0;
606 select_ret = select (max_nfds, &aread, &awrite, &aexcept, &tvslice); 606 select_ret = select (max_nfds, &aread, &awrite, &aexcept, &tvslice);
607 if (select_ret == -1) 607 if (select_ret == -1)
608 select_ret = 0; 608 select_ret = 0;
609#if DEBUG_NETWORK 609#if DEBUG_NETWORK
610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "select() returned %d\n", select_ret); 610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
611 "select() returned %d\n",
612 select_ret);
611#endif 613#endif
612 } 614 }
613 if (always_ready_write_fd >= 0 && ml->cached_poll_array[always_ready_write_fd].revents & G_IO_OUT) 615 if (always_ready_write_fd >= 0 && ml->cached_poll_array[always_ready_write_fd].revents & G_IO_OUT)
614 { 616 {
615 GNUNET_CONTAINER_slist_append (ml->handles_write, wfds->handles); 617 GNUNET_CONTAINER_slist_append (ml->handles_write, wfds->handles);
616 result += GNUNET_CONTAINER_slist_count (ml->handles_write); 618 result += GNUNET_CONTAINER_slist_count (ml->handles_write);
617#if DEBUG_NETWORK 619#if DEBUG_NETWORK
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n"); 620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n");
619#endif 621#endif
620 } 622 }
621 for (i = 0; i < read_handles; i++) 623 for (i = 0; i < read_handles; i++)
622 { 624 {
623 DWORD error; 625 DWORD error;
624 BOOL bret; 626 BOOL bret;
625 if (!(ml->cached_poll_array[i].revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) 627 if (!(ml->cached_poll_array[i].revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)))
626 continue; 628 continue;
627 SetLastError (0); 629 SetLastError (0);
628 waitstatus = 0; 630 waitstatus = 0;
629 bret = PeekNamedPipe (ml->read_array[i]->h, NULL, 0, NULL, &waitstatus, NULL); 631 bret = PeekNamedPipe (ml->read_array[i]->h, NULL, 0, NULL, &waitstatus, NULL);
630 error = GetLastError (); 632 error = GetLastError ();
631#if DEBUG_NETWORK 633#if DEBUG_NETWORK
632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
633 "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n", 635 "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n",
634 i, ml->read_array[i]->h, bret, waitstatus, error); 636 i, ml->read_array[i]->h, bret, waitstatus, error);
635#endif 637#endif
636 if (bret == 0 || (ml->cached_poll_array[i].revents & G_IO_ERR)) 638 if (bret == 0 || (ml->cached_poll_array[i].revents & G_IO_ERR))
637 { 639 {
638 if (efds != NULL) 640 if (efds != NULL)
639 { 641 {
640 struct GNUNET_CONTAINER_SList_Iterator *t; 642 struct GNUNET_CONTAINER_SList_Iterator *t;
641 for (t = GNUNET_CONTAINER_slist_begin (efds->handles), i = 0; 643 for (t = GNUNET_CONTAINER_slist_begin (efds->handles), i = 0;
642 GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; 644 GNUNET_CONTAINER_slist_end (t) != GNUNET_YES;
643 GNUNET_CONTAINER_slist_next (t), i += 1) 645 GNUNET_CONTAINER_slist_next (t), i += 1)
644 { 646 {
645 struct GNUNET_DISK_FileHandle *fh = GNUNET_CONTAINER_slist_get (t, NULL); 647 struct GNUNET_DISK_FileHandle *fh = GNUNET_CONTAINER_slist_get (t, NULL);
646 if (fh == ml->read_array[i]) 648 if (fh == ml->read_array[i])
647 { 649 {
648 GNUNET_CONTAINER_slist_add (ml->handles_except, 650 GNUNET_CONTAINER_slist_add (ml->handles_except,
649 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 651 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
650 fh, sizeof (struct GNUNET_DISK_FileHandle)); 652 fh, sizeof (struct GNUNET_DISK_FileHandle));
651 break; 653 break;
652 } 654 }
653 } 655 }
654 GNUNET_CONTAINER_slist_iter_destroy (t); 656 GNUNET_CONTAINER_slist_iter_destroy (t);
655 } 657 }
656 } 658 }
657 else if (waitstatus <= 0) 659 else if (waitstatus <= 0)
658 continue; 660 continue;
659 GNUNET_CONTAINER_slist_add (ml->handles_read, 661 GNUNET_CONTAINER_slist_add (ml->handles_read,
660 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 662 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
661 ml->read_array[i], sizeof (struct GNUNET_DISK_FileHandle)); 663 ml->read_array[i], sizeof (struct GNUNET_DISK_FileHandle));
662 result += 1; 664 result += 1;
663#if DEBUG_NETWORK 665#if DEBUG_NETWORK
664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n", ml->read_array[i], ml->read_array[i]->h); 666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
667 "Added read Pipe 0x%x (0x%x)\n",
668 ml->read_array[i],
669 ml->read_array[i]->h);
665#endif 670#endif
666 } 671 }
667 waitstatus = WaitForSingleObject (ml->hEventWrite, 0); 672 waitstatus = WaitForSingleObject (ml->hEventWrite, 0);
668#if DEBUG_NETWORK 673#if DEBUG_NETWORK
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Wait for the write event returned %d\n", waitstatus); 674 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
675 "Wait for the write event returned %d\n",
676 waitstatus);
670#endif 677#endif
671 if (waitstatus == WAIT_OBJECT_0) 678 if (waitstatus == WAIT_OBJECT_0)
672 {
673 for (i = 0; i < wfds->sds.fd_count; i++)
674 { 679 {
675 DWORD error; 680 for (i = 0; i < wfds->sds.fd_count; i++)
676 int status; 681 {
677 int so_error = 0; 682 DWORD error;
678 int sizeof_so_error = sizeof (so_error); 683 int status;
679 int gso_result = getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR, (char *) &so_error, &sizeof_so_error); 684 int so_error = 0;
680 status = send (wfds->sds.fd_array[i], NULL, 0, 0); 685 int sizeof_so_error = sizeof (so_error);
681 error = GetLastError (); 686 int gso_result = getsockopt (wfds->sds.fd_array[i],
687 SOL_SOCKET, SO_ERROR,
688 (char *) &so_error, &sizeof_so_error);
689 status = send (wfds->sds.fd_array[i], NULL, 0, 0);
690 error = GetLastError ();
682#if DEBUG_NETWORK 691#if DEBUG_NETWORK
683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
684 "send to the socket %d returned %d (%u)\n", 693 "send to the socket %d returned %d (%u)\n",
685 i, status, error); 694 i, status, error);
686#endif 695#endif
687 if (status == 0 696 if (status == 0
688 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) 697 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)
689 || (status == -1 && gso_result == 0 && error == WSAENOTCONN && so_error == WSAECONNREFUSED)) 698 || (status == -1 && gso_result == 0 && error == WSAENOTCONN && so_error == WSAECONNREFUSED))
690 { 699 {
691 FD_SET (wfds->sds.fd_array[i], &awrite); 700 FD_SET (wfds->sds.fd_array[i], &awrite);
692 result += 1; 701 result += 1;
693 } 702 }
703 }
694 } 704 }
695 }
696 if (rfds) 705 if (rfds)
697 {
698 struct GNUNET_CONTAINER_SList_Iterator *t;
699 for (i = 0; i < rfds->sds.fd_count; i++)
700 WSAEventSelect (rfds->sds.fd_array[i], ml->hEventRead, 0);
701 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
702 GNUNET_CONTAINER_slist_end (t) != GNUNET_YES;
703 GNUNET_CONTAINER_slist_next (t))
704 { 706 {
705 struct GNUNET_DISK_FileHandle *fh = GNUNET_CONTAINER_slist_get (t, NULL); 707 struct GNUNET_CONTAINER_SList_Iterator *t;
706 if (fh->type == GNUNET_PIPE) 708 for (i = 0; i < rfds->sds.fd_count; i++)
707 CancelIo (fh->h); 709 WSAEventSelect (rfds->sds.fd_array[i], ml->hEventRead, 0);
710 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
711 GNUNET_CONTAINER_slist_end (t) != GNUNET_YES;
712 GNUNET_CONTAINER_slist_next (t))
713 {
714 struct GNUNET_DISK_FileHandle *fh = GNUNET_CONTAINER_slist_get (t, NULL);
715 if (fh->type == GNUNET_PIPE)
716 CancelIo (fh->h);
717 }
718 GNUNET_CONTAINER_slist_iter_destroy (t);
719 GNUNET_NETWORK_fdset_zero (rfds);
720 if (select_ret != -1 && socks > 0)
721 GNUNET_NETWORK_fdset_copy_native (rfds, &aread, select_ret);
722 GNUNET_CONTAINER_slist_append (rfds->handles, ml->handles_read);
708 } 723 }
709 GNUNET_CONTAINER_slist_iter_destroy (t);
710 GNUNET_NETWORK_fdset_zero (rfds);
711 if (select_ret != -1 && socks > 0)
712 GNUNET_NETWORK_fdset_copy_native (rfds, &aread, select_ret);
713 GNUNET_CONTAINER_slist_append (rfds->handles, ml->handles_read);
714 }
715 if (wfds) 724 if (wfds)
716 { 725 {
717 for (i = 0; i < wfds->sds.fd_count; i++) 726 for (i = 0; i < wfds->sds.fd_count; i++)
718 WSAEventSelect (wfds->sds.fd_array[i], ml->hEventWrite, 0); 727 WSAEventSelect (wfds->sds.fd_array[i], ml->hEventWrite, 0);
719 GNUNET_NETWORK_fdset_zero (wfds); 728 GNUNET_NETWORK_fdset_zero (wfds);
720 if (select_ret != -1 && socks > 0) 729 if (select_ret != -1 && socks > 0)
721 GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, select_ret); 730 GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, select_ret);
722 GNUNET_CONTAINER_slist_append (wfds->handles, ml->handles_write); 731 GNUNET_CONTAINER_slist_append (wfds->handles, ml->handles_write);
723 } 732 }
724 if (efds) 733 if (efds)
725 { 734 {
726 for (i = 0; i < efds->sds.fd_count; i++) 735 for (i = 0; i < efds->sds.fd_count; i++)
727 WSAEventSelect (efds->sds.fd_array[i], ml->hEventException, 0); 736 WSAEventSelect (efds->sds.fd_array[i], ml->hEventException, 0);
728 GNUNET_NETWORK_fdset_zero (efds); 737 GNUNET_NETWORK_fdset_zero (efds);
729 if (select_ret != -1 && socks > 0) 738 if (select_ret != -1 && socks > 0)
730 GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, select_ret); 739 GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, select_ret);
731 GNUNET_CONTAINER_slist_append (efds->handles, ml->handles_except); 740 GNUNET_CONTAINER_slist_append (efds->handles, ml->handles_except);
732 result += GNUNET_CONTAINER_slist_count (ml->handles_except); 741 result += GNUNET_CONTAINER_slist_count (ml->handles_except);
733 } 742 }
734 if (fd_counter > 0) 743 if (fd_counter > 0)
735 /* This is not accurate (select_ret counts write-ready sockets, 744 /* This is not accurate (select_ret counts write-ready sockets,
736 * and result does as well. Anything out there actually cares 745 * and result does as well. Anything out there actually cares
737 * about this? 746 * about this?
738 */ 747 */
739 return select_ret + result; 748 result = select_ret + result;
740 else 749 else
741 return 0; 750 result = 0;
742#endif 751#endif
743 return result; 752 return result;
744} 753}