]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * commio.h: A header for the network subsystem. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2004 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
24 | * $Id: commio.h 3354 2007-04-03 09:21:31Z nenolod $ | |
25 | */ | |
26 | ||
27 | #ifndef INCLUDED_commio_h | |
28 | #define INCLUDED_commio_h | |
29 | ||
30 | #include "setup.h" | |
31 | #include "config.h" | |
32 | #include "ircd_defs.h" | |
33 | #include "tools.h" | |
34 | ||
35 | typedef struct _fde fde_t; | |
36 | ||
37 | /* Callback for completed IO events */ | |
38 | typedef void PF(int fd, void *); | |
39 | ||
40 | /* virtual function types for I/O --nenolod */ | |
41 | typedef int IOFuncRead(fde_t *, void *buf, size_t count); | |
42 | typedef int IOFuncWrite(fde_t *, const void *buf, size_t count); | |
43 | ||
44 | /* Callback for completed connections */ | |
45 | /* int fd, int status, void * */ | |
46 | typedef void CNCB(int fd, int, void *); | |
47 | ||
48 | #define FD_DESC_SZ 128 /* hostlen + comment */ | |
49 | ||
50 | ||
51 | /* FD type values */ | |
52 | enum | |
53 | { | |
54 | FD_NONE, | |
55 | FD_LOG, | |
56 | FD_FILE, | |
57 | FD_FILECLOSE, | |
58 | FD_SOCKET, | |
59 | FD_PIPE, | |
60 | FD_UNKNOWN | |
61 | }; | |
62 | ||
63 | enum | |
64 | { | |
65 | COMM_OK, | |
66 | COMM_ERR_BIND, | |
67 | COMM_ERR_DNS, | |
68 | COMM_ERR_TIMEOUT, | |
69 | COMM_ERR_CONNECT, | |
70 | COMM_ERROR, | |
71 | COMM_ERR_MAX | |
72 | }; | |
73 | ||
74 | typedef enum fdlist_t | |
75 | { | |
76 | FDLIST_NONE, | |
77 | FDLIST_SERVICE, | |
78 | FDLIST_SERVER, | |
79 | FDLIST_IDLECLIENT, | |
80 | FDLIST_BUSYCLIENT, | |
81 | FDLIST_MAX | |
82 | } | |
83 | fdlist_t; | |
84 | ||
85 | ||
86 | extern int highest_fd; | |
87 | extern int number_fd; | |
88 | ||
89 | struct Client; | |
90 | ||
91 | struct _fde | |
92 | { | |
93 | /* New-school stuff, again pretty much ripped from squid */ | |
94 | /* | |
95 | * Yes, this gives us only one pending read and one pending write per | |
96 | * filedescriptor. Think though: when do you think we'll need more? | |
97 | */ | |
98 | int fd; /* So we can use the fde_t as a callback ptr */ | |
99 | int type; | |
100 | fdlist_t list; /* Which list this FD should sit on */ | |
101 | int comm_index; /* where in the poll list we live */ | |
102 | char desc[FD_DESC_SZ]; | |
103 | ||
104 | PF *read_handler; | |
105 | void *read_data; | |
106 | ||
107 | PF *write_handler; | |
108 | void *write_data; | |
109 | ||
110 | PF *timeout_handler; | |
111 | void *timeout_data; | |
112 | time_t timeout; | |
113 | ||
114 | PF *flush_handler; | |
115 | void *flush_data; | |
116 | time_t flush_timeout; | |
117 | ||
118 | IOFuncRead *read_impl; | |
119 | IOFuncWrite *write_impl; | |
120 | ||
121 | struct DNSQuery *dns_query; | |
122 | struct | |
123 | { | |
124 | unsigned int open:1; | |
125 | unsigned int close_request:1; | |
126 | unsigned int write_daemon:1; | |
127 | unsigned int closing:1; | |
128 | unsigned int socket_eof:1; | |
129 | unsigned int nolinger:1; | |
130 | unsigned int nonblocking:1; | |
131 | unsigned int ipc:1; | |
132 | unsigned int called_connect:1; | |
133 | } | |
134 | flags; | |
135 | struct | |
136 | { | |
137 | struct irc_sockaddr_storage hostaddr; | |
138 | CNCB *callback; | |
139 | void *data; | |
140 | /* We'd also add the retry count here when we get to that -- adrian */ | |
141 | } | |
142 | connect; | |
143 | int pflags; | |
144 | dlink_node node; | |
145 | }; | |
146 | ||
147 | ||
148 | void fdlist_init(void); | |
149 | ||
150 | extern void comm_open(int, unsigned int, const char *); | |
151 | extern void comm_close(int); | |
152 | extern void comm_dump(struct Client *source_p); | |
153 | #ifndef __GNUC__ | |
154 | extern void comm_note(int fd, const char *format, ...); | |
155 | #else | |
156 | extern void comm_note(int fd, const char *format, ...) __attribute__ ((format(printf, 2, 3))); | |
157 | #endif | |
158 | ||
159 | #define FB_EOF 0x01 | |
160 | #define FB_FAIL 0x02 | |
161 | ||
162 | ||
163 | /* Size of a read buffer */ | |
164 | #define READBUF_SIZE 16384 /* used by src/packet.c and src/s_serv.c */ | |
165 | ||
166 | /* Type of IO */ | |
167 | #define COMM_SELECT_READ 0x1 | |
168 | #define COMM_SELECT_WRITE 0x2 | |
169 | #define COMM_SELECT_RETRY 0x4 | |
170 | extern int readcalls; | |
171 | extern const char *const NONB_ERROR_MSG; | |
172 | extern const char *const SETBUF_ERROR_MSG; | |
173 | ||
174 | extern void comm_close_all(void); | |
175 | extern int comm_set_nb(int); | |
176 | extern int comm_set_buffers(int, int); | |
177 | ||
178 | extern int comm_get_sockerr(int); | |
179 | extern int ignoreErrno(int ierrno); | |
180 | ||
181 | extern void comm_settimeout(int fd, time_t, PF *, void *); | |
182 | extern void comm_setflush(int fd, time_t, PF *, void *); | |
183 | extern void comm_checktimeouts(void *); | |
184 | extern void comm_connect_tcp(int fd, const char *, u_short, | |
185 | struct sockaddr *, int, CNCB *, void *, int, int); | |
186 | extern const char *comm_errstr(int status); | |
187 | extern int comm_socket(int family, int sock_type, int proto, const char *note); | |
188 | extern int comm_accept(int fd, struct sockaddr *pn, socklen_t *addrlen); | |
189 | ||
190 | /* These must be defined in the network IO loop code of your choice */ | |
191 | extern void comm_setselect(int fd, fdlist_t list, unsigned int type, | |
192 | PF * handler, void *client_data, time_t timeout); | |
193 | extern void init_netio(void); | |
194 | extern int read_message(time_t, unsigned char); | |
195 | extern int comm_select(unsigned long); | |
196 | extern int disable_sock_options(int); | |
197 | #ifdef IPV6 | |
198 | extern void mangle_mapped_sockaddr(struct sockaddr *in); | |
199 | #else | |
200 | #define mangle_mapped_sockaddr(x) | |
201 | #endif | |
202 | ||
203 | extern int comm_get_maxconnections(void); | |
204 | ||
205 | extern fde_t *comm_locate_fd(int fd); | |
206 | ||
207 | #endif /* INCLUDED_commio_h */ |