diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-10-28 23:14:38 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-10-28 23:14:45 +0200 |
commit | a98fecfbfa095ceee45b963c07480ed9331c48e2 (patch) | |
tree | 7a4d427ccb99ed3dcab33be7e7883c16e39dcef1 /src/util | |
parent | 4e2259f14be320c8e2fe2a672a473e09677269c4 (diff) | |
download | gnunet-a98fecfbfa095ceee45b963c07480ed9331c48e2.tar.gz gnunet-a98fecfbfa095ceee45b963c07480ed9331c48e2.zip |
-code cleanup plus one new assertion to debug madmurphy issue
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/client.c | 7 | ||||
-rw-r--r-- | src/util/mq.c | 1 | ||||
-rw-r--r-- | src/util/mst.c | 21 |
3 files changed, 15 insertions, 14 deletions
diff --git a/src/util/client.c b/src/util/client.c index 686e0562a..91e0c1a85 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -267,7 +267,7 @@ transmit_ready (void *cls) | |||
267 | cstate->sock, | 267 | cstate->sock, |
268 | cstate->mq); | 268 | cstate->mq); |
269 | 269 | ||
270 | RETRY: | 270 | RETRY: |
271 | ret = GNUNET_NETWORK_socket_send (cstate->sock, | 271 | ret = GNUNET_NETWORK_socket_send (cstate->sock, |
272 | &pos[cstate->msg_off], | 272 | &pos[cstate->msg_off], |
273 | len - cstate->msg_off); | 273 | len - cstate->msg_off); |
@@ -330,7 +330,7 @@ transmit_ready (void *cls) | |||
330 | * #GNUNET_NO to stop further processing due to disconnect (no error) | 330 | * #GNUNET_NO to stop further processing due to disconnect (no error) |
331 | * #GNUNET_SYSERR to stop further processing due to error | 331 | * #GNUNET_SYSERR to stop further processing due to error |
332 | */ | 332 | */ |
333 | static int | 333 | static enum GNUNET_GenericReturnValue |
334 | recv_message (void *cls, | 334 | recv_message (void *cls, |
335 | const struct GNUNET_MessageHeader *msg) | 335 | const struct GNUNET_MessageHeader *msg) |
336 | { | 336 | { |
@@ -439,7 +439,7 @@ static void | |||
439 | receive_ready (void *cls) | 439 | receive_ready (void *cls) |
440 | { | 440 | { |
441 | struct ClientState *cstate = cls; | 441 | struct ClientState *cstate = cls; |
442 | int ret; | 442 | enum GNUNET_GenericReturnValue ret; |
443 | 443 | ||
444 | cstate->recv_task = NULL; | 444 | cstate->recv_task = NULL; |
445 | cstate->in_destroy = GNUNET_SYSERR; | 445 | cstate->in_destroy = GNUNET_SYSERR; |
@@ -464,6 +464,7 @@ receive_ready (void *cls) | |||
464 | return; | 464 | return; |
465 | } | 465 | } |
466 | cstate->in_destroy = GNUNET_NO; | 466 | cstate->in_destroy = GNUNET_NO; |
467 | GNUNET_assert (NULL == cstate->recv_task); | ||
467 | cstate->recv_task | 468 | cstate->recv_task |
468 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 469 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
469 | cstate->sock, | 470 | cstate->sock, |
diff --git a/src/util/mq.c b/src/util/mq.c index 8749d5d21..585389ce8 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -192,6 +192,7 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, | |||
192 | mh); | 192 | mh); |
193 | if (GNUNET_SYSERR == ret) | 193 | if (GNUNET_SYSERR == ret) |
194 | { | 194 | { |
195 | GNUNET_break_op (0); | ||
195 | GNUNET_MQ_inject_error (mq, | 196 | GNUNET_MQ_inject_error (mq, |
196 | GNUNET_MQ_ERROR_MALFORMED); | 197 | GNUNET_MQ_ERROR_MALFORMED); |
197 | return; | 198 | return; |
diff --git a/src/util/mst.c b/src/util/mst.c index 264fdb979..18f144906 100644 --- a/src/util/mst.c +++ b/src/util/mst.c | |||
@@ -96,7 +96,7 @@ GNUNET_MST_create (GNUNET_MessageTokenizerCallback cb, | |||
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | int | 99 | enum GNUNET_GenericReturnValue |
100 | GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst, | 100 | GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst, |
101 | const char *buf, | 101 | const char *buf, |
102 | size_t size, | 102 | size_t size, |
@@ -107,8 +107,6 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst, | |||
107 | size_t delta; | 107 | size_t delta; |
108 | uint16_t want; | 108 | uint16_t want; |
109 | char *ibuf; | 109 | char *ibuf; |
110 | int need_align; | ||
111 | unsigned long offset; | ||
112 | int ret; | 110 | int ret; |
113 | int cbret; | 111 | int cbret; |
114 | 112 | ||
@@ -124,7 +122,7 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst, | |||
124 | ibuf = (char *) mst->hdr; | 122 | ibuf = (char *) mst->hdr; |
125 | while (mst->pos > 0) | 123 | while (mst->pos > 0) |
126 | { | 124 | { |
127 | do_align: | 125 | do_align: |
128 | GNUNET_assert (mst->pos >= mst->off); | 126 | GNUNET_assert (mst->pos >= mst->off); |
129 | if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) || | 127 | if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) || |
130 | (0 != (mst->off % ALIGN_FACTOR))) | 128 | (0 != (mst->off % ALIGN_FACTOR))) |
@@ -240,14 +238,15 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst, | |||
240 | GNUNET_assert (0 == mst->pos); | 238 | GNUNET_assert (0 == mst->pos); |
241 | while (size > 0) | 239 | while (size > 0) |
242 | { | 240 | { |
241 | unsigned long offset = (unsigned long) buf; | ||
242 | bool need_align = (0 != (offset % ALIGN_FACTOR)); | ||
243 | |||
243 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 244 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
244 | "Server-mst has %u bytes left in inbound buffer\n", | 245 | "Server-mst has %u bytes left in inbound buffer\n", |
245 | (unsigned int) size); | 246 | (unsigned int) size); |
246 | if (size < sizeof(struct GNUNET_MessageHeader)) | 247 | if (size < sizeof(struct GNUNET_MessageHeader)) |
247 | break; | 248 | break; |
248 | offset = (unsigned long) buf; | 249 | if (! need_align) |
249 | need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO; | ||
250 | if (GNUNET_NO == need_align) | ||
251 | { | 250 | { |
252 | /* can try to do zero-copy and process directly from original buffer */ | 251 | /* can try to do zero-copy and process directly from original buffer */ |
253 | hdr = (const struct GNUNET_MessageHeader *) buf; | 252 | hdr = (const struct GNUNET_MessageHeader *) buf; |
@@ -267,7 +266,7 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst, | |||
267 | ret = GNUNET_NO; | 266 | ret = GNUNET_NO; |
268 | goto copy; | 267 | goto copy; |
269 | } | 268 | } |
270 | if (one_shot == GNUNET_YES) | 269 | if (GNUNET_YES == one_shot) |
271 | one_shot = GNUNET_SYSERR; | 270 | one_shot = GNUNET_SYSERR; |
272 | if (GNUNET_OK != | 271 | if (GNUNET_OK != |
273 | (cbret = mst->cb (mst->cb_cls, | 272 | (cbret = mst->cb (mst->cb_cls, |
@@ -290,7 +289,7 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst, | |||
290 | goto do_align; | 289 | goto do_align; |
291 | } | 290 | } |
292 | } | 291 | } |
293 | copy: | 292 | copy: |
294 | if ((size > 0) && (! purge)) | 293 | if ((size > 0) && (! purge)) |
295 | { | 294 | { |
296 | if (size + mst->pos > mst->curr_buf) | 295 | if (size + mst->pos > mst->curr_buf) |
@@ -334,7 +333,7 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst, | |||
334 | * #GNUNET_NO if one_shot was set and we have another message ready | 333 | * #GNUNET_NO if one_shot was set and we have another message ready |
335 | * #GNUNET_SYSERR if the data stream is corrupt | 334 | * #GNUNET_SYSERR if the data stream is corrupt |
336 | */ | 335 | */ |
337 | int | 336 | enum GNUNET_GenericReturnValue |
338 | GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst, | 337 | GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst, |
339 | struct GNUNET_NETWORK_Handle *sock, | 338 | struct GNUNET_NETWORK_Handle *sock, |
340 | int purge, | 339 | int purge, |
@@ -383,7 +382,7 @@ GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst, | |||
383 | * #GNUNET_NO if one_shot was set and we have another message ready | 382 | * #GNUNET_NO if one_shot was set and we have another message ready |
384 | * #GNUNET_SYSERR if the data stream is corrupt | 383 | * #GNUNET_SYSERR if the data stream is corrupt |
385 | */ | 384 | */ |
386 | int | 385 | enum GNUNET_GenericReturnValue |
387 | GNUNET_MST_next (struct GNUNET_MessageStreamTokenizer *mst, | 386 | GNUNET_MST_next (struct GNUNET_MessageStreamTokenizer *mst, |
388 | int one_shot) | 387 | int one_shot) |
389 | { | 388 | { |