-
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
-/**
- * Callback called as a result of issuing a GNUNET_SERVER_notify_transmit_ready
- * request. A ClientList is passed as closure, take the head of the list
- * and copy it into buf, which has the result of sending the message to the
- * client.
- *
- * @param cls closure to this call
- * @param size maximum number of bytes available to send
- * @param buf where to copy the actual message to
- *
- * @return the number of bytes actually copied, 0 indicates failure
- */
-static size_t
-send_reply_to_client (void *cls, size_t size, void *buf)
-{
- struct ClientList *client = cls;
- char *cbuf = buf;
- struct PendingMessage *reply;
- size_t off;
- size_t msize;
-
- client->transmit_handle = NULL;
- if (buf == NULL)
- {
- /* client disconnected */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p disconnected, pending messages will be discarded\n",
- client->client_handle);
- return 0;
- }
- off = 0;
- while ((NULL != (reply = client->pending_head)) &&
- (size >= off + (msize = ntohs (reply->msg->size))))
- {
- GNUNET_CONTAINER_DLL_remove (client->pending_head, client->pending_tail,
- reply);
- GNUNET_memcpy (&cbuf[off], reply->msg, msize);
- GNUNET_free (reply);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting %u bytes to client %p\n",
- (unsigned int) msize,
- client->client_handle);
- off += msize;
- }
- process_pending_messages (client);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitted %u/%u bytes to client %p\n",
- (unsigned int) off,
- (unsigned int) size,
- client->client_handle);
- return off;
-}
-
-
-/**
- * Task run to check for messages that need to be sent to a client.
- *
- * @param client a ClientList, containing the client and any messages to be sent to it
- */
-static void
-process_pending_messages (struct ClientList *client)
-{
- if ((client->pending_head == NULL) || (client->transmit_handle != NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not asking for transmission to %p now: %s\n",
- client->client_handle,
- client->pending_head ==
- NULL ? "no more messages" : "request already pending");
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking for transmission of %u bytes to client %p\n",
- ntohs (client->pending_head->msg->size), client->client_handle);
- client->transmit_handle =
- GNUNET_SERVER_notify_transmit_ready (client->client_handle,
- ntohs (client->pending_head->
- msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_reply_to_client, client);