diff options
Diffstat (limited to 'src/arm/gnunet-service-arm_interceptor.c')
-rw-r--r-- | src/arm/gnunet-service-arm_interceptor.c | 86 |
1 files changed, 76 insertions, 10 deletions
diff --git a/src/arm/gnunet-service-arm_interceptor.c b/src/arm/gnunet-service-arm_interceptor.c index 9380a8deb..bc8db396b 100644 --- a/src/arm/gnunet-service-arm_interceptor.c +++ b/src/arm/gnunet-service-arm_interceptor.c | |||
@@ -847,7 +847,6 @@ stop_listening (const char *serviceName) | |||
847 | return ret; | 847 | return ret; |
848 | } | 848 | } |
849 | 849 | ||
850 | |||
851 | /** | 850 | /** |
852 | * First connection has come to the listening socket associated with the service, | 851 | * First connection has come to the listening socket associated with the service, |
853 | * create the service in order to relay the incoming connection to it | 852 | * create the service in order to relay the incoming connection to it |
@@ -856,14 +855,15 @@ stop_listening (const char *serviceName) | |||
856 | * @param tc context | 855 | * @param tc context |
857 | */ | 856 | */ |
858 | static void | 857 | static void |
859 | acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 858 | acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
859 | |||
860 | |||
861 | #if MINGW | ||
862 | static void | ||
863 | accept_and_forward (struct ServiceListeningInfo *serviceListeningInfo) | ||
860 | { | 864 | { |
861 | struct ServiceListeningInfo *serviceListeningInfo = cls; | ||
862 | struct ForwardedConnection *fc; | 865 | struct ForwardedConnection *fc; |
863 | 866 | ||
864 | serviceListeningInfo->acceptTask = GNUNET_SCHEDULER_NO_TASK; | ||
865 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
866 | return; | ||
867 | fc = GNUNET_malloc (sizeof (struct ForwardedConnection)); | 867 | fc = GNUNET_malloc (sizeof (struct ForwardedConnection)); |
868 | fc->listen_info = serviceListeningInfo; | 868 | fc->listen_info = serviceListeningInfo; |
869 | fc->service_to_client_bufferPos = fc->service_to_client_buffer; | 869 | fc->service_to_client_bufferPos = fc->service_to_client_buffer; |
@@ -879,6 +879,9 @@ acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
879 | serviceListeningInfo->serviceName, | 879 | serviceListeningInfo->serviceName, |
880 | STRERROR (errno)); | 880 | STRERROR (errno)); |
881 | GNUNET_free (fc); | 881 | GNUNET_free (fc); |
882 | GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head, | ||
883 | serviceListeningInfoList_tail, | ||
884 | serviceListeningInfo); | ||
882 | serviceListeningInfo->acceptTask = | 885 | serviceListeningInfo->acceptTask = |
883 | GNUNET_SCHEDULER_add_read_net (scheduler, | 886 | GNUNET_SCHEDULER_add_read_net (scheduler, |
884 | GNUNET_TIME_UNIT_FOREVER_REL, | 887 | GNUNET_TIME_UNIT_FOREVER_REL, |
@@ -889,10 +892,7 @@ acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
889 | } | 892 | } |
890 | GNUNET_break (GNUNET_OK == | 893 | GNUNET_break (GNUNET_OK == |
891 | GNUNET_NETWORK_socket_close (serviceListeningInfo->listeningSocket)); | 894 | GNUNET_NETWORK_socket_close (serviceListeningInfo->listeningSocket)); |
892 | GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head, | 895 | start_service (NULL, serviceListeningInfo->serviceName, NULL); |
893 | serviceListeningInfoList_tail, | ||
894 | serviceListeningInfo); | ||
895 | start_service (NULL, serviceListeningInfo->serviceName); | ||
896 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 896 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
897 | _("Service `%s' started\n"), | 897 | _("Service `%s' started\n"), |
898 | fc->listen_info->serviceName); | 898 | fc->listen_info->serviceName); |
@@ -909,6 +909,72 @@ acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
909 | &start_forwarding, | 909 | &start_forwarding, |
910 | fc); | 910 | fc); |
911 | } | 911 | } |
912 | #endif | ||
913 | |||
914 | |||
915 | /** | ||
916 | * First connection has come to the listening socket associated with the service, | ||
917 | * create the service in order to relay the incoming connection to it | ||
918 | * | ||
919 | * @param cls callback data, struct ServiceListeningInfo describing a listen socket | ||
920 | * @param tc context | ||
921 | */ | ||
922 | static void | ||
923 | acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
924 | { | ||
925 | struct ServiceListeningInfo *sli = cls; | ||
926 | struct ServiceListeningInfo *pos; | ||
927 | struct ServiceListeningInfo *next; | ||
928 | int *lsocks; | ||
929 | unsigned int ls; | ||
930 | |||
931 | sli->acceptTask = GNUNET_SCHEDULER_NO_TASK; | ||
932 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
933 | return; | ||
934 | GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head, | ||
935 | serviceListeningInfoList_tail, | ||
936 | sli); | ||
937 | #ifndef MINGW | ||
938 | lsocks = NULL; | ||
939 | ls = 0; | ||
940 | next = serviceListeningInfoList_head; | ||
941 | while (NULL != (pos = next)) | ||
942 | { | ||
943 | next = pos->next; | ||
944 | if (0 == strcmp (pos->serviceName, | ||
945 | sli->serviceName)) | ||
946 | { | ||
947 | GNUNET_array_append (lsocks, ls, | ||
948 | GNUNET_NETWORK_get_fd (pos->listeningSocket)); | ||
949 | GNUNET_free (pos->listeningSocket); /* deliberately no closing! */ | ||
950 | GNUNET_free (pos->service_addr); | ||
951 | GNUNET_free (pos->serviceName); | ||
952 | GNUNET_SCHEDULER_cancel (scheduler, | ||
953 | pos->acceptTask); | ||
954 | GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head, | ||
955 | serviceListeningInfoList_tail, | ||
956 | pos); | ||
957 | GNUNET_free (pos); | ||
958 | } | ||
959 | } | ||
960 | GNUNET_array_append (lsocks, ls, | ||
961 | GNUNET_NETWORK_get_fd (sli->listeningSocket)); | ||
962 | GNUNET_free (sli->listeningSocket); /* deliberately no closing! */ | ||
963 | GNUNET_free (sli->service_addr); | ||
964 | GNUNET_array_append (lsocks, ls, -1); | ||
965 | start_service (NULL, | ||
966 | sli->serviceName, | ||
967 | lsocks); | ||
968 | ls = 0; | ||
969 | while (lsocks[ls] != -1) | ||
970 | GNUNET_break (0 == close (lsocks[ls++])); | ||
971 | GNUNET_array_grow (lsocks, ls, 0); | ||
972 | GNUNET_free (sli->serviceName); | ||
973 | GNUNET_free (sli); | ||
974 | #else | ||
975 | accept_and_forward (sli); | ||
976 | #endif | ||
977 | } | ||
912 | 978 | ||
913 | 979 | ||
914 | /** | 980 | /** |