/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1995-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_files.c - implement asynch file IO for the eventlib
* vix 11sep95 [initial]
*/
#if !defined(LINT) && !defined(CODECENTER)
#endif
#include "port_before.h"
#include "fd_setsize.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <isc/eventlib.h>
#include "eventlib_p.h"
#include "port_after.h"
int
int fd,
int eventmask,
void *uap,
) {
int mode;
"evSelectFD(ctx %p, fd %d, mask 0x%x, func %p, uap %p)\n",
#ifndef USE_POLL
#endif
/*
* The first time we touch a file descriptor, we need to check to see
* if the application already had it in O_NONBLOCK mode and if so, all
* of our deselect()'s have to leave it in O_NONBLOCK. If not, then
* all but our last deselect() has to leave it in O_NONBLOCK.
*/
#ifdef USE_POLL
/* Make sure both ctx->pollfds[] and ctx->fdTable[] are large enough */
#endif /* USE_POLL */
if (mode & PORT_NONBLOCK)
else {
#ifdef USE_FIONBIO_IOCTL
#else
#endif
}
}
/*
* If this descriptor is already in use, search for it again to see
* if any of the eventmask bits we want to set are already captured.
* We cannot usefully capture the same fd event more than once in the
* same context.
*/
/* Allocate and fill. */
/*
* Insert at head. Order could be important for performance if we
* believe that evGetNext()'s accesses to the fd_sets will be more
* serial and therefore more cache-lucky if the list is ordered by
* ``fd.'' We do not believe these things, so we don't do it.
*
* The interesting sequence is where GetNext() has cached a select()
* result and the caller decides to evSelectFD() on some descriptor.
* Since GetNext() starts at the head, it can miss new entries we add
* at the head. This is not a serious problem since the event being
* evSelectFD()'d for has to occur before evSelectFD() is called for
* the file event to be considered "missed" -- a real corner case.
* Maintaining a "tail" pointer for ctx->files would fix this, but I'm
* not sure it would be ``more correct.''
*/
/* Insert into fd table. */
/* Turn on the appropriate bits in the {rd,wr,ex}Next fd_set's. */
/* Update fdMax. */
/* Remember the ID if the caller provided us a place for it. */
if (opaqueID)
return (0);
}
int
if (!del) {
return (-1);
}
/* Get the mode. Unless the file has been closed, errors are bad. */
/* Remove from the list of files. */
else
/* Remove from the fd table. */
else
/*
* If the file descriptor does not appear in any other select() entry,
* and if !EV_WASNONBLOCK, and if we got no EBADF when we got the mode
* earlier, then: restore the fd to blocking status.
*/
mode != -1) {
/*
* Note that we won't return an error status to the caller if
* this fcntl() fails since (a) we've already done the work
* and (b) the caller didn't ask us anything about O_NONBLOCK.
*/
#ifdef USE_FIONBIO_IOCTL
int off = 0;
#else
#endif
}
/*
* Now find all other uses of this descriptor and OR together an event
* mask so that we don't turn off {rd,wr,ex}Next bits that some other
* file event is using. As an optimization, stop if the event mask
* fills.
*/
eventmask = 0;
for ((void)NULL;
/* OK, now we know which bits we can clear out. */
}
}
}
}
}
}
/* If this was the maxFD, find the new one. */
}
/* If this was the fdNext, cycle that to the next entry. */
/* Couldn't free it before now since we were using fields out of it. */
return (0);
}
static evFile *
break;
return (id);
}
/*! \file */