head 1.16;
access;
symbols
SIO_0_9_3:1.16
SIO_0_9_2:1.15
SIO_0_9_1:1.15
SIO_0_9_0:1.13;
locks; strict;
comment @ * @;
1.16
date 2005.10.03.09.06.11; author rse; state Exp;
branches;
next 1.15;
1.15
date 2003.02.09.21.39.17; author mlelstv; state Exp;
branches;
next 1.14;
1.14
date 2003.02.09.19.57.22; author rse; state Exp;
branches;
next 1.13;
1.13
date 2003.01.06.19.04.56; author rse; state Exp;
branches;
next 1.12;
1.12
date 2002.11.29.14.50.21; author mlelstv; state Exp;
branches;
next 1.11;
1.11
date 2002.11.29.13.00.18; author mlelstv; state Exp;
branches;
next 1.10;
1.10
date 2002.11.27.15.50.29; author mlelstv; state Exp;
branches;
next 1.9;
1.9
date 2002.11.24.19.36.48; author mlelstv; state Exp;
branches;
next 1.8;
1.8
date 2002.11.19.15.30.51; author mlelstv; state Exp;
branches;
next 1.7;
1.7
date 2002.11.14.15.56.10; author mlelstv; state Exp;
branches;
next 1.6;
1.6
date 2002.11.05.16.18.46; author mlelstv; state Exp;
branches;
next 1.5;
1.5
date 2002.11.05.16.05.25; author mlelstv; state Exp;
branches;
next 1.4;
1.4
date 2002.11.05.15.57.50; author mlelstv; state Exp;
branches;
next 1.3;
1.3
date 2002.11.05.15.52.21; author mlelstv; state Exp;
branches;
next 1.2;
1.2
date 2002.10.23.17.05.10; author mlelstv; state Exp;
branches;
next 1.1;
1.1
date 2002.10.22.12.57.20; author mlelstv; state Exp;
branches;
next ;
desc
@@
1.16
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_fd.h: filedescriptor stage
*/
#include
#include
#include
#include
#include
#include
#include "al.h"
#include "sio.h"
typedef struct {
char *mem;
size_t size;
} buffer_t;
typedef struct {
int fd;
buffer_t input;
size_t written;
al_label_t data_label;
al_label_t error_label;
al_label_t eof_label;
char eof, error;
} private_t;
/*
* create stage
*
* allocate private instance data
*/
static
sio_rc_t fd_init(sio_t *sio, void **up)
{
private_t *my;
my = (private_t *)malloc(sizeof(private_t));
if (my == NULL)
return SIO_ERR_MEM;
my->fd = -1;
my->input.mem = NULL;
my->input.size = 0;
sio_label(sio, SIO_LN_DATA, &my->data_label);
sio_label(sio, SIO_LN_ERROR, &my->error_label);
sio_label(sio, SIO_LN_EOF, &my->eof_label);
my->eof = '\0';
my->error = '\0';
*up = my;
return SIO_OK;
}
/*
* configure stage
*
*/
static
sio_rc_t fd_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, "fd")) {
my->fd = *(int *)val;
} else if (!strcmp(name, "buflen")) {
my->input.size = *(size_t *)val;
} else {
return SIO_ERR_ARG;
}
return SIO_OK;
}
/*
* destroy stage
*/
static
sio_rc_t fd_cleanup(sio_t *sio, void *u)
{
private_t *my = (private_t *)u;
free(my);
return SIO_OK;
}
static
sio_rc_t fd_openr(sio_t *sio, al_t *al, void *u)
{
private_t *my = (private_t *)u;
buffer_t *buf = &my->input;
char *p;
size_t n;
n = buf->size;
if (n == 0)
return SIO_ERR_ARG;
p = realloc(buf->mem, n);
if (p != NULL)
buf->mem = p;
if (buf->mem == NULL)
return SIO_ERR_MEM;
return SIO_OK;
}
static
sio_rc_t fd_closer(sio_t *sio, al_t *al, void *u)
{
private_t *my = (private_t *)u;
buffer_t *buf = &my->input;
if (buf->mem != NULL) {
free(buf->mem);
buf->mem = NULL;
}
return SIO_OK;
}
static
sio_rc_t fd_openw(sio_t *sio, al_t *al, void *u)
{
return SIO_OK;
}
static
sio_rc_t fd_closew(sio_t *sio, al_t *al, void *u)
{
return SIO_OK;
}
static
sio_rc_t fd_input(sio_t *sio, al_t *al, void *u, sio_rc_t orc)
{
private_t *my = (private_t *)u;
buffer_t *buf = &my->input;
int actual;
actual = read(my->fd, buf->mem, buf->size);
if (actual < 0) {
al_append_bytes(al, &my->error, sizeof(my->error), my->error_label);
return SIO_SCHED_DOWN;
} else if (actual == 0) {
al_append_bytes(al, &my->eof, sizeof(my->eof), my->eof_label);
return SIO_SCHED_DOWN;
}
al_append_bytes(al, buf->mem, actual, my->data_label);
return SIO_SCHED_DOWN;
}
static
al_rc_t fd_output_chunk(al_chunk_t *alc, void *u)
{
private_t *my = (private_t *)u;
char *p;
size_t n;
int actual;
p = al_chunk_ptr(alc, 0);
n = al_chunk_len(alc);
actual = write(my->fd, p, n);
if (actual < 0)
return AL_ERR_EOF;
my->written += actual;
return AL_OK;
}
static
sio_rc_t fd_output(sio_t *sio, al_t *al, void *u, sio_rc_t orc)
{
private_t *my = (private_t *)u;
al_rc_t arc;
size_t n = al_bytes(al);
my->written = 0;
arc = al_traverse_cb(al, 0, n, AL_FORWARD, my->data_label,
fd_output_chunk, u);
if (arc != AL_OK)
return SIO_SCHED_DOWN;
arc = al_splice(al, 0, al_bytes(al), NULL, NULL);
if (arc != AL_OK)
return SIO_SCHED_DOWN;
return SIO_SCHED_DOWN;
}
sio_module_t sio_module_fd = {
"fd",
fd_init,
fd_configure,
fd_cleanup,
fd_openr,
fd_closer,
fd_openw,
fd_closew,
fd_input,
fd_output,
NULL
};
@
1.15
log
@fix memory leak.
align code with other modules
@
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.14
log
@Fix memory leak.
@
text
@d114 4
a117 2
if (u != NULL)
free(u);
@
1.13
log
@- consistently use standard OSSP copyright message everywhere
- strip trailing whitespaces
@
text
@d114 2
@
1.12
log
@fix cut&paste
fix signed error (return value of read != size_t)
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d1 30
d65 1
a65 1
@
1.11
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
@d136 1
a136 1
sio_rc_t fd_input(sio_t *sio, al_t *al, void *u)
d140 1
a140 1
size_t actual;
d157 1
a157 1
al_rc_t fd_output_chunk(al_chunk_t *alc, void *u, sio_rc_t orc)
@
1.10
log
@code cleanup
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d157 1
a157 1
al_rc_t fd_output_chunk(al_chunk_t *alc, void *u)
d177 1
a177 1
sio_rc_t fd_output(sio_t *sio, al_t *al, void *u)
@
1.9
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
@d32 1
a32 1
sio_rc_t fd_init(sio_t *sio, void **u)
d52 1
a52 1
*u = my;
@
1.8
log
@cut&paste error
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d207 2
a208 1
fd_output
@
1.7
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
@d144 1
a144 1
al_append_bytes(al, &my->eof, sizeof(my->eof), my->error_label);
d147 1
a147 1
al_append_bytes(al, &my->error, sizeof(my->error), my->eof_label);
@
1.6
log
@more sanity checking
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@a9 1
#include "sio_module.h"
d145 1
a145 1
return SIO_DOWNSTREAM;
d148 1
a148 1
return SIO_DOWNSTREAM;
d153 1
a153 1
return SIO_DOWNSTREAM;
d188 1
a188 1
return SIO_DOWNSTREAM;
d192 1
a192 1
return SIO_DOWNSTREAM;
d194 1
a194 1
return SIO_DOWNSTREAM;
@
1.5
log
@eat all output, even when write failed. Otherwise sio_buffer will
insist until we deliver...
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d97 3
@
1.4
log
@fix typos
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d159 2
a160 1
size_t n, actual;
d188 1
a188 1
arc = al_splice(al, 0, my->written, NULL, NULL);
@
1.3
log
@code cleanup
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d142 1
a142 1
al_appendbytes(al, &my->eof, sizeof(my->eof), my->error_label);
d145 1
a145 1
al_appendbytes(al, &my->error, sizeof(my->error), my->eof_label);
d185 1
a185 1
return SIO_ERR_DOWNSTREAM;
d189 1
a189 1
return SIO_ERR_DOWNSTREAM;
@
1.2
log
@snapshot
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d21 4
a24 3
void *label_data;
void *label_error;
void *label_eof;
d35 1
a35 1
private_t *mydata;
d37 2
a38 2
mydata = (private_t *)malloc(sizeof(private_t));
if (mydata == NULL)
d41 1
a41 1
mydata->fd = -1;
d43 2
a44 2
mydata->input.mem = NULL;
mydata->input.size = 0;
d46 3
a48 3
sio_label(sio, SIO_LN_DATA, &mydata->label_data);
sio_label(sio, SIO_LN_ERROR, &mydata->label_error);
sio_label(sio, SIO_LN_EOF, &mydata->label_eof);
d50 4
a53 1
*u = mydata;
d65 1
a65 1
private_t *mydata = (private_t *)u;
d69 1
a69 1
mydata->fd = *(int *)val;
d71 1
a71 1
mydata->input.size = *(size_t *)val;
d91 2
a92 2
private_t *mydata = (private_t *)u;
buffer_t *buf = &mydata->input;
d110 2
a111 2
private_t *mydata = (private_t *)u;
buffer_t *buf = &mydata->input;
d136 2
a137 2
private_t *mydata = (private_t *)u;
buffer_t *buf = &mydata->input;
d140 1
a140 1
actual = read(mydata->fd, buf->mem, buf->size);
d142 2
a143 2
al_append_bytes(al, NULL, 0, mydata->label_error);
return SIO_OK;
d145 2
a146 2
al_append_bytes(al, NULL, 0, mydata->label_eof);
return SIO_OK;
d149 1
a149 1
al_append_bytes(al, buf->mem, actual, mydata->label_data);
d157 1
a157 1
private_t *mydata = (private_t *)u;
d164 1
a164 1
actual = write(mydata->fd, p, n);
d168 1
a168 1
mydata->written += actual;
d176 1
a176 1
private_t *mydata = (private_t *)u;
d180 1
a180 1
mydata->written = 0;
d182 1
a182 1
arc = al_traverse_cb(al, 0, n, AL_FORWARD, mydata->label_data,
d184 2
a185 1
if (arc != AL_OK) return SIO_ERR_INT;
d187 3
a189 2
arc = al_splice(al, 0, mydata->written, NULL, NULL);
if (arc != AL_OK) return SIO_ERR_INT;
@
1.1
log
@initial commit
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d13 5
d19 5
a23 3
size_t buflen;
char *buf;
size_t actual;
d40 8
a47 3
mydata->fd = -1;
mydata->buflen = 0;
mydata->buf = NULL;
d59 1
a59 1
sio_rc_t fd_configure(sio_t *sio, void *u, void *obj, void *value)
a62 1
char *newbuf;
d65 1
a65 1
mydata->fd = *(int *)value;
d67 1
a67 5
mydata->buflen = *(int *)value;
newbuf = realloc(mydata->buf, mydata->buflen);
if (newbuf == NULL)
return SIO_ERR_MEM;
mydata->buf = newbuf;
d81 6
d88 8
d97 2
a98 2
if (mydata->buf) free(mydata->buf);
free(mydata);
d104 15
a118 1
sio_rc_t fd_open(sio_t *sio, void *u)
d124 1
a124 1
sio_rc_t fd_close(sio_t *sio, void *u)
d133 1
d136 8
a143 6
if (mydata->buf == NULL)
return SIO_ERR_ARG;
actual = read(mydata->fd, mydata->buf, mydata->buflen);
if (actual < 0)
return SIO_ERR_SYS;
d145 1
a145 1
al_append_bytes(al, mydata->buf, actual);
d147 1
a147 1
return SIO_OK;
d164 1
a164 1
mydata->actual += actual;
d176 1
a176 1
mydata->actual = 0;
d178 2
a179 1
arc = al_traverse_cb(al, 0, n, AL_FORWARD, fd_output_chunk, u);
d182 1
a182 1
arc = al_splice(al, 0, mydata->actual, NULL, NULL);
d185 1
a185 1
return SIO_OK;
d188 1
a188 1
sio_module_t sio_fd_module = {
d193 4
a196 2
fd_open,
fd_close,
@