/*++ /* NAME /* poll_fd 3 /* SUMMARY /* wait until file descriptor becomes readable or writable /* SYNOPSIS /* #include <iostuff.h> /* /* int readable(fd) /* int fd; /* /* int writable(fd) /* int fd; /* /* int read_wait(fd, time_limit) /* int fd; /* int time_limit; /* /* int write_wait(fd, time_limit) /* int fd; /* int time_limit; /* /* int poll_fd(fd, request, time_limit, true_res, false_res) /* int fd; /* int request; /* int time_limit; /* int true_res; /* int false_res; /* DESCRIPTION /* The read*() and write*() functions in this module are macros /* that provide a convenient interface to poll_fd(). /* /* readable() asks the kernel if the specified file descriptor /* is readable, i.e. a read operation would not block. /* /* writable() asks the kernel if the specified file descriptor /* is writable, i.e. a write operation would not block. /* /* read_wait() waits until the specified file descriptor becomes /* readable, or until the time limit is reached. /* /* write_wait() waits until the specified file descriptor /* becomes writable, or until the time limit is reached. /* /* poll_fd() waits until the specified file descriptor becomes /* readable or writable, or until the time limit is reached. /* /* Arguments: /* .IP fd /* File descriptor. With implementations based on select(), a /* best effort is made to handle descriptors >=FD_SETSIZE. /* .IP request /* POLL_FD_READ (wait until readable) or POLL_FD_WRITE (wait /* until writable). /* .IP time_limit /* A positive value specifies a time limit in seconds. A zero /* value effects a poll (return immediately). A negative value /* means wait until the requested POLL_FD_READ or POLL_FD_WRITE /* condition becomes true. /* .IP true_res /* Result value when the requested POLL_FD_READ or POLL_FD_WRITE /* condition is true. /* .IP false_res /* Result value when the requested POLL_FD_READ or POLL_FD_WRITE /* condition is false. /* DIAGNOSTICS /* Panic: interface violation. All system call errors are fatal /* unless specified otherwise. /* /* readable() and writable() return 1 when the requested /* POLL_FD_READ or POLL_FD_WRITE condition is true, zero when /* it is false. They never return an error indication. /* /* read_wait() and write_wait() return zero when the requested /* POLL_FD_READ or POLL_FD_WRITE condition is true, -1 (with /* errno set to ETIMEDOUT) when it is false. /* /* poll_fd() returns true_res when the requested POLL_FD_READ /* or POLL_FD_WRITE condition is true, false_res when it is /* false. When poll_fd() returns a false_res value < 0, it /* also sets errno to ETIMEDOUT. /* LICENSE /* .ad /* .fi /* The Secure Mailer license must be distributed with this software. /* AUTHOR(S) /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA
/*--*/
/* poll_fd_bsd - block with time_limit until file descriptor is ready */
int poll_fd_bsd(int fd, int request, int time_limit, int true_res, int false_res)
{
fd_set req_fds;
fd_set *read_fds;
fd_set *write_fds;
fd_set except_fds; struct timeval tv; struct timeval *tp; int temp_fd = -1;
/* *Sanitychecks.
*/ if (FD_SETSIZE <= fd) { if ((temp_fd = dup(fd)) < 0 || temp_fd >= FD_SETSIZE)
msg_fatal("descriptor %d does not fit FD_SETSIZE %d", fd, FD_SETSIZE);
fd = temp_fd;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.