X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fserver_tc.c;h=b7158dadbd345266bfd6ed9e2e07895ed48f6205;hb=8dfd7bda2f139e2dac27e804167eedc3d227453e;hp=bffb892b17299afd9a70d888fb426a6d830feaab;hpb=2518cfc0a86865ebe4d0550e0013ed52a494231b;p=oweals%2Fgnunet.git diff --git a/src/util/server_tc.c b/src/util/server_tc.c index bffb892b1..b7158dadb 100644 --- a/src/util/server_tc.c +++ b/src/util/server_tc.c @@ -82,6 +82,7 @@ transmit_response (void *cls, size_t size, void *buf) if (buf == NULL) { GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR); + GNUNET_SERVER_client_drop (tc->client); GNUNET_free_non_null (tc->buf); GNUNET_free (tc); return 0; @@ -95,6 +96,7 @@ transmit_response (void *cls, size_t size, void *buf) 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); } @@ -111,6 +113,7 @@ transmit_response (void *cls, size_t size, void *buf) { GNUNET_break (0); GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR); + GNUNET_SERVER_client_drop (tc->client); GNUNET_free_non_null (tc->buf); GNUNET_free (tc); } @@ -133,6 +136,7 @@ GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client) GNUNET_assert (client != NULL); tc = GNUNET_malloc (sizeof (struct GNUNET_SERVER_TransmitContext)); + GNUNET_SERVER_client_keep (client); tc->client = client; return tc; } @@ -149,9 +153,9 @@ GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client) * @param type type of the message */ void -GNUNET_SERVER_transmit_context_append (struct GNUNET_SERVER_TransmitContext - *tc, const void *data, size_t length, - uint16_t type) +GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext + *tc, const void *data, size_t length, + uint16_t type) { struct GNUNET_MessageHeader *msg; size_t size; @@ -168,6 +172,29 @@ GNUNET_SERVER_transmit_context_append (struct GNUNET_SERVER_TransmitContext } +/** + * Append a message to the transmission context. + * All messages in the context will be sent by + * the transmit_context_run method. + * + * @param tc context to use + * @param msg message to append + */ +void +GNUNET_SERVER_transmit_context_append_message(struct GNUNET_SERVER_TransmitContext + *tc, const struct GNUNET_MessageHeader *msg) +{ + struct GNUNET_MessageHeader *m; + uint16_t size; + + size = ntohs (msg->size); + tc->buf = GNUNET_realloc (tc->buf, tc->total + size); + m = (struct GNUNET_MessageHeader *) &tc->buf[tc->total]; + tc->total += size; + memcpy (m, msg, size); +} + + /** * Execute a transmission context. If there is * an error in the transmission, the receive_done @@ -190,6 +217,7 @@ GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, { GNUNET_break (0); GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR); + GNUNET_SERVER_client_drop (tc->client); GNUNET_free_non_null (tc->buf); GNUNET_free (tc); }