diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-27 12:27:15 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-27 12:27:15 +0000 |
commit | f4c1249ba12461abe0616963959b9470a41e1de5 (patch) | |
tree | b06fc1a4e500f0cff193b2034fb5cc1582459b46 /src/transport/plugin_transport_unix.c | |
parent | d24c48a02579b812cd01f2fa32b687160dc61036 (diff) | |
download | gnunet-f4c1249ba12461abe0616963959b9470a41e1de5.tar.gz gnunet-f4c1249ba12461abe0616963959b9470a41e1de5.zip |
-first half of write select implementation
Diffstat (limited to 'src/transport/plugin_transport_unix.c')
-rw-r--r-- | src/transport/plugin_transport_unix.c | 84 |
1 files changed, 55 insertions, 29 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 7d41b95a7..06918d39d 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -325,6 +325,11 @@ struct Plugin | |||
325 | struct GNUNET_NETWORK_FDSet *rs; | 325 | struct GNUNET_NETWORK_FDSet *rs; |
326 | 326 | ||
327 | /** | 327 | /** |
328 | * FD Write set | ||
329 | */ | ||
330 | struct GNUNET_NETWORK_FDSet *ws; | ||
331 | |||
332 | /** | ||
328 | * socket that we transmit all data with | 333 | * socket that we transmit all data with |
329 | */ | 334 | */ |
330 | struct UNIX_Sock_Info unix_sock; | 335 | struct UNIX_Sock_Info unix_sock; |
@@ -806,19 +811,9 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
806 | } | 811 | } |
807 | 812 | ||
808 | 813 | ||
809 | /* | ||
810 | * @param cls the plugin handle | ||
811 | * @param tc the scheduling context (for rescheduling this function again) | ||
812 | * | ||
813 | * We have been notified that our writeset has something to read. We don't | ||
814 | * know which socket needs to be read, so we have to check each one | ||
815 | * Then reschedule this function to be called again once more is available. | ||
816 | * | ||
817 | */ | ||
818 | static void | 814 | static void |
819 | unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 815 | unix_plugin_select_read (struct Plugin * plugin) |
820 | { | 816 | { |
821 | struct Plugin *plugin = cls; | ||
822 | char buf[65536]; | 817 | char buf[65536]; |
823 | struct UNIXMessage *msg; | 818 | struct UNIXMessage *msg; |
824 | struct GNUNET_PeerIdentity sender; | 819 | struct GNUNET_PeerIdentity sender; |
@@ -831,14 +826,9 @@ unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
831 | const struct GNUNET_MessageHeader *currhdr; | 826 | const struct GNUNET_MessageHeader *currhdr; |
832 | uint16_t csize; | 827 | uint16_t csize; |
833 | 828 | ||
834 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; | ||
835 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
836 | return; | ||
837 | |||
838 | addrlen = sizeof (un); | 829 | addrlen = sizeof (un); |
839 | memset (&un, 0, sizeof (un)); | 830 | memset (&un, 0, sizeof (un)); |
840 | GNUNET_assert (GNUNET_NETWORK_fdset_isset | 831 | |
841 | (tc->read_ready, plugin->unix_sock.desc)); | ||
842 | ret = | 832 | ret = |
843 | GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, buf, sizeof (buf), | 833 | GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, buf, sizeof (buf), |
844 | (struct sockaddr *) &un, &addrlen); | 834 | (struct sockaddr *) &un, &addrlen); |
@@ -846,11 +836,6 @@ unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
846 | if (ret == GNUNET_SYSERR) | 836 | if (ret == GNUNET_SYSERR) |
847 | { | 837 | { |
848 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); | 838 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); |
849 | plugin->select_task = | ||
850 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
851 | GNUNET_SCHEDULER_NO_TASK, | ||
852 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, | ||
853 | NULL, &unix_plugin_select, plugin); | ||
854 | return; | 839 | return; |
855 | } | 840 | } |
856 | else | 841 | else |
@@ -871,11 +856,6 @@ unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
871 | if ((csize < sizeof (struct UNIXMessage)) || (csize > ret)) | 856 | if ((csize < sizeof (struct UNIXMessage)) || (csize > ret)) |
872 | { | 857 | { |
873 | GNUNET_break_op (0); | 858 | GNUNET_break_op (0); |
874 | plugin->select_task = | ||
875 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
876 | GNUNET_SCHEDULER_NO_TASK, | ||
877 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, | ||
878 | NULL, &unix_plugin_select, plugin); | ||
879 | return; | 859 | return; |
880 | } | 860 | } |
881 | msgbuf = (char *) &msg[1]; | 861 | msgbuf = (char *) &msg[1]; |
@@ -895,11 +875,53 @@ unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
895 | unix_demultiplexer (plugin, &sender, currhdr, &un, sizeof (un)); | 875 | unix_demultiplexer (plugin, &sender, currhdr, &un, sizeof (un)); |
896 | offset += csize; | 876 | offset += csize; |
897 | } | 877 | } |
878 | } | ||
879 | |||
880 | static void | ||
881 | unix_plugin_select_write (struct Plugin * plugin) | ||
882 | { | ||
883 | |||
884 | |||
885 | } | ||
886 | |||
887 | /* | ||
888 | * @param cls the plugin handle | ||
889 | * @param tc the scheduling context (for rescheduling this function again) | ||
890 | * | ||
891 | * We have been notified that our writeset has something to read. We don't | ||
892 | * know which socket needs to be read, so we have to check each one | ||
893 | * Then reschedule this function to be called again once more is available. | ||
894 | * | ||
895 | */ | ||
896 | static void | ||
897 | unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
898 | { | ||
899 | struct Plugin *plugin = cls; | ||
900 | |||
901 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; | ||
902 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
903 | return; | ||
904 | |||
905 | |||
906 | if ((tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) | ||
907 | { | ||
908 | GNUNET_assert (GNUNET_NETWORK_fdset_isset | ||
909 | (tc->write_ready, plugin->unix_sock.desc)); | ||
910 | unix_plugin_select_write (plugin); | ||
911 | } | ||
912 | |||
913 | if ((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0) | ||
914 | { | ||
915 | GNUNET_assert (GNUNET_NETWORK_fdset_isset | ||
916 | (tc->read_ready, plugin->unix_sock.desc)); | ||
917 | unix_plugin_select_read (plugin); | ||
918 | } | ||
919 | |||
898 | plugin->select_task = | 920 | plugin->select_task = |
899 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 921 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
900 | GNUNET_SCHEDULER_NO_TASK, | 922 | GNUNET_SCHEDULER_NO_TASK, |
901 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, | 923 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, |
902 | NULL, &unix_plugin_select, plugin); | 924 | plugin->ws, &unix_plugin_select, plugin); |
903 | } | 925 | } |
904 | 926 | ||
905 | /** | 927 | /** |
@@ -956,14 +978,17 @@ unix_transport_server_start (void *cls) | |||
956 | &un.sun_path[0]); | 978 | &un.sun_path[0]); |
957 | #endif | 979 | #endif |
958 | plugin->rs = GNUNET_NETWORK_fdset_create (); | 980 | plugin->rs = GNUNET_NETWORK_fdset_create (); |
981 | plugin->ws = GNUNET_NETWORK_fdset_create (); | ||
959 | GNUNET_NETWORK_fdset_zero (plugin->rs); | 982 | GNUNET_NETWORK_fdset_zero (plugin->rs); |
983 | GNUNET_NETWORK_fdset_zero (plugin->ws); | ||
960 | GNUNET_NETWORK_fdset_set (plugin->rs, plugin->unix_sock.desc); | 984 | GNUNET_NETWORK_fdset_set (plugin->rs, plugin->unix_sock.desc); |
985 | GNUNET_NETWORK_fdset_set (plugin->ws, plugin->unix_sock.desc); | ||
961 | 986 | ||
962 | plugin->select_task = | 987 | plugin->select_task = |
963 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 988 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
964 | GNUNET_SCHEDULER_NO_TASK, | 989 | GNUNET_SCHEDULER_NO_TASK, |
965 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, | 990 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, |
966 | NULL, &unix_plugin_select, plugin); | 991 | plugin->ws, &unix_plugin_select, plugin); |
967 | return 1; | 992 | return 1; |
968 | } | 993 | } |
969 | 994 | ||
@@ -1171,6 +1196,7 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1171 | unix_transport_server_stop (plugin); | 1196 | unix_transport_server_stop (plugin); |
1172 | 1197 | ||
1173 | GNUNET_NETWORK_fdset_destroy (plugin->rs); | 1198 | GNUNET_NETWORK_fdset_destroy (plugin->rs); |
1199 | GNUNET_NETWORK_fdset_destroy (plugin->ws); | ||
1174 | GNUNET_free (plugin->unix_socket_path); | 1200 | GNUNET_free (plugin->unix_socket_path); |
1175 | GNUNET_free (plugin); | 1201 | GNUNET_free (plugin); |
1176 | GNUNET_free (api); | 1202 | GNUNET_free (api); |