head 1.11; access; symbols SIO_0_9_3:1.11 SIO_0_9_2:1.10 SIO_0_9_1:1.9 SIO_0_9_0:1.8; locks; strict; comment @ * @; 1.11 date 2005.10.03.09.06.11; author rse; state Exp; branches; next 1.10; 1.10 date 2003.06.30.10.36.52; author rse; state Exp; branches; next 1.9; 1.9 date 2003.02.09.21.39.17; author mlelstv; state Exp; branches; next 1.8; 1.8 date 2003.01.20.19.12.54; author mlelstv; state Exp; branches; next 1.7; 1.7 date 2003.01.06.19.04.56; author rse; state Exp; branches; next 1.6; 1.6 date 2002.11.29.13.00.18; author mlelstv; state Exp; branches; next 1.5; 1.5 date 2002.11.27.15.50.29; author mlelstv; state Exp; branches; next 1.4; 1.4 date 2002.11.24.19.36.48; author mlelstv; state Exp; branches; next 1.3; 1.3 date 2002.11.14.15.56.10; 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.11.05.13.23.36; author mlelstv; state Exp; branches; next ; desc @@ 1.11 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_sa.c: OSSP sa socket I/O stage */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #if ENABLE_SA #include #include #include #include #include #include #include "al.h" #include "sio.h" #include "sa.h" typedef struct { char *mem; size_t size; } buffer_t; typedef struct { sa_t *sa; buffer_t input; size_t written; al_label_t data_label; al_label_t error_label; al_label_t eof_label; char eof; char error; } private_t; /* * create stage * * allocate private instance data */ static sio_rc_t saw_init(sio_t *sio, void **up) { private_t *my; my = (private_t *)malloc(sizeof(private_t)); if (my == NULL) return SIO_ERR_MEM; my->sa = NULL; 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 saw_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, "sa")) { my->sa = (sa_t *)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 saw_cleanup(sio_t *sio, void *u) { private_t *my = (private_t *)u; free(my); return SIO_OK; } static sio_rc_t saw_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; 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 saw_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 saw_openw(sio_t *sio, al_t *al, void *u) { return SIO_OK; } static sio_rc_t saw_closew(sio_t *sio, al_t *al, void *u) { return SIO_OK; } static void saw_writeeof(al_t *al, private_t *my) { al_splice(al, 0, al_bytes(al), NULL, NULL); al_append_bytes(al, &my->eof, sizeof(my->eof), my->eof_label); } static void saw_writeerror(al_t *al, private_t *my) { al_splice(al, 0, al_bytes(al), NULL, NULL); al_append_bytes(al, &my->error, sizeof(my->error), my->error_label); } static sio_rc_t saw_input(sio_t *sio, al_t *al, void *u, sio_rc_t orc) { private_t *my = (private_t *)u; buffer_t *buf = &my->input; size_t actual; sa_rc_t src; src = sa_read(my->sa, buf->mem, buf->size, &actual); if (src != SA_OK) { saw_writeerror(al, my); return SIO_SCHED_DOWN; } else if (src == SA_ERR_EOF) { saw_writeeof(al, my); return SIO_SCHED_DOWN; } al_append_bytes(al, buf->mem, actual, my->data_label); return SIO_SCHED_DOWN; } static al_rc_t saw_output_chunk(al_chunk_t *alc, void *u) { private_t *my = (private_t *)u; char *p; size_t n, actual; sa_rc_t src; p = al_chunk_ptr(alc, 0); n = al_chunk_len(alc); src = sa_write(my->sa, p, n, &actual); if (src != SA_OK) return AL_ERR_EOF; my->written += actual; /* XXX not used */ return AL_OK; } static sio_rc_t saw_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, saw_output_chunk, u); if (arc != AL_OK) return SIO_ERR_INT; arc = al_splice(al, 0, al_bytes(al), NULL, NULL); if (arc != AL_OK) return SIO_ERR_INT; return SIO_SCHED_DOWN; } sio_module_t sio_module_sa = { "sa", saw_init, saw_configure, saw_cleanup, saw_openr, saw_closer, saw_openw, saw_closew, saw_input, saw_output, NULL }; #else const char __sio_sa_c[] = ""; #endif /* ENABLE_SA */ @ 1.10 log @*) Correctly check the "status" return value of waitpid(3) in the test suite. *) Change in the test suite "%08lx" format string to "%d" because the ts library only has a minimal formatting engine and the argument is "int" and not "long" anyway. *) Make sure that sio_{bio,sa,zlib}.c are not empty compilation units (not allowed in ISO C) even if BIO, SA or ZLIB support is not activated. *) Changed SIZE_T_MAX fallback definition to a more portable variant based on sizeof(size_t) instead of relying on the existance of (non portable) UINT_MAX. *) Added GNU autoconf checks for libnsl/libsocket under Solaris. *) Upgraded to GNU libtool 1.5 @ 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.9 log @fix memory leak. align code with other modules @ text @d264 4 @ 1.8 log @make compilation optional @ text @d123 4 @ 1.7 log @- consistently use standard OSSP copyright message everywhere - strip trailing whitespaces @ text @d31 6 d260 1 a260 1 @ 1.6 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 d68 1 a68 1 @ 1.5 log @code cleanup PR: Submitted by: Reviewed by: Approved by: Obtained from: @ text @d150 1 a150 1 sio_rc_t saw_input(sio_t *sio, al_t *al, void *u) d192 1 a192 1 sio_rc_t saw_output(sio_t *sio, al_t *al, void *u) @ 1.4 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 @d35 1 a35 1 sio_rc_t saw_init(sio_t *sio, void **u) d55 1 a55 1 *u = my; @ 1.3 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 @d220 2 a221 1 saw_output @ 1.2 log @code cleanup PR: Submitted by: Reviewed by: Approved by: Obtained from: @ text @a9 1 #include "sio_module.h" d160 1 a160 1 return SIO_DOWNSTREAM; d163 1 a163 1 return SIO_DOWNSTREAM; d168 1 a168 1 return SIO_DOWNSTREAM; d207 1 a207 1 return SIO_DOWNSTREAM; @ 1.1 log @snapshot - sio_strategy now has a default direction triggered by SIO_OK result - added structure tag to aid debugging - sio_hole eats all data and returns downstream (correct ?) - sio_null now uses default directio - sio_sa puts wrapper on sa objects - sio_hello.c implements a trivial protocol handler PR: Submitted by: Reviewed by: Approved by: Obtained from: @ text @d23 3 a25 3 void *label_data; void *label_error; void *label_eof; d36 1 a36 1 sio_rc_t sa_init(sio_t *sio, void **u) d49 3 a51 3 sio_label(sio, SIO_LN_DATA, &my->label_data); sio_label(sio, SIO_LN_ERROR, &my->label_error); sio_label(sio, SIO_LN_EOF, &my->label_eof); d66 1 a66 1 sio_rc_t sa_configure(sio_t *sio, void *u, void *obj, void *val) d86 1 a86 1 sio_rc_t sa_cleanup(sio_t *sio, void *u) d92 1 a92 1 sio_rc_t sa_openr(sio_t *sio, al_t *al, void *u) d111 1 a111 1 sio_rc_t sa_closer(sio_t *sio, al_t *al, void *u) d125 1 a125 1 sio_rc_t sa_openw(sio_t *sio, al_t *al, void *u) d131 1 a131 1 sio_rc_t sa_closew(sio_t *sio, al_t *al, void *u) d137 1 a137 1 void sa_writeeof(al_t *al, private_t *my) d140 1 a140 1 al_append_bytes(al, &my->eof, sizeof(my->eof), my->label_eof); d144 1 a144 1 void sa_writeerror(al_t *al, private_t *my) d147 1 a147 1 al_append_bytes(al, &my->error, sizeof(my->error), my->label_error); d151 1 a151 1 sio_rc_t sa_input(sio_t *sio, al_t *al, void *u) d160 1 a160 1 sa_writeerror(al, my); d163 1 a163 1 sa_writeeof(al, my); d167 1 a167 1 al_append_bytes(al, buf->mem, actual, my->label_data); d173 1 a173 1 al_rc_t sa_output_chunk(al_chunk_t *alc, void *u) d193 1 a193 1 sio_rc_t sa_output(sio_t *sio, al_t *al, void *u) d201 2 a202 2 arc = al_traverse_cb(al, 0, n, AL_FORWARD, my->label_data, sa_output_chunk, u); d213 9 a221 9 sa_init, sa_configure, sa_cleanup, sa_openr, sa_closer, sa_openw, sa_closew, sa_input, sa_output @