server_mst.c   server_mst.c 
skipping to change at line 131 skipping to change at line 131
int purge, int one_shot) int purge, int one_shot)
{ {
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->pos <= mst->curr_buf);
#if DEBUG_SERVER_MST #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 #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);
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 */
mst->pos -= mst->off; mst->pos -= mst->off;
memmove (ibuf, &ibuf[mst->off], mst->pos); memmove (ibuf, &ibuf[mst->off], mst->pos);
mst->off = 0; mst->off = 0;
} }
if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
{ {
skipping to change at line 175 skipping to change at line 178
} }
return GNUNET_OK; return GNUNET_OK;
} }
hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
want = ntohs (hdr->size); want = ntohs (hdr->size);
if (want < sizeof (struct GNUNET_MessageHeader)) if (want < sizeof (struct GNUNET_MessageHeader))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (mst->curr_buf - mst->off < want) if ( (mst->curr_buf - mst->off < want) &&
(mst->off > 0) )
{ {
/* need more space */ /* can get more space by moving */
mst->pos -= mst->off; mst->pos -= mst->off;
memmove (ibuf, &ibuf[mst->off], mst->pos); memmove (ibuf, &ibuf[mst->off], mst->pos);
mst->off = 0; mst->off = 0;
} }
if (want > mst->curr_buf) if (mst->curr_buf < want)
{ {
/* need to get more space by growing buffer */
GNUNET_assert (0 == mst->off);
mst->hdr = GNUNET_realloc (mst->hdr, want); mst->hdr = GNUNET_realloc (mst->hdr, want);
ibuf = (char *) mst->hdr; ibuf = (char *) mst->hdr;
mst->curr_buf = want; mst->curr_buf = want;
} }
hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
if (mst->pos - mst->off < want) if (mst->pos - mst->off < want)
{ {
delta = GNUNET_MIN (want - (mst->pos - mst->off), size); delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
GNUNET_assert (mst->pos + delta <= mst->curr_buf);
memcpy (&ibuf[mst->pos], buf, delta); memcpy (&ibuf[mst->pos], buf, delta);
mst->pos += delta; mst->pos += delta;
buf += delta; buf += delta;
size -= delta; size -= delta;
} }
if (mst->pos - mst->off < want) if (mst->pos - mst->off < want)
{ {
if (purge) if (purge)
{ {
mst->off = 0; mst->off = 0;
skipping to change at line 215 skipping to change at line 222
} }
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);
mst->off += want; mst->off += want;
mst->cb (mst->cb_cls, client_identity, hdr);
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);
while (size > 0) while (size > 0)
{ {
#if DEBUG_SERVER_MST #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 #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))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
mst->off = 0; mst->off = 0;
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (size < want) if (size < want)
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); mst->cb (mst->cb_cls, client_identity, hdr);
skipping to change at line 277 skipping to change at line 285
} }
copy: copy:
if ((size > 0) && (!purge)) if ((size > 0) && (!purge))
{ {
if (size + mst->pos > mst->curr_buf) if (size + mst->pos > mst->curr_buf)
{ {
mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos); mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos);
ibuf = (char *) mst->hdr; ibuf = (char *) mst->hdr;
mst->curr_buf = size + mst->pos; mst->curr_buf = size + mst->pos;
} }
GNUNET_assert (mst->pos + size <= 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;
}
#if DEBUG_SERVER_MST #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 #endif
return ret; return ret;
} }
/** /**
* Destroys a tokenizer. * Destroys a tokenizer.
 End of changes. 15 change blocks. 
7 lines changed or deleted 18 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/