server_mst.c | server_mst.c | |||
---|---|---|---|---|
skipping to change at line 34 | skipping to change at line 34 | |||
* @author Christian Grothoff | * @author Christian Grothoff | |||
*/ | */ | |||
#include "platform.h" | #include "platform.h" | |||
#include "gnunet_common.h" | #include "gnunet_common.h" | |||
#include "gnunet_connection_lib.h" | #include "gnunet_connection_lib.h" | |||
#include "gnunet_scheduler_lib.h" | #include "gnunet_scheduler_lib.h" | |||
#include "gnunet_server_lib.h" | #include "gnunet_server_lib.h" | |||
#include "gnunet_time_lib.h" | #include "gnunet_time_lib.h" | |||
#define DEBUG_SERVER_MST GNUNET_EXTRA_LOGGING | ||||
#if HAVE_UNALIGNED_64_ACCESS | #if HAVE_UNALIGNED_64_ACCESS | |||
#define ALIGN_FACTOR 4 | #define ALIGN_FACTOR 4 | |||
#else | #else | |||
#define ALIGN_FACTOR 8 | #define ALIGN_FACTOR 8 | |||
#endif | #endif | |||
#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | |||
/** | /** | |||
* Handle to a message stream tokenizer. | * Handle to a message stream tokenizer. | |||
skipping to change at line 133 | skipping to change at line 131 | |||
const struct GNUNET_MessageHeader *hdr; | const struct GNUNET_MessageHeader *hdr; | |||
size_t delta; | size_t delta; | |||
uint16_t want; | uint16_t want; | |||
char *ibuf; | char *ibuf; | |||
int need_align; | int need_align; | |||
unsigned long offset; | unsigned long offset; | |||
int ret; | int ret; | |||
GNUNET_assert (mst->off <= mst->pos); | GNUNET_assert (mst->off <= mst->pos); | |||
GNUNET_assert (mst->pos <= mst->curr_buf); | GNUNET_assert (mst->pos <= mst->curr_buf); | |||
#if DEBUG_SERVER_MST | ||||
LOG (GNUNET_ERROR_TYPE_DEBUG, | LOG (GNUNET_ERROR_TYPE_DEBUG, | |||
"Server-mst receives %u bytes with %u bytes already in private buffe r\n", | "Server-mst receives %u bytes with %u bytes already in private buffe r\n", | |||
(unsigned int) size, (unsigned int) (mst->pos - mst->off)); | (unsigned int) size, (unsigned int) (mst->pos - mst->off)); | |||
#endif | ||||
ret = GNUNET_OK; | ret = GNUNET_OK; | |||
ibuf = (char *) mst->hdr; | ibuf = (char *) mst->hdr; | |||
while (mst->pos > 0) | while (mst->pos > 0) | |||
{ | { | |||
do_align: | do_align: | |||
GNUNET_assert (mst->pos >= mst->off); | GNUNET_assert (mst->pos >= mst->off); | |||
if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) | | | if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) | | | |||
(0 != (mst->off % ALIGN_FACTOR))) | (0 != (mst->off % ALIGN_FACTOR))) | |||
{ | { | |||
/* need to align or need more space */ | /* need to align or need more space */ | |||
skipping to change at line 223 | skipping to change at line 219 | |||
if (one_shot == GNUNET_SYSERR) | if (one_shot == GNUNET_SYSERR) | |||
{ | { | |||
/* cannot call callback again, but return value saying that | /* cannot call callback again, but return value saying that | |||
* we have another full message in the buffer */ | * we have another full message in the buffer */ | |||
ret = GNUNET_NO; | ret = GNUNET_NO; | |||
goto copy; | goto copy; | |||
} | } | |||
if (one_shot == GNUNET_YES) | if (one_shot == GNUNET_YES) | |||
one_shot = GNUNET_SYSERR; | one_shot = GNUNET_SYSERR; | |||
mst->off += want; | mst->off += want; | |||
mst->cb (mst->cb_cls, client_identity, hdr); | if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr)) | |||
return GNUNET_SYSERR; | ||||
if (mst->off == mst->pos) | if (mst->off == mst->pos) | |||
{ | { | |||
/* reset to beginning of buffer, it's free right now! */ | /* reset to beginning of buffer, it's free right now! */ | |||
mst->off = 0; | mst->off = 0; | |||
mst->pos = 0; | mst->pos = 0; | |||
} | } | |||
} | } | |||
GNUNET_assert (0 == mst->pos); | GNUNET_assert (0 == mst->pos); | |||
while (size > 0) | while (size > 0) | |||
{ | { | |||
#if DEBUG_SERVER_MST | ||||
LOG (GNUNET_ERROR_TYPE_DEBUG, | LOG (GNUNET_ERROR_TYPE_DEBUG, | |||
"Server-mst has %u bytes left in inbound buffer\n", | "Server-mst has %u bytes left in inbound buffer\n", | |||
(unsigned int) size); | (unsigned int) size); | |||
#endif | ||||
if (size < sizeof (struct GNUNET_MessageHeader)) | if (size < sizeof (struct GNUNET_MessageHeader)) | |||
break; | break; | |||
offset = (unsigned long) buf; | offset = (unsigned long) buf; | |||
need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO; | need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO; | |||
if (GNUNET_NO == need_align) | if (GNUNET_NO == need_align) | |||
{ | { | |||
/* can try to do zero-copy and process directly from original buffer */ | /* can try to do zero-copy and process directly from original buffer */ | |||
hdr = (const struct GNUNET_MessageHeader *) buf; | hdr = (const struct GNUNET_MessageHeader *) buf; | |||
want = ntohs (hdr->size); | want = ntohs (hdr->size); | |||
if (want < sizeof (struct GNUNET_MessageHeader)) | if (want < sizeof (struct GNUNET_MessageHeader)) | |||
skipping to change at line 265 | skipping to change at line 260 | |||
break; /* or not: buffer incomplete, so copy to pr ivate buffer... */ | break; /* or not: buffer incomplete, so copy to pr ivate buffer... */ | |||
if (one_shot == GNUNET_SYSERR) | if (one_shot == GNUNET_SYSERR) | |||
{ | { | |||
/* cannot call callback again, but return value saying that | /* cannot call callback again, but return value saying that | |||
* we have another full message in the buffer */ | * we have another full message in the buffer */ | |||
ret = GNUNET_NO; | ret = GNUNET_NO; | |||
goto copy; | goto copy; | |||
} | } | |||
if (one_shot == GNUNET_YES) | if (one_shot == GNUNET_YES) | |||
one_shot = GNUNET_SYSERR; | one_shot = GNUNET_SYSERR; | |||
mst->cb (mst->cb_cls, client_identity, hdr); | if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr)) | |||
return GNUNET_SYSERR; | ||||
buf += want; | buf += want; | |||
size -= want; | size -= want; | |||
} | } | |||
else | else | |||
{ | { | |||
/* need to copy to private buffer to align; | /* need to copy to private buffer to align; | |||
* yes, we go a bit more spagetti than usual here */ | * yes, we go a bit more spagetti than usual here */ | |||
goto do_align; | goto do_align; | |||
} | } | |||
} | } | |||
skipping to change at line 294 | skipping to change at line 290 | |||
} | } | |||
GNUNET_assert (size + mst->pos <= mst->curr_buf); | GNUNET_assert (size + mst->pos <= mst->curr_buf); | |||
memcpy (&ibuf[mst->pos], buf, size); | memcpy (&ibuf[mst->pos], buf, size); | |||
mst->pos += size; | mst->pos += size; | |||
} | } | |||
if (purge) | if (purge) | |||
{ | { | |||
mst->off = 0; | mst->off = 0; | |||
mst->pos = 0; | mst->pos = 0; | |||
} | } | |||
#if DEBUG_SERVER_MST | ||||
LOG (GNUNET_ERROR_TYPE_DEBUG, | LOG (GNUNET_ERROR_TYPE_DEBUG, | |||
"Server-mst leaves %u bytes in private buffer\n", | "Server-mst leaves %u bytes in private buffer\n", | |||
(unsigned int) (mst->pos - mst->off)); | (unsigned int) (mst->pos - mst->off)); | |||
#endif | ||||
return ret; | return ret; | |||
} | } | |||
/** | /** | |||
* Destroys a tokenizer. | * Destroys a tokenizer. | |||
* | * | |||
* @param mst tokenizer to destroy | * @param mst tokenizer to destroy | |||
*/ | */ | |||
void | void | |||
GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst ) | GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst ) | |||
End of changes. 9 change blocks. | ||||
10 lines changed or deleted | 4 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |