aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_unix.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-05-03 08:16:06 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-05-03 08:16:06 +0000
commit5d0af07ba54df3f2b0b9a5b367b1a6844eef67f6 (patch)
tree14053f24329c2ae26d4aad1cdadae5e3d9c56beb /src/transport/plugin_transport_unix.c
parentec8695870ac7a738c247f35a2380742ec2d402e3 (diff)
downloadgnunet-5d0af07ba54df3f2b0b9a5b367b1a6844eef67f6.tar.gz
gnunet-5d0af07ba54df3f2b0b9a5b367b1a6844eef67f6.zip
- improved rescheduling
Diffstat (limited to 'src/transport/plugin_transport_unix.c')
-rw-r--r--src/transport/plugin_transport_unix.c98
1 files changed, 57 insertions, 41 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 78025ab75..1f39f1d40 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -243,17 +243,71 @@ struct Plugin
243 unsigned int bytes_in_queue; 243 unsigned int bytes_in_queue;
244}; 244};
245 245
246static void
247unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
248
249static void
250reschedule_select (struct Plugin * plugin)
251{
252
253 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
254 {
255 GNUNET_SCHEDULER_cancel (plugin->select_task);
256 plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
257 }
258
259 if (NULL != plugin->msg_head)
260 {
261 plugin->select_task =
262 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
263 GNUNET_TIME_UNIT_FOREVER_REL,
264 plugin->rs,
265 plugin->ws,
266 &unix_plugin_select, plugin);
267 plugin->with_ws = GNUNET_YES;
268 }
269 else
270 {
271 plugin->select_task =
272 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
273 GNUNET_TIME_UNIT_FOREVER_REL,
274 plugin->rs,
275 NULL,
276 &unix_plugin_select, plugin);
277 plugin->with_ws = GNUNET_NO;
278 }
279}
280
246 281
247static int 282static int
248get_session_delete_it (void *cls, const GNUNET_HashCode * key, void *value) 283get_session_delete_it (void *cls, const GNUNET_HashCode * key, void *value)
249{ 284{
250 struct Session *s = value; 285 struct Session *s = value;
286 struct UNIXMessageWrapper * msgw;
251 struct Plugin *plugin = cls; 287 struct Plugin *plugin = cls;
288 int removed;
252 GNUNET_assert (plugin != NULL); 289 GNUNET_assert (plugin != NULL);
253 290
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting session for peer `%s' `%s' \n", GNUNET_i2s (&s->target), s->addr); 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting session for peer `%s' `%s' \n", GNUNET_i2s (&s->target), s->addr);
255 plugin->env->session_end (plugin->env->cls, &s->target, s); 292 plugin->env->session_end (plugin->env->cls, &s->target, s);
256 293
294 msgw = plugin->msg_head;
295 removed = GNUNET_NO;
296 while (NULL != (msgw = plugin->msg_head))
297 {
298 if (msgw->session == s)
299 {
300 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
301 if (msgw->cont != NULL)
302 msgw->cont (msgw->cont_cls, &msgw->session->target, GNUNET_SYSERR);
303 GNUNET_free (msgw->msg);
304 GNUNET_free (msgw);
305 removed = GNUNET_YES;
306 }
307 }
308 if ((GNUNET_YES == removed) && (NULL == plugin->msg_head))
309 reschedule_select (plugin);
310
257 GNUNET_assert (GNUNET_YES == 311 GNUNET_assert (GNUNET_YES ==
258 GNUNET_CONTAINER_multihashmap_remove(plugin->session_map, &s->target.hashPubKey, s)); 312 GNUNET_CONTAINER_multihashmap_remove(plugin->session_map, &s->target.hashPubKey, s));
259 313
@@ -263,7 +317,6 @@ get_session_delete_it (void *cls, const GNUNET_HashCode * key, void *value)
263 GNUNET_NO); 317 GNUNET_NO);
264 318
265 GNUNET_free (s); 319 GNUNET_free (s);
266
267 return GNUNET_YES; 320 return GNUNET_YES;
268} 321}
269 322
@@ -667,16 +720,7 @@ unix_plugin_send (void *cls,
667 (char *) session->addr); 720 (char *) session->addr);
668 if (plugin->with_ws == GNUNET_NO) 721 if (plugin->with_ws == GNUNET_NO)
669 { 722 {
670 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) 723 reschedule_select (plugin);
671 GNUNET_SCHEDULER_cancel(plugin->select_task);
672
673 plugin->select_task =
674 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
675 GNUNET_TIME_UNIT_FOREVER_REL,
676 plugin->rs,
677 plugin->ws,
678 &unix_plugin_select, plugin);
679 plugin->with_ws = GNUNET_YES;
680 } 724 }
681 return ssize; 725 return ssize;
682} 726}
@@ -882,29 +926,7 @@ unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
882 unix_plugin_select_read (plugin); 926 unix_plugin_select_read (plugin);
883 } 927 }
884 928
885 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) 929 reschedule_select (plugin);
886 GNUNET_SCHEDULER_cancel (plugin->select_task);
887
888 if (NULL != plugin->msg_head)
889 {
890 plugin->select_task =
891 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
892 GNUNET_TIME_UNIT_FOREVER_REL,
893 plugin->rs,
894 plugin->ws,
895 &unix_plugin_select, plugin);
896 plugin->with_ws = GNUNET_YES;
897 }
898 else
899 {
900 plugin->select_task =
901 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
902 GNUNET_TIME_UNIT_FOREVER_REL,
903 plugin->rs,
904 NULL,
905 &unix_plugin_select, plugin);
906 plugin->with_ws = GNUNET_NO;
907 }
908} 930}
909 931
910/** 932/**
@@ -965,13 +987,7 @@ unix_transport_server_start (void *cls)
965 GNUNET_NETWORK_fdset_set (plugin->rs, plugin->unix_sock.desc); 987 GNUNET_NETWORK_fdset_set (plugin->rs, plugin->unix_sock.desc);
966 GNUNET_NETWORK_fdset_set (plugin->ws, plugin->unix_sock.desc); 988 GNUNET_NETWORK_fdset_set (plugin->ws, plugin->unix_sock.desc);
967 989
968 plugin->select_task = 990 reschedule_select (plugin);
969 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
970 GNUNET_TIME_UNIT_FOREVER_REL,
971 plugin->rs,
972 NULL,
973 &unix_plugin_select, plugin);
974 plugin->with_ws = GNUNET_NO;
975 991
976 return 1; 992 return 1;
977} 993}