/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996-1999 by Internet Software Consortium
*
* 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.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* ev_streams.c - implement asynch stream file IO for the eventlib
* vix 04mar96 [initial]
*/
/*
* The streams list is doubly threaded. First, there's ctx->streams
* that's used by evDestroy() to find and cancel all streams. Second,
* there's ctx->strDone (head) and ctx->strLast (tail) which thread
* through the potentially smaller number of "IO completed" streams,
* used in evGetNext() to avoid scanning the entire list.
*/
/* Unlink from ctx->streams. */
if (old->prev != NULL)
old->prev->next = old->next;
else
ctx->streams = old->next;
if (old->next != NULL)
old->next->prev = old->prev;
/*
* If 'old' is on the ctx->strDone list, remove it. Update
* ctx->strLast if necessary.
*/
if (old->prevDone == NULL && old->nextDone == NULL) {
/*
* Either 'old' is the only item on the done list, or it's
* not on the done list. If the former, then we unlink it
* from the list. If the latter, we leave the list alone.
*/
if (ctx->strDone == old) {
ctx->strDone = NULL;
ctx->strLast = NULL;
}
} else {
if (old->prevDone != NULL)
old->prevDone->nextDone = old->nextDone;
else
ctx->strDone = old->nextDone;
if (old->nextDone != NULL)
old->nextDone->prevDone = old->prevDone;
else
ctx->strLast = old->prevDone;
}
/* Deallocate the stream. */
if (old->file.opaque)
evDeselectFD(opaqueCtx, old->file);
memput(old->iovOrig, sizeof (struct iovec) * old->iovOrigCount);
FREE(old);
return (0);
}
/* Copy a scatter/gather vector and initialize a stream handler's IO. */
static int
copyvec(evStream *str, const struct iovec *iov, int iocnt) {
int i;
/* Dribble out some bytes on the stream. (Called by evDispatch().) */
static void
writable(evContext opaqueCtx, void *uap, int fd, int evmask) {
evStream *str = uap;
int bytes;
/* Scoop up some bytes from the stream. (Called by evDispatch().) */
static void
readable(evContext opaqueCtx, void *uap, int fd, int evmask) {
evStream *str = uap;
int bytes;