#ifndef FD_H #define FD_H #include #include "list.h" #define fd_SET(fd, fdset, maxfd) FD_SET((fd)->fd_no, (fdset)); \ if ((fd)->fd_no>(maxfd)) (maxfd)=(fd)->fd_no; #define fd_ISSET(fd, fdset) FD_ISSET((fd)->fd_no, (fdset)) #define FD_CLOSE 1 typedef struct fd_s { int fd_no, fd_in, fd_out; int fd_flags, fd_fdflags, fd_flagsvalid; int fd_read_error, fd_write_error; char *fd_name; list_t fd_all; list_t fd_open_readers; list_t fd_open_writers; list_t fd_notify_readok; list_t fd_notify_writeok; list_t fd_notify_misc; } fd_t; typedef void (notify_func_t)(void *object, void *arg1, int arg2); typedef struct notifier_s { list_t list; void *object; notify_func_t *function; } notifier_t; extern fd_t *fd_stdin, *fd_stdout, *fd_stderr; extern notifier_t *notifier_alloc(void); extern notifier_t *notifier_init(notifier_t *notifier, void *notify_obj, notify_func_t *notify_func); extern fd_t *fd_alloc(void); extern void fd_init(fd_t *fd, int fd_no, int in, int out, const char *name); extern void fd_set_close_on_exec(fd_t *fd); extern void fd_set_nonblock(fd_t *fd); extern void fd_dup(fd_t **dst, fd_t *src, const char *name); extern int fd_accept(fd_t **dst, fd_t *listener, struct sockaddr *addr, socklen_t *addrlen, const char *name); extern int fd_shutdown(fd_t *fd, int how); extern void fd_close(fd_t *fd); extern void fd_last_use(fd_t *fd); extern void fd_add_reader(fd_t *fd, list_t *user); extern void fd_add_writer(fd_t *fd, list_t *user); extern void fd_add_readwriter(fd_t *fd, list_t *user); extern void fd_del_reader(fd_t *fd, list_t *user); extern void fd_del_writer(fd_t *fd, list_t *user); extern void fd_del_readwriter(fd_t *fd, list_t *user); extern void fd_request_read(fd_t *fd, notifier_t *notifier); extern void fd_request_write(fd_t *fd, notifier_t *notifier); extern void fd_request_misc(fd_t *fd, notifier_t *notifier); extern void fd_unrequest_read(notifier_t *notifier); extern void fd_unrequest_write(notifier_t *notifier); extern void fd_unrequest_misc(notifier_t *notifier); extern void fd_preselect(fd_t *fd, int *maxfd, fd_set *rfds, fd_set *wfds); extern void fd_postselect(fd_t *fd, fd_set *rfds, fd_set *wfds); extern void fd_all_preselect(int *maxfd, fd_set *rfds, fd_set *wfds); extern void fd_all_postselect(fd_set *rfds, fd_set *wfds); extern ssize_t fd_read(fd_t *fd, void *buf, size_t len); extern ssize_t fd_readv(fd_t *fd, const struct iovec *vec, size_t veclen); extern ssize_t fd_write(fd_t *fd, void *buf, size_t len); extern ssize_t fd_writev(fd_t *fd, const struct iovec *vec, size_t veclen); extern void fd_prog_init(void); #endif