diff options
author | Nils Durner <durner@gnunet.org> | 2009-11-13 21:49:46 +0000 |
---|---|---|
committer | Nils Durner <durner@gnunet.org> | 2009-11-13 21:49:46 +0000 |
commit | 9edcee802d2b2e1b2ce73f840c84ab84544093b5 (patch) | |
tree | 7c7ac76829ff19ad7ecb598a1f5256ce920f5b4a /src/util/network.c | |
parent | 6e82eafc0400a66cebcfbcc05429ffbd5acf55a1 (diff) | |
download | gnunet-9edcee802d2b2e1b2ce73f840c84ab84544093b5.tar.gz gnunet-9edcee802d2b2e1b2ce73f840c84ab84544093b5.zip |
various fixes
Diffstat (limited to 'src/util/network.c')
-rw-r--r-- | src/util/network.c | 99 |
1 files changed, 57 insertions, 42 deletions
diff --git a/src/util/network.c b/src/util/network.c index 5d7370003..3d2ff51de 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -636,6 +636,9 @@ GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, | |||
636 | if (nfds + 1 > dst->nsds) | 636 | if (nfds + 1 > dst->nsds) |
637 | dst->nsds = nfds + 1; | 637 | dst->nsds = nfds + 1; |
638 | } | 638 | } |
639 | #ifdef MINGW | ||
640 | GNUNET_CONTAINER_slist_append (dst->handles, src->handles); | ||
641 | #endif | ||
639 | } | 642 | } |
640 | 643 | ||
641 | 644 | ||
@@ -652,21 +655,8 @@ GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, | |||
652 | to->nsds = from->nsds; | 655 | to->nsds = from->nsds; |
653 | 656 | ||
654 | #ifdef MINGW | 657 | #ifdef MINGW |
655 | struct GNUNET_CONTAINER_SList_Iterator *iter; | ||
656 | GNUNET_CONTAINER_slist_clear (to->handles); | 658 | GNUNET_CONTAINER_slist_clear (to->handles); |
657 | for (iter = GNUNET_CONTAINER_slist_begin (from->handles); | 659 | GNUNET_CONTAINER_slist_append (to->handles, from->handles); |
658 | GNUNET_CONTAINER_slist_end (iter) != GNUNET_YES; | ||
659 | GNUNET_CONTAINER_slist_next (iter)) | ||
660 | |||
661 | { | ||
662 | void *handle; | ||
663 | size_t len; | ||
664 | handle = GNUNET_CONTAINER_slist_get (iter, &len); | ||
665 | GNUNET_CONTAINER_slist_add (to->handles, | ||
666 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | ||
667 | handle, len); | ||
668 | } | ||
669 | GNUNET_CONTAINER_slist_iter_destroy (iter); | ||
670 | #endif /* */ | 660 | #endif /* */ |
671 | } | 661 | } |
672 | 662 | ||
@@ -697,7 +687,7 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, | |||
697 | #ifdef MINGW | 687 | #ifdef MINGW |
698 | HANDLE hw; | 688 | HANDLE hw; |
699 | GNUNET_DISK_internal_file_handle_ (h, &hw, sizeof (HANDLE)); | 689 | GNUNET_DISK_internal_file_handle_ (h, &hw, sizeof (HANDLE)); |
700 | GNUNET_CONTAINER_slist_add (fds->handles, GNUNET_NO, &hw, sizeof (HANDLE)); | 690 | GNUNET_CONTAINER_slist_add (fds->handles, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &hw, sizeof (HANDLE)); |
701 | 691 | ||
702 | #else /* */ | 692 | #else /* */ |
703 | int fd; | 693 | int fd; |
@@ -722,7 +712,7 @@ GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, | |||
722 | { | 712 | { |
723 | 713 | ||
724 | #ifdef MINGW | 714 | #ifdef MINGW |
725 | return GNUNET_CONTAINER_slist_contains (fds->handles, h->h, | 715 | return GNUNET_CONTAINER_slist_contains (fds->handles, &h->h, |
726 | sizeof (HANDLE)); | 716 | sizeof (HANDLE)); |
727 | 717 | ||
728 | #else /* */ | 718 | #else /* */ |
@@ -749,6 +739,24 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, | |||
749 | for (; nfds >= 0; nfds--) | 739 | for (; nfds >= 0; nfds--) |
750 | if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) | 740 | if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) |
751 | return GNUNET_YES; | 741 | return GNUNET_YES; |
742 | #ifdef MINGW | ||
743 | { | ||
744 | struct GNUNET_CONTAINER_SList_Iterator *it; | ||
745 | |||
746 | for(it = GNUNET_CONTAINER_slist_begin (fds1->handles); GNUNET_CONTAINER_slist_end (it) != GNUNET_YES; GNUNET_CONTAINER_slist_next (it)) | ||
747 | { | ||
748 | HANDLE *h; | ||
749 | |||
750 | h = GNUNET_CONTAINER_slist_get (it, NULL); | ||
751 | if (GNUNET_CONTAINER_slist_contains (fds2->handles, h, sizeof (HANDLE))) | ||
752 | { | ||
753 | GNUNET_CONTAINER_slist_iter_destroy (it); | ||
754 | return GNUNET_YES; | ||
755 | } | ||
756 | } | ||
757 | GNUNET_CONTAINER_slist_iter_destroy (it); | ||
758 | } | ||
759 | #endif | ||
752 | return GNUNET_NO; | 760 | return GNUNET_NO; |
753 | } | 761 | } |
754 | 762 | ||
@@ -859,6 +867,8 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
859 | DWORD limit; | 867 | DWORD limit; |
860 | fd_set sock_read, sock_write, sock_except; | 868 | fd_set sock_read, sock_write, sock_except; |
861 | fd_set aread, awrite, aexcept; | 869 | fd_set aread, awrite, aexcept; |
870 | struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except; | ||
871 | |||
862 | int i; | 872 | int i; |
863 | struct timeval tvslice; | 873 | struct timeval tvslice; |
864 | int retcode; | 874 | int retcode; |
@@ -880,6 +890,11 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
880 | Sleep (ms_total); | 890 | Sleep (ms_total); |
881 | return 0; | 891 | return 0; |
882 | } | 892 | } |
893 | |||
894 | handles_read = GNUNET_CONTAINER_slist_create (); | ||
895 | handles_write = GNUNET_CONTAINER_slist_create (); | ||
896 | handles_except = GNUNET_CONTAINER_slist_create (); | ||
897 | |||
883 | if (rfds) | 898 | if (rfds) |
884 | sock_read = rfds->sds; | 899 | sock_read = rfds->sds; |
885 | else | 900 | else |
@@ -936,22 +951,16 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
936 | 951 | ||
937 | { | 952 | { |
938 | struct GNUNET_CONTAINER_SList_Iterator *i; | 953 | struct GNUNET_CONTAINER_SList_Iterator *i; |
939 | int on_next; | ||
940 | on_next = GNUNET_NO; | ||
941 | for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); | 954 | for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); |
942 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; | 955 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; |
943 | on_next || GNUNET_CONTAINER_slist_next (i)) | 956 | GNUNET_CONTAINER_slist_next (i)) |
944 | 957 | ||
945 | { | 958 | { |
946 | HANDLE h; | 959 | HANDLE h; |
947 | DWORD dwBytes; | 960 | DWORD dwBytes; |
948 | h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL); | 961 | h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL); |
949 | on_next = GNUNET_NO; | ||
950 | if (!PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL)) | 962 | if (!PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL)) |
951 | |||
952 | { | 963 | { |
953 | GNUNET_CONTAINER_slist_erase (i); | ||
954 | on_next = GNUNET_YES; | ||
955 | retcode = -1; | 964 | retcode = -1; |
956 | SetErrnoFromWinError (GetLastError ()); | 965 | SetErrnoFromWinError (GetLastError ()); |
957 | 966 | ||
@@ -962,19 +971,14 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
962 | #endif /* */ | 971 | #endif /* */ |
963 | goto select_loop_end; | 972 | goto select_loop_end; |
964 | } | 973 | } |
965 | |||
966 | else if (dwBytes) | 974 | else if (dwBytes) |
967 | 975 | ||
968 | { | 976 | { |
977 | GNUNET_CONTAINER_slist_add (handles_read, | ||
978 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &h, | ||
979 | sizeof (HANDLE)); | ||
969 | retcode++; | 980 | retcode++; |
970 | } | 981 | } |
971 | |||
972 | else | ||
973 | |||
974 | { | ||
975 | GNUNET_CONTAINER_slist_erase (i); | ||
976 | on_next = GNUNET_YES; | ||
977 | } | ||
978 | } | 982 | } |
979 | GNUNET_CONTAINER_slist_iter_destroy (i); | 983 | GNUNET_CONTAINER_slist_iter_destroy (i); |
980 | } | 984 | } |
@@ -984,33 +988,31 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
984 | 988 | ||
985 | { | 989 | { |
986 | struct GNUNET_CONTAINER_SList_Iterator *i; | 990 | struct GNUNET_CONTAINER_SList_Iterator *i; |
987 | int on_next; | ||
988 | on_next = GNUNET_NO; | ||
989 | for (i = GNUNET_CONTAINER_slist_begin (efds->handles); | 991 | for (i = GNUNET_CONTAINER_slist_begin (efds->handles); |
990 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; | 992 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; |
991 | on_next || GNUNET_CONTAINER_slist_next (i)) | 993 | GNUNET_CONTAINER_slist_next (i)) |
992 | 994 | ||
993 | { | 995 | { |
994 | HANDLE h; | 996 | HANDLE h; |
995 | DWORD dwBytes; | 997 | DWORD dwBytes; |
996 | h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL); | 998 | h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL); |
997 | if (PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL)) | 999 | if (!PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL)) |
998 | 1000 | ||
999 | { | 1001 | { |
1000 | GNUNET_CONTAINER_slist_erase (i); | 1002 | GNUNET_CONTAINER_slist_add (handles_except, |
1001 | on_next = GNUNET_YES; | 1003 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &h, |
1004 | sizeof (HANDLE)); | ||
1002 | retcode++; | 1005 | retcode++; |
1003 | } | 1006 | } |
1004 | |||
1005 | else | ||
1006 | on_next = GNUNET_NO; | ||
1007 | } | 1007 | } |
1008 | GNUNET_CONTAINER_slist_iter_destroy (i); | 1008 | GNUNET_CONTAINER_slist_iter_destroy (i); |
1009 | } | 1009 | } |
1010 | 1010 | ||
1011 | /* FIXME */ | ||
1012 | if (wfds) | 1011 | if (wfds) |
1013 | GNUNET_assert (GNUNET_CONTAINER_slist_count (wfds->handles) == 0); | 1012 | { |
1013 | GNUNET_CONTAINER_slist_append (handles_write, wfds->handles); | ||
1014 | retcode += GNUNET_CONTAINER_slist_count (wfds->handles); | ||
1015 | } | ||
1014 | 1016 | ||
1015 | /* Check for closed sockets */ | 1017 | /* Check for closed sockets */ |
1016 | for (i = 0; i < nfds; i++) | 1018 | for (i = 0; i < nfds; i++) |
@@ -1046,6 +1048,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1046 | Sleep (GNUNET_MIN (100, limit - GetTickCount ())); | 1048 | Sleep (GNUNET_MIN (100, limit - GetTickCount ())); |
1047 | } | 1049 | } |
1048 | while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit)); | 1050 | while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit)); |
1051 | |||
1049 | if (retcode != -1) | 1052 | if (retcode != -1) |
1050 | 1053 | ||
1051 | { | 1054 | { |
@@ -1054,20 +1057,32 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1054 | { | 1057 | { |
1055 | GNUNET_NETWORK_fdset_zero (rfds); | 1058 | GNUNET_NETWORK_fdset_zero (rfds); |
1056 | GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); | 1059 | GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); |
1060 | GNUNET_CONTAINER_slist_clear (rfds->handles); | ||
1061 | GNUNET_CONTAINER_slist_append (rfds->handles, handles_read); | ||
1062 | |||
1057 | } | 1063 | } |
1058 | if (wfds) | 1064 | if (wfds) |
1059 | 1065 | ||
1060 | { | 1066 | { |
1061 | GNUNET_NETWORK_fdset_zero (wfds); | 1067 | GNUNET_NETWORK_fdset_zero (wfds); |
1062 | GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); | 1068 | GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); |
1069 | GNUNET_CONTAINER_slist_clear (wfds->handles); | ||
1070 | GNUNET_CONTAINER_slist_append (wfds->handles, handles_write); | ||
1063 | } | 1071 | } |
1064 | if (efds) | 1072 | if (efds) |
1065 | 1073 | ||
1066 | { | 1074 | { |
1067 | GNUNET_NETWORK_fdset_zero (efds); | 1075 | GNUNET_NETWORK_fdset_zero (efds); |
1068 | GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); | 1076 | GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); |
1077 | GNUNET_CONTAINER_slist_clear (efds->handles); | ||
1078 | GNUNET_CONTAINER_slist_append (efds->handles, handles_except); | ||
1069 | } | 1079 | } |
1070 | } | 1080 | } |
1081 | |||
1082 | GNUNET_CONTAINER_slist_destroy (handles_read); | ||
1083 | GNUNET_CONTAINER_slist_destroy (handles_write); | ||
1084 | GNUNET_CONTAINER_slist_destroy (handles_except); | ||
1085 | |||
1071 | return retcode; | 1086 | return retcode; |
1072 | 1087 | ||
1073 | #endif /* */ | 1088 | #endif /* */ |