int status);
+/**
+ * Context for transmitting replies to clients.
+ */
struct TransmitCallbackContext
{
+
+ /**
+ * We keep these in a doubly-linked list (for cleanup).
+ */
+ struct TransmitCallbackContext *next;
+
+ /**
+ * We keep these in a doubly-linked list (for cleanup).
+ */
+ struct TransmitCallbackContext *prev;
+
/**
* The message that we're asked to transmit.
*/
struct GNUNET_MessageHeader *msg;
+
+ /**
+ * Handle for the transmission request.
+ */
+ struct GNUNET_CONNECTION_TransmitHandle *th;
/**
* Client that we are transmitting to.
int end;
};
+
+/**
+ * Head of the doubly-linked list (for cleanup).
+ */
+static struct TransmitCallbackContext *tcc_head;
+
+/**
+ * Tail of the doubly-linked list (for cleanup).
+ */
+static struct TransmitCallbackContext *tcc_tail;
+
/**
* Task that is used to remove expired entries from
struct TransmitCallbackContext *tcc = cls;
size_t msize;
+ tcc->th = NULL;
+ GNUNET_CONTAINER_DLL_remove (tcc_head,
+ tcc_tail,
+ tcc);
msize = ntohs(tcc->msg->size);
if (size == 0)
{
tcc->tc = tc;
tcc->tc_cls = tc_cls;
tcc->end = end;
-
if (NULL ==
- GNUNET_SERVER_notify_transmit_ready (client,
- ntohs(msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_callback,
- tcc))
+ (tcc->th = GNUNET_SERVER_notify_transmit_ready (client,
+ ntohs(msg->size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_callback,
+ tcc)))
{
GNUNET_break (0);
if (GNUNET_YES == end)
GNUNET_free (msg);
GNUNET_free (tcc);
}
+ GNUNET_CONTAINER_DLL_insert (tcc_head,
+ tcc_tail,
+ tcc);
}
}
+/**
+ * Function that removes all active reservations made
+ * by the given client and releases the space for other
+ * requests.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ */
+static void
+cleanup_transmits (void *cls,
+ struct GNUNET_SERVER_Client
+ * client)
+{
+ struct TransmitCallbackContext *tcc;
+
+ while (NULL != (tcc = tcc_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (tcc_head,
+ tcc_tail,
+ tcc);
+ if (tcc->th != NULL)
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (tcc->th);
+ GNUNET_free (tcc->msg);
+ GNUNET_free (tcc);
+ }
+
+}
+
+
+
/**
* Process datastore requests.
*
return;
}
GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL);
+ GNUNET_SERVER_disconnect_notify (server, &cleanup_transmits, NULL);
GNUNET_SERVER_add_handlers (server, handlers);
expired_kill_task
= GNUNET_SCHEDULER_add_with_priority (sched,