#include "libut/ut.h" int UT_fd_cntl(int fd, int op, ...);
This function gets or sets ancillary state about file descriptor fd, which
must have been previously registered using UT_fd_reg(3)
or created using
UT_net_connect(3). The op argument must be one of these pre-defined
constants:
UTFD_PIPE /* type passed to UT_fd_reg(3) */ UTFD_SOCKET /* type passed to UT_fd_reg(3) */ UTFD_OTHER /* type passed to UT_fd_reg(3) */ UTFD_R /* callback invoked when readable */ UTFD_W /* callback invoked when writable */ UTFD_SOCKET_LISTENING /* disposition passed to UT_fd_reg(3) */ UTFD_SOCKET_ACCEPTED /* disposition passed to UT_fd_reg(3) */ UTFD_SOCKET_CONNECTING /* disposition passed to UT_fd_reg(3) */ UTFD_SOCKET_CONNECTED /* disposition passed to UT_fd_reg(3) */ UTFD_SOCKET_LOCALADDR /* aux data contains local address */ UTFD_SOCKET_REMOTEADDR /* aux data contains remote address */ UTFD_WRITE_PENDING /* data being written when writable */
UT_fd_cntl(fd, UTFD_GET_FLAGS, &f); f |= UTFD_CLOSE_AFTER_WRITE; UT_fd_cntl(fd, UTFD_SET_FLAGS, f);
The only flag that should be set using this method is UTFD_CLOSE_AFTER_WRITE
(which specifies that the file descriptor should be closed and unregistered
after the subsequent UT_fd_write(3)
completes, which may not be immediately).
For socket file descriptors, this function be used to alter the disposition
flags, by clearing the UTFD_SOCKET_CONNECTING flag and setting
UTFD_SOCKET_CONNECTED. (Normally this is handled automatically if
UT_net_connect(3)
is used).
This functions returns 0 on success. On error, -1 is returned. An invalid file descriptor fd or invalid op are errors.
UT_fd_reg(3), UT_fd_unreg(3), UT_fd_write(3)
Troy D. Hanson <thanson@users.sourceforge.net>