/** * Helper function for incremental transmission of the response. */ static size_t transmit_response (void *cls, size_t size, void *buf) { struct GNUNET_SERVER_TransmitContext *tc = cls; size_t msize; if (NULL == buf) { GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); return 0; } if (tc->total - tc->off > size) msize = size; else msize = tc->total - tc->off; memcpy (buf, &tc->buf[tc->off], msize); tc->off += msize; if (tc->total == tc->off) { GNUNET_SERVER_receive_done (tc->client, GNUNET_OK); GNUNET_SERVER_client_drop (tc->client); GNUNET_free_non_null (tc->buf); GNUNET_free (tc); } else { if (NULL == GNUNET_SERVER_notify_transmit_ready (tc->client, GNUNET_MIN (MIN_BLOCK_SIZE, tc->total - tc->off), GNUNET_TIME_absolute_get_remaining (tc->timeout), &transmit_response, tc)) { GNUNET_break (0); GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); } } return msize; }
/** * Execute a transmission context. If there is * an error in the transmission, the #GNUNET_SERVER_receive_done() * method will be called with an error code (#GNUNET_SYSERR), * otherwise with #GNUNET_OK. * * @param tc transmission context to use * @param timeout when to time out and abort the transmission */ void GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, struct GNUNET_TIME_Relative timeout) { tc->timeout = GNUNET_TIME_relative_to_absolute (timeout); if (NULL == GNUNET_SERVER_notify_transmit_ready (tc->client, GNUNET_MIN (MIN_BLOCK_SIZE, tc->total), timeout, &transmit_response, tc)) { GNUNET_break (0); GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); } }
/** * Stop processing clients. */ void GST_clients_stop () { struct AddressToStringContext *cur; while (NULL != (cur = a2s_head)) { GNUNET_SERVER_transmit_context_destroy (cur->tc, GNUNET_NO); GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur); GNUNET_free (cur); } if (NULL != peer_nc) { GNUNET_SERVER_notification_context_destroy (peer_nc); peer_nc = NULL; } if (NULL != val_nc) { GNUNET_SERVER_notification_context_destroy (val_nc); val_nc = NULL; } }