]>
Commit | Line | Data |
---|---|---|
d76ed9a9 AS |
1 | /* ioset.h - srvx event loop |
2 | * Copyright 2002-2003 srvx Development Team | |
3 | * | |
1136f709 | 4 | * This file is part of srvx. |
d76ed9a9 | 5 | * |
1136f709 | 6 | * srvx is free software; you can redistribute it and/or modify |
d76ed9a9 | 7 | * it under the terms of the GNU General Public License as published by |
be2c97a5 | 8 | * the Free Software Foundation; either version 3 of the License, or |
d76ed9a9 AS |
9 | * (at your option) any later version. |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with srvx; if not, write to the Free Software Foundation, | |
18 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
19 | */ | |
20 | ||
21 | #if !defined(IOSET_H) | |
22 | #define IOSET_H | |
23 | ||
1136f709 | 24 | #include "common.h" |
25 | ||
26 | /* Forward declare, since functions take these as arguments. */ | |
d76ed9a9 AS |
27 | struct sockaddr; |
28 | ||
29 | struct ioq { | |
30 | char *buf; | |
31 | unsigned int size, get, put; | |
32 | }; | |
33 | ||
34 | struct io_fd { | |
35 | int fd; | |
36 | void *data; | |
1136f709 | 37 | enum { IO_CLOSED, IO_LISTENING, IO_CONNECTING, IO_CONNECTED } state; |
d76ed9a9 | 38 | unsigned int line_reads : 1; |
d76ed9a9 AS |
39 | int line_len; |
40 | struct ioq send; | |
41 | struct ioq recv; | |
1136f709 | 42 | void (*accept_cb)(struct io_fd *listener, struct io_fd *new_connect); |
d76ed9a9 AS |
43 | void (*connect_cb)(struct io_fd *fd, int error); |
44 | void (*readable_cb)(struct io_fd *fd); | |
45 | void (*destroy_cb)(struct io_fd *fd); | |
46 | }; | |
d76ed9a9 AS |
47 | extern int do_write_dbs; |
48 | extern int do_reopen; | |
49 | ||
1136f709 | 50 | void ioset_init(void); |
d76ed9a9 | 51 | struct io_fd *ioset_add(int fd); |
1136f709 | 52 | 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)); |
d76ed9a9 | 53 | 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)); |
1136f709 | 54 | void ioset_update(struct io_fd *fd); |
d76ed9a9 AS |
55 | void ioset_run(void); |
56 | void ioset_write(struct io_fd *fd, const char *buf, unsigned int nbw); | |
1136f709 | 57 | int ioset_printf(struct io_fd *fd, const char *fmt, ...) PRINTF_LIKE(2, 3); |
d76ed9a9 | 58 | int ioset_line_read(struct io_fd *fd, char *buf, int maxlen); |
1136f709 | 59 | void ioset_close(struct io_fd *fd, int os_close); |
d76ed9a9 AS |
60 | void ioset_cleanup(void); |
61 | void ioset_set_time(unsigned long new_now); | |
62 | ||
63 | #endif /* !defined(IOSET_H) */ |