aboutsummaryrefslogtreecommitdiff
path: root/src/util/server_tc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/server_tc.c')
-rw-r--r--src/util/server_tc.c79
1 files changed, 41 insertions, 38 deletions
diff --git a/src/util/server_tc.c b/src/util/server_tc.c
index 5e9a9e946..020fd86db 100644
--- a/src/util/server_tc.c
+++ b/src/util/server_tc.c
@@ -33,6 +33,8 @@
33#include "gnunet_time_lib.h" 33#include "gnunet_time_lib.h"
34 34
35 35
36#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
37
36 38
37/** 39/**
38 * How much buffer space do we want to have at least 40 * How much buffer space do we want to have at least
@@ -81,10 +83,10 @@ transmit_response (void *cls, size_t size, void *buf)
81 size_t msize; 83 size_t msize;
82 84
83 if (buf == NULL) 85 if (buf == NULL)
84 { 86 {
85 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); 87 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
86 return 0; 88 return 0;
87 } 89 }
88 if (tc->total - tc->off > size) 90 if (tc->total - tc->off > size)
89 msize = size; 91 msize = size;
90 else 92 else
@@ -92,27 +94,28 @@ transmit_response (void *cls, size_t size, void *buf)
92 memcpy (buf, &tc->buf[tc->off], msize); 94 memcpy (buf, &tc->buf[tc->off], msize);
93 tc->off += msize; 95 tc->off += msize;
94 if (tc->total == tc->off) 96 if (tc->total == tc->off)
95 { 97 {
96 98
97 GNUNET_SERVER_receive_done (tc->client, GNUNET_OK); 99 GNUNET_SERVER_receive_done (tc->client, GNUNET_OK);
98 GNUNET_SERVER_client_drop (tc->client); 100 GNUNET_SERVER_client_drop (tc->client);
99 GNUNET_free_non_null (tc->buf); 101 GNUNET_free_non_null (tc->buf);
100 GNUNET_free (tc); 102 GNUNET_free (tc);
101 } 103 }
102 else 104 else
103 {
104 if (NULL ==
105 GNUNET_SERVER_notify_transmit_ready (tc->client,
106 GNUNET_MIN (MIN_BLOCK_SIZE,
107 tc->total - tc->off),
108 GNUNET_TIME_absolute_get_remaining
109 (tc->timeout), &transmit_response,
110 tc))
111 { 105 {
112 GNUNET_break (0); 106 if (NULL ==
113 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); 107 GNUNET_SERVER_notify_transmit_ready (tc->client,
108 GNUNET_MIN (MIN_BLOCK_SIZE,
109 tc->total -
110 tc->off),
111 GNUNET_TIME_absolute_get_remaining
112 (tc->timeout),
113 &transmit_response, tc))
114 {
115 GNUNET_break (0);
116 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
117 }
114 } 118 }
115 }
116 return msize; 119 return msize;
117} 120}
118 121
@@ -148,9 +151,10 @@ GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client)
148 * @param type type of the message 151 * @param type type of the message
149 */ 152 */
150void 153void
151GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext 154GNUNET_SERVER_transmit_context_append_data (struct
152 *tc, const void *data, 155 GNUNET_SERVER_TransmitContext *tc,
153 size_t length, uint16_t type) 156 const void *data, size_t length,
157 uint16_t type)
154{ 158{
155 struct GNUNET_MessageHeader *msg; 159 struct GNUNET_MessageHeader *msg;
156 size_t size; 160 size_t size;
@@ -177,10 +181,10 @@ GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext
177 */ 181 */
178void 182void
179GNUNET_SERVER_transmit_context_append_message (struct 183GNUNET_SERVER_transmit_context_append_message (struct
180 GNUNET_SERVER_TransmitContext 184 GNUNET_SERVER_TransmitContext
181 *tc, 185 *tc,
182 const struct GNUNET_MessageHeader 186 const struct
183 *msg) 187 GNUNET_MessageHeader *msg)
184{ 188{
185 struct GNUNET_MessageHeader *m; 189 struct GNUNET_MessageHeader *m;
186 uint16_t size; 190 uint16_t size;
@@ -204,18 +208,18 @@ GNUNET_SERVER_transmit_context_append_message (struct
204 */ 208 */
205void 209void
206GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, 210GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc,
207 struct GNUNET_TIME_Relative timeout) 211 struct GNUNET_TIME_Relative timeout)
208{ 212{
209 tc->timeout = GNUNET_TIME_relative_to_absolute (timeout); 213 tc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
210 if (NULL == 214 if (NULL ==
211 GNUNET_SERVER_notify_transmit_ready (tc->client, 215 GNUNET_SERVER_notify_transmit_ready (tc->client,
212 GNUNET_MIN (MIN_BLOCK_SIZE, 216 GNUNET_MIN (MIN_BLOCK_SIZE,
213 tc->total), timeout, 217 tc->total), timeout,
214 &transmit_response, tc)) 218 &transmit_response, tc))
215 { 219 {
216 GNUNET_break (0); 220 GNUNET_break (0);
217 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); 221 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
218 } 222 }
219} 223}
220 224
221 225
@@ -233,8 +237,7 @@ GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc,
233 */ 237 */
234void 238void
235GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext 239GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext
236 *tc, 240 *tc, int success)
237 int success)
238{ 241{
239 GNUNET_SERVER_receive_done (tc->client, success); 242 GNUNET_SERVER_receive_done (tc->client, success);
240 GNUNET_SERVER_client_drop (tc->client); 243 GNUNET_SERVER_client_drop (tc->client);