* TRANSPORT:
- HTTP backend [MW]
* DV: [Nate]
- - write DV API (need to move declarations from dv_api.c to gnunet_dv_service.h!)
- - implement DV service
- - implement DV library (looks done)
- - implement DV transport plugin
- - implement testcases
- implement performance tests (needs tbench)
* UTIL:
- only connect() sockets that are ready (select()) [Nils]
* @param size number of bytes in buf
* @param purge should any excess bytes in the buffer be discarded
* (i.e. for packet-based services like UDP)
- * @return GNUNET_NO if the data stream is corrupt
- * GNUNET_SYSERR if the data stream is corrupt beyond repair
+ * @param one_shot only call callback once, keep rest of message in buffer
+ * @return GNUNET_OK if we are done processing (need more data)
+ * GNUNET_NO if one_shot was set and we have another message ready
+ * GNUNET_SYSERR if the data stream is corrupt
*/
int
GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
const char *buf,
size_t size,
- int purge);
+ int purge,
+ int one_shot);
+
+
+/**
+ * Read incoming data into the receive buffer and call the
+ * callback for all complete messages.
+ *
+ * @param mst tokenizer to use
+ * @param sock socket to read from (must be ready according to select)
+ * @param purge should any excess bytes in the buffer be discarded
+ * (i.e. for packet-based services like UDP)
+ * @return GNUNET_NO if the data stream is corrupt
+ * GNUNET_SYSERR if the data stream is corrupt beyond repair
+ */
+int
+GNUNET_SERVER_mst_read (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
+ const char *buf,
+ size_t size,
+ int purge);
+
/**
* Destroys a tokenizer.
* @param size number of bytes in buf
* @param purge should any excess bytes in the buffer be discarded
* (i.e. for packet-based services like UDP)
- * @return GNUNET_NO if the data stream is corrupt
- * GNUNET_SYSERR if the data stream is corrupt beyond repair
+ * @param one_shot only call callback once, keep rest of message in buffer
+ * @return GNUNET_OK if we are done processing (need more data)
+ * GNUNET_NO if one_shot was set and we have another message ready
+ * GNUNET_SYSERR if the data stream is corrupt
*/
int
GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
const char *buf,
size_t size,
- int purge)
+ int purge,
+ int one_shot)
{
const struct GNUNET_MessageHeader *hdr;
size_t delta;
char *ibuf;
int need_align;
unsigned long offset;
+ int ret;
+ ret = GNUNET_OK;
ibuf = (char*) &mst->hdr;
if (mst->off > 0)
{
if (want < sizeof (struct GNUNET_MessageHeader))
{
GNUNET_break_op (0);
- if (purge)
- return GNUNET_NO;
return GNUNET_SYSERR;
}
if (want < mst->off)
mst->off = 0;
return GNUNET_OK;
}
+ if (one_shot == GNUNET_SYSERR)
+ {
+ ret = GNUNET_NO;
+ goto copy;
+ }
+ if (one_shot == GNUNET_YES)
+ one_shot = GNUNET_SYSERR;
mst->cb (mst->cb_cls, mst->client_identity, &mst->hdr);
mst->off = 0;
}
want = ntohs (hdr->size);
if (size < want)
break; /* or not, buffer incomplete... */
+ if (one_shot == GNUNET_SYSERR)
+ {
+ ret = GNUNET_NO;
+ goto copy;
+ }
+ if (one_shot == GNUNET_YES)
+ one_shot = GNUNET_SYSERR;
mst->cb (mst->cb_cls, mst->client_identity, hdr);
buf += want;
size -= want;
goto do_align;
}
}
+ copy:
if ( (size > 0) && (! purge) )
{
- memcpy (&mst->hdr, buf, size);
- mst->off = size;
+ memcpy (&ibuf[mst->off], buf, size);
+ mst->off += size;
size = 0;
}
if (purge)
mst->off = 0;
- return GNUNET_OK;
+ return ret;
}