From 0b911f6f0cb0159a97509b37ce0557942eac9ce9 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 14 Nov 2012 14:09:43 +0000 Subject: [PATCH] improve unix timeout behaviour --- src/transport/plugin_transport_unix.c | 38 ++++++++++++++++--- .../test_transport_api_unreliability.c | 2 +- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index fee1c58c0..d9badf380 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -108,7 +108,7 @@ struct UNIXMessageWrapper size_t msgsize; size_t payload; - struct GNUNET_TIME_Relative timeout; + struct GNUNET_TIME_Absolute timeout; unsigned int priority; struct Session *session; @@ -495,7 +495,7 @@ unix_real_send (void *cls, struct GNUNET_NETWORK_Handle *send_handle, const struct GNUNET_PeerIdentity *target, const char *msgbuf, size_t msgbuf_size, unsigned int priority, - struct GNUNET_TIME_Relative timeout, + struct GNUNET_TIME_Absolute timeout, const void *addr, size_t addrlen, size_t payload, @@ -753,7 +753,7 @@ unix_plugin_send (void *cls, wrapper->msgsize = ssize; wrapper->payload = msgbuf_size; wrapper->priority = priority; - wrapper->timeout = to; + wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), to); wrapper->cont = cont; wrapper->cont_cls = cont_cls; wrapper->session = session; @@ -896,7 +896,35 @@ unix_plugin_select_write (struct Plugin * plugin) { static int retry_counter = 0; int sent = 0; - struct UNIXMessageWrapper * msgw = plugin->msg_head; + + + struct UNIXMessageWrapper * msgw = plugin->msg_tail; + while (NULL != msgw) + { + if (GNUNET_TIME_absolute_get_remaining (msgw->timeout).rel_value > 0) + break; /* Message is ready for sending */ + else + { + /* Message has a timeout */ + GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); + if (NULL != msgw->cont) + msgw->cont (msgw->cont_cls, &msgw->session->target, GNUNET_SYSERR, msgw->payload, 0); + + plugin->bytes_in_queue -= msgw->msgsize; + GNUNET_STATISTICS_set (plugin->env->stats, "# bytes currently in UNIX buffers", + plugin->bytes_in_queue, GNUNET_NO); + + plugin->bytes_discarded += msgw->msgsize; + GNUNET_STATISTICS_set (plugin->env->stats,"# UNIX bytes discarded", + plugin->bytes_discarded, GNUNET_NO); + + GNUNET_free (msgw->msg); + GNUNET_free (msgw); + } + msgw = plugin->msg_tail; + } + if (NULL == msgw) + return; /* Nothing to send at the moment */ sent = unix_real_send (plugin, plugin->unix_sock.desc, @@ -965,8 +993,6 @@ unix_plugin_select_write (struct Plugin * plugin) GNUNET_free (msgw); return; } - - } diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c index f1e249cdb..73158e59c 100644 --- a/src/transport/test_transport_api_unreliability.c +++ b/src/transport/test_transport_api_unreliability.c @@ -447,7 +447,7 @@ static void sendtask () { start_time = GNUNET_TIME_absolute_get (); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting to send %u messages\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to send %u messages\n", TOTAL_MSGS); th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), 0, TIMEOUT_TRANSMIT, ¬ify_ready, -- 2.25.1