X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fioset.h;h=be27332b1f820c6153e2af520fba25188bcae0e9;hb=560c19871dfb899e254f5f3e68d4d2d567f4940c;hp=0c4f84fc12c4e4c3d94519508c9e83b7f9327143;hpb=e44152b845d78f9e8ad0b2ca3957d70f4ff7e5b1;p=srvx.git diff --git a/src/ioset.h b/src/ioset.h index 0c4f84f..be27332 100644 --- a/src/ioset.h +++ b/src/ioset.h @@ -21,7 +21,9 @@ #if !defined(IOSET_H) #define IOSET_H -/* Forward declare, since ioset_connect() takes a sockaddr argument. */ +#include "common.h" + +/* Forward declare, since functions take these as arguments. */ struct sockaddr; struct ioq { @@ -32,27 +34,29 @@ struct ioq { struct io_fd { int fd; void *data; - unsigned int connected : 1; + enum { IO_CLOSED, IO_LISTENING, IO_CONNECTING, IO_CONNECTED } state; unsigned int wants_reads : 1; unsigned int line_reads : 1; - unsigned int eof : 1; int line_len; struct ioq send; struct ioq recv; + void (*accept_cb)(struct io_fd *listener, struct io_fd *new_connect); void (*connect_cb)(struct io_fd *fd, int error); void (*readable_cb)(struct io_fd *fd); void (*destroy_cb)(struct io_fd *fd); }; - extern int do_write_dbs; extern int do_reopen; +void ioset_init(void); struct io_fd *ioset_add(int fd); +struct io_fd *ioset_listen(struct sockaddr *local, unsigned int sa_size, void *data, void (*accept_cb)(struct io_fd *listener, struct io_fd *new_connect)); struct io_fd *ioset_connect(struct sockaddr *local, unsigned int sa_size, const char *hostname, unsigned int port, int blocking, void *data, void (*connect_cb)(struct io_fd *fd, int error)); void ioset_run(void); void ioset_write(struct io_fd *fd, const char *buf, unsigned int nbw); +int ioset_printf(struct io_fd *fd, const char *fmt, ...) PRINTF_LIKE(2, 3); int ioset_line_read(struct io_fd *fd, char *buf, int maxlen); -void ioset_close(int fd, int os_close); +void ioset_close(struct io_fd *fd, int os_close); void ioset_cleanup(void); void ioset_set_time(unsigned long new_now);