--- sio.c 2002/11/24 19:36:48 1.13
+++ sio.c 2002/11/28 16:29:37 1.14
@@ -487,12 +487,10 @@
sios->module->shutdown(sio, sios->userdata) == SIO_OK) {
if (sios->rw == SIO_MODE_WRITE || sios->rw == SIO_MODE_READWRITE) {
-printf("final output\n");
rc = sio_strategy(sio, HEAD(&sio->writers,hd));
if (rc != SIO_OK) return SIO_RC(rc);
}
if (sios->rw == SIO_MODE_READ || sios->rw == SIO_MODE_READWRITE) {
-printf("final input\n");
sio_strategy(sio, HEAD(&sio->readers,hd));
if (rc != SIO_OK) return SIO_RC(rc);
}
@@ -532,17 +530,21 @@
*
* if there is no data in the reader assembly line
* then schedule the input side of the pipe once
+ * if this still doesn't retrieve data then raise
+ * a SIO_ERR_EOF error.
*
* retrieve data from the reader assembly line up to
- * the specified byte limit
+ * the specified byte limit for the first span of
+ * the specified label or any data if label == NULL
*
*/
-sio_rc_t sio_input(sio_t *sio, al_t *al, size_t limit)
+sio_rc_t sio_input(sio_t *sio, al_t *al, size_t limit, al_label_t label)
{
sio_rc_t rc;
sio_halfduplex_t *h;
al_t *src;
size_t n;
+ size_t datastart, datasize;
/* argument sanity check(s) */
if (sio == NULL || al == NULL)
@@ -565,10 +567,22 @@
}
- if (n > limit)
- n = limit;
+ if (label == NULL) {
+ datastart = 0;
+ datasize = n;
+ } else if (al_spanlabel(src, 0, n, label, &datastart, &datasize) != AL_OK) {
+ datastart = 0;
+ datasize = 0;
+ }
+
+ /*
+ * clamp to requested size
+ */
+ if (datasize > n)
+ datasize = n;
- (void) al_splice(src, 0, n, NULL, al); /* XXX - error handling ? */
+ /* XXX - error handling ? */
+ (void) al_splice(src, datastart, datasize, NULL, al);
return SIO_OK;
}
@@ -688,7 +702,7 @@
arc = al_create(&al);
if (arc != AL_OK) return SIO_RC(SIO_ERR_INT);
- rc = sio_input(sio, al, n);
+ rc = sio_input(sio, al, n, NULL);
if (rc == SIO_OK) {
sio->dst = dst;
al_traverse_cb(al, 0, n, AL_FORWARD, NULL, sio_readchunk, (void*)sio);
|