Initial import (again)
[srvx.git] / src / ioset.h
1 /* ioset.h - srvx event loop
2  * Copyright 2002-2003 srvx Development Team
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.  Important limitations are
8  * listed in the COPYING file that accompanies this software.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, email srvx-maintainers@srvx.net.
17  */
18
19 #if !defined(IOSET_H)
20 #define IOSET_H
21
22 /* Forward declare, since ioset_connect() takes a sockaddr argument. */
23 struct sockaddr;
24
25 struct ioq {
26     char *buf;
27     unsigned int size, get, put;
28 };
29
30 struct io_fd {
31     int fd;
32     void *data;
33     unsigned int connected : 1;
34     unsigned int wants_reads : 1;
35     unsigned int line_reads : 1;
36     unsigned int eof : 1;
37     int line_len;
38     struct ioq send;
39     struct ioq recv;
40     void (*connect_cb)(struct io_fd *fd, int error);
41     void (*readable_cb)(struct io_fd *fd);
42     void (*destroy_cb)(struct io_fd *fd);
43 };
44
45 extern int clock_skew;
46 extern int do_write_dbs;
47 extern int do_reopen;
48
49 struct io_fd *ioset_add(int fd);
50 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));
51 void ioset_run(void);
52 void ioset_write(struct io_fd *fd, const char *buf, unsigned int nbw);
53 int ioset_line_read(struct io_fd *fd, char *buf, int maxlen);
54 void ioset_close(int fd, int os_close);
55 void ioset_cleanup(void);
56 void ioset_set_time(unsigned long new_now);
57
58 #endif /* !defined(IOSET_H) */