aboutsummaryrefslogtreecommitdiff
path: root/src/util/connection.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-11-15 16:49:39 +0000
committerChristian Grothoff <christian@grothoff.org>2009-11-15 16:49:39 +0000
commitc67e3cbb6b4e76c01cf6c6f14acafae0e32e34ed (patch)
tree2017a0613cb79ba53818cf94e8862cbdaadeb19c /src/util/connection.c
parent0652421a4cd27dd64877fe651678d6028ffb4c56 (diff)
downloadgnunet-c67e3cbb6b4e76c01cf6c6f14acafae0e32e34ed.tar.gz
gnunet-c67e3cbb6b4e76c01cf6c6f14acafae0e32e34ed.zip
ignore shutdown support for client/connection and shutdown fix in connection
Diffstat (limited to 'src/util/connection.c')
-rw-r--r--src/util/connection.c47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/util/connection.c b/src/util/connection.c
index c12ea2751..468fb750c 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -270,6 +270,11 @@ struct GNUNET_CONNECTION_Handle
270 size_t max; 270 size_t max;
271 271
272 /** 272 /**
273 * Ignore GNUNET_SCHEDULER_REASON_SHUTDOWN for this socket.
274 */
275 int ignore_shutdown;
276
277 /**
273 * Port to connect to. 278 * Port to connect to.
274 */ 279 */
275 uint16_t port; 280 uint16_t port;
@@ -490,8 +495,14 @@ destroy_continuation (void *cls,
490 return; 495 return;
491 } 496 }
492#if DEBUG_CONNECTION 497#if DEBUG_CONNECTION
493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock); 498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
499 "Destroy actually runs (%p)!\n", sock);
494#endif 500#endif
501 if (sock->dns_active != NULL)
502 {
503 GNUNET_RESOLVER_request_cancel (sock->dns_active);
504 sock->dns_active = NULL;
505 }
495 GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); 506 GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK);
496 GNUNET_assert (sock->ccs == COCO_NONE); 507 GNUNET_assert (sock->ccs == COCO_NONE);
497 if (NULL != (notify = sock->nth.notify_ready)) 508 if (NULL != (notify = sock->nth.notify_ready))
@@ -911,9 +922,8 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock)
911 sock->dns_active = NULL; 922 sock->dns_active = NULL;
912 } 923 }
913 GNUNET_assert (sock->sched != NULL); 924 GNUNET_assert (sock->sched != NULL);
914 GNUNET_SCHEDULER_add_after (sock->sched, 925 GNUNET_SCHEDULER_add_now (sock->sched,
915 GNUNET_SCHEDULER_NO_TASK, 926 &destroy_continuation, sock);
916 &destroy_continuation, sock);
917} 927}
918 928
919 929
@@ -962,6 +972,21 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
962 GNUNET_CONNECTION_Receiver receiver; 972 GNUNET_CONNECTION_Receiver receiver;
963 973
964 sh->read_task = GNUNET_SCHEDULER_NO_TASK; 974 sh->read_task = GNUNET_SCHEDULER_NO_TASK;
975 if ( (GNUNET_YES == sh->ignore_shutdown) &&
976 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
977 {
978 /* ignore shutdown request, go again immediately */
979#if DEBUG_CONNECTION
980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
981 "Ignoring shutdown signal per configuration\n");
982#endif
983 sh->read_task = GNUNET_SCHEDULER_add_read_net (tc->sched,
984 GNUNET_TIME_absolute_get_remaining
985 (sh->receive_timeout),
986 sh->sock,
987 &receive_ready, sh);
988 return;
989 }
965 now = GNUNET_TIME_absolute_get (); 990 now = GNUNET_TIME_absolute_get ();
966 if ((now.value > sh->receive_timeout.value) || 991 if ((now.value > sh->receive_timeout.value) ||
967 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) || 992 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) ||
@@ -1109,6 +1134,20 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock,
1109 1134
1110 1135
1111/** 1136/**
1137 * Configure this connection to ignore shutdown signals.
1138 *
1139 * @param sock socket handle
1140 * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default
1141 */
1142void
1143GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock,
1144 int do_ignore)
1145{
1146 sock->ignore_shutdown = do_ignore;
1147}
1148
1149
1150/**
1112 * Cancel receive job on the given socket. Note that the 1151 * Cancel receive job on the given socket. Note that the
1113 * receiver callback must not have been called yet in order 1152 * receiver callback must not have been called yet in order
1114 * for the cancellation to be valid. 1153 * for the cancellation to be valid.