head 1.10;
access;
symbols
SIO_0_9_3:1.10
SIO_0_9_2:1.9
SIO_0_9_1:1.9
SIO_0_9_0:1.9;
locks; strict;
comment @ * @;
1.10
date 2005.10.03.09.06.11; author rse; state Exp;
branches;
next 1.9;
1.9
date 2003.01.06.19.04.56; author rse; state Exp;
branches;
next 1.8;
1.8
date 2002.11.29.13.00.18; author mlelstv; state Exp;
branches;
next 1.7;
1.7
date 2002.11.27.15.50.29; author mlelstv; state Exp;
branches;
next 1.6;
1.6
date 2002.11.27.10.42.36; author mlelstv; state Exp;
branches;
next 1.5;
1.5
date 2002.11.24.19.36.48; author mlelstv; state Exp;
branches;
next 1.4;
1.4
date 2002.11.14.15.56.10; author mlelstv; state Exp;
branches;
next 1.3;
1.3
date 2002.11.05.17.30.38; author mlelstv; state Exp;
branches;
next 1.2;
1.2
date 2002.11.05.15.52.21; author mlelstv; state Exp;
branches;
next 1.1;
1.1
date 2002.10.23.17.05.10; author mlelstv; state Exp;
branches;
next ;
desc
@@
1.10
log
@adjust copyright messages
@
text
@/*
** OSSP sio - Stream I/O
** Copyright (c) 2002-2005 Cable & Wireless
** Copyright (c) 2002-2005 The OSSP Project
** Copyright (c) 2002-2005 Ralf S. Engelschall
**
** This file is part of OSSP sio, a layered stream I/O library
** which can be found at http://www.ossp.org/pkg/lib/sio/.
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** sio_buffer.c: buffer stage
*/
#include
#include
#include
#include "al.h"
#include "sio.h"
typedef struct {
size_t outputsize;
size_t inputsize;
al_t *input, *output;
al_label_t data_label;
} private_t;
/*
* create stage
*
* allocate private instance data
*/
static
sio_rc_t buffer_init(sio_t *sio, void **up)
{
private_t *my;
my = (private_t *)malloc(sizeof(private_t));
if (my == NULL)
return SIO_ERR_MEM;
my->inputsize = 0;
my->outputsize = 0;
sio_label(sio, SIO_LN_DATA, &my->data_label);
*up = my;
return SIO_OK;
}
/*
* configure stage
*
* pass two void pointers
*/
static
sio_rc_t buffer_configure(sio_t *sio, void *u, void *obj, void *val)
{
private_t *my = (private_t *)u;
const char *name = (const char *)obj;
if (!strcmp(name, "inputsize")) {
my->inputsize = *(size_t *)val;
} else if (!strcmp(name, "outputsize")) {
my->outputsize = *(size_t *)val;
} else {
return SIO_ERR_ARG;
}
return SIO_OK;
}
/*
* destroy stage
*/
static
sio_rc_t buffer_cleanup(sio_t *sio, void *u)
{
private_t *my = (private_t *)u;
free(my);
return SIO_OK;
}
static
sio_rc_t buffer_openr(sio_t *sio, al_t *al, void *u)
{
private_t *my = (private_t *)u;
al_rc_t arc;
arc = al_create(&my->input);
if (arc != AL_OK)
return SIO_ERR_INT;
return SIO_OK;
}
static
sio_rc_t buffer_closer(sio_t *sio, al_t *al, void *u)
{
private_t *my = (private_t *)u;
al_destroy(my->input);
my->input = NULL;
return SIO_OK;
}
static
sio_rc_t buffer_openw(sio_t *sio, al_t *al, void *u)
{
private_t *my = (private_t *)u;
al_rc_t arc;
arc = al_create(&my->output);
if (arc != AL_OK)
return SIO_ERR_INT;
return SIO_OK;
}
static
sio_rc_t buffer_closew(sio_t *sio, al_t *al, void *u)
{
private_t *my = (private_t *)u;
al_destroy(my->output);
my->output = NULL;
return SIO_OK;
}
/*
* buffer logic
*
* gather data from producer
* if buffer size reached or label changes then push data to consumer
* (read -> downstream, write -> upstream)
*
* buffer size depends on label type
*
*/
static
sio_rc_t buffer_inout(sio_t *sio, al_t *al, private_t *my,
al_t *buf, size_t size)
{
size_t avail, data, needed;
al_rc_t arc;
al_label_t label;
arc = al_splice(buf, al_bytes(buf), 0, al, NULL);
if (arc != AL_OK)
return SIO_ERR_INT;
avail = al_bytes(buf);
if (avail <= 0)
return SIO_OK;
arc = al_firstlabel(buf, 0, 1, AL_FORWARD, NULL, &label);
if (arc != AL_OK)
return SIO_ERR_INT;
al_flatten(buf, 0, avail, AL_FORWARD_SPAN, label, NULL, &data);
/* non-data is not buffered */
if (label == my->data_label)
needed = size;
else
needed = 1;
/* flush if there is extra data (that must have a different label) */
if (data < avail)
needed = 1;
if (data >= needed) {
if (data >= size)
data = size;
al_splice(buf, 0, data, NULL, al);
return SIO_OK;
}
return SIO_OK;
}
static
sio_rc_t buffer_input(sio_t *sio, al_t *al, void *u, sio_rc_t orc)
{
private_t *my = (private_t *)u;
return buffer_inout(sio, al, my, my->input, my->inputsize);
}
static
sio_rc_t buffer_output(sio_t *sio, al_t *al, void *u, sio_rc_t orc)
{
private_t *my = (private_t *)u;
return buffer_inout(sio, al, my, my->output, my->outputsize);
}
sio_module_t sio_module_buffer = {
"buffer",
buffer_init,
buffer_configure,
buffer_cleanup,
buffer_openr,
buffer_closer,
buffer_openw,
buffer_closew,
buffer_input,
buffer_output,
NULL
};
@
1.9
log
@- consistently use standard OSSP copyright message everywhere
- strip trailing whitespaces
@
text
@d3 3
a5 3
** Copyright (c) 2002-2003 Cable & Wireless Deutschland
** Copyright (c) 2002-2003 The OSSP Project
** Copyright (c) 2002-2003 Ralf S. Engelschall
@
1.8
log
@input/output now gets another parameter where scheduler tells
them from where they methods called by passing the return value
of the previously called stage.
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d1 30
d54 1
a54 1
@
1.7
log
@code cleanup
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d175 1
a175 1
sio_rc_t buffer_input(sio_t *sio, al_t *al, void *u)
d183 1
a183 1
sio_rc_t buffer_output(sio_t *sio, al_t *al, void *u)
@
1.6
log
@drop tx instance, it hasn't been used for a while.
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d21 1
a21 1
sio_rc_t buffer_init(sio_t *sio, void **u)
d34 1
a34 1
*u = my;
@
1.5
log
@add optional shutdown function to modules. On detach, it is called
and if returning SIO_OK another round through output and input
is done.
modules are now pushed at pipe head instead of appended so that
a module can do upstream I/O while being wound up.
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@a9 1
al_tx_t *outputtx;
d104 1
a104 1
arc = al_txalloc(al, &my->outputtx);
a107 6
arc = al_create(&my->output);
if (arc != AL_OK) {
al_txfree(al, my->outputtx);
return SIO_ERR_INT;
}
a117 2
al_txfree(al, my->outputtx);
my->outputtx = NULL;
@
1.4
log
@merged sio_module.h into sio.h
renamed scheduler codes to SIO_SCHED_*
added comments to sio.c
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d209 2
a210 1
buffer_output
@
1.3
log
@utilize default action
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@a6 1
#include "sio_module.h"
@
1.2
log
@code cleanup
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d144 1
a144 2
al_t *buf, size_t size,
sio_rc_t up, sio_rc_t down)
d156 1
a156 1
return down;
d178 1
a178 1
return up;
d181 1
a181 1
return down;
d189 1
a189 3
return buffer_inout(sio, al, my,
my->input, my->inputsize,
SIO_DOWNSTREAM, SIO_UPSTREAM);
d197 1
a197 3
return buffer_inout(sio, al, my,
my->output, my->outputsize,
SIO_UPSTREAM, SIO_DOWNSTREAM);
@
1.1
log
@snapshot
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d14 1
d25 1
a25 1
private_t *mydata;
d27 2
a28 2
mydata = (private_t *)malloc(sizeof(private_t));
if (mydata == NULL)
d31 2
a32 2
mydata->inputsize = 0;
mydata->outputsize = 0;
d34 3
a36 1
*u = mydata;
d49 1
a49 1
private_t *mydata = (private_t *)u;
d53 1
a53 1
mydata->inputsize = *(size_t *)val;
d55 1
a55 1
mydata->outputsize = *(size_t *)val;
d69 1
a69 1
private_t *mydata = (private_t *)u;
d71 1
a71 1
free(mydata);
d79 1
a79 1
private_t *mydata = (private_t *)u;
d82 1
a82 1
arc = al_create(&mydata->input);
d92 1
a92 1
private_t *mydata = (private_t *)u;
d94 2
a95 2
al_destroy(mydata->input);
mydata->input = NULL;
d103 1
a103 1
private_t *mydata = (private_t *)u;
d106 1
a106 1
arc = al_txalloc(al, &mydata->outputtx);
d110 1
a110 1
arc = al_create(&mydata->output);
d112 1
a112 1
al_txfree(al, mydata->outputtx);
d122 1
a122 1
private_t *mydata = (private_t *)u;
d124 4
a127 4
al_destroy(mydata->output);
mydata->output = NULL;
al_txfree(al, mydata->outputtx);
mydata->outputtx = NULL;
d132 10
d143 2
a144 1
sio_rc_t buffer_inout(sio_t *sio, al_t *al, al_t *buf, size_t size,
d165 7
a171 1
needed = size;
d188 1
a188 1
private_t *mydata = (private_t *)u;
d190 2
a191 1
return buffer_inout(sio, al, mydata->input, mydata->inputsize,
d198 1
a198 1
private_t *mydata = (private_t *)u;
d200 2
a201 1
return buffer_inout(sio, al, mydata->output, mydata->outputsize,
@