-/**
- * 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_SERVER_TransmitHandle *th;
-
-};
-
-
-/**
- * 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;
-
-/**
- * Have we already cleaned up the TCCs and are hence no longer
- * willing (or able) to transmit anything to anyone?
- */
-static int cleaning_done;
-
-
-/**
- * Function called to notify a client about the socket
- * being ready to queue more data. "buf" will be
- * NULL and "size" zero if the socket was closed for
- * writing in the meantime.
- *
- * @param cls closure
- * @param size number of bytes available in buf
- * @param buf where the callee should write the message
- * @return number of bytes written to buf
- */
-static size_t
-transmit_callback (void *cls, size_t size, void *buf)
-{
- 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)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Transmission to client failed!\n"));
- GNUNET_free (tcc->msg);
- GNUNET_free (tcc);
- return 0;
- }
- GNUNET_assert (size >= msize);
- memcpy (buf, tcc->msg, msize);
- GNUNET_free (tcc->msg);
- GNUNET_free (tcc);
- return msize;
-}
-
-
-/**
- * Transmit the given message to the client.
- *
- * @param client target of the message
- * @param msg message to transmit, will be freed!
- */
-static void
-transmit (struct GNUNET_SERVER_Client *client,
- struct GNUNET_MessageHeader *msg)
-{
- struct TransmitCallbackContext *tcc;
-
- if (GNUNET_YES == cleaning_done)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Shutdown in progress, aborting transmission.\n"));
- GNUNET_free (msg);
- return;
- }
- tcc = GNUNET_malloc (sizeof (struct TransmitCallbackContext));
- tcc->msg = msg;
- if (NULL ==
- (tcc->th =
- GNUNET_SERVER_notify_transmit_ready (client,
- ntohs (msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_callback, tcc)))
- {
- GNUNET_break (0);
- GNUNET_free (msg);
- GNUNET_free (tcc);
- return;
- }
- GNUNET_CONTAINER_DLL_insert (tcc_head, tcc_tail, tcc);
-}
-