]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * commio-int.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-2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
22 | * USA | |
23 | * | |
24 | * $Id: commio.h 24059 2007-07-24 17:25:41Z androsyn $ | |
25 | */ | |
26 | ||
27 | #ifndef _COMMIO_INT_H | |
28 | #define _COMMIO_INT_H 1 | |
29 | ||
30 | #define RB_FD_HASH_BITS 12 | |
31 | #define RB_FD_HASH_SIZE (1UL << RB_FD_HASH_BITS) | |
32 | #define RB_FD_HASH_MASK (RB_FD_HASH_SIZE-1) | |
33 | ||
34 | #define FD_DESC_SZ 128 /* hostlen + comment */ | |
35 | ||
36 | ||
37 | #ifdef _WIN32 | |
38 | #define rb_get_errno() do { errno = WSAGetLastError(); WSASetLastError(errno); } while(0) | |
39 | #else | |
40 | #define rb_get_errno() | |
41 | #endif | |
42 | ||
43 | #define rb_hash_fd(x) ((x ^ (x >> RB_FD_HASH_BITS) ^ (x >> (RB_FD_HASH_BITS * 2))) & RB_FD_HASH_MASK) | |
44 | ||
45 | #ifdef HAVE_WRITEV | |
46 | #ifndef UIO_MAXIOV | |
47 | # if defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__) | |
48 | /* FreeBSD 4.7 defines it in sys/uio.h only if _KERNEL is specified */ | |
49 | # define RB_UIO_MAXIOV 1024 | |
50 | # elif defined(__sgi) | |
51 | /* IRIX 6.5 has sysconf(_SC_IOV_MAX) which might return 512 or bigger */ | |
52 | # define RB_UIO_MAXIOV 512 | |
53 | # elif defined(__sun) | |
54 | /* Solaris (and SunOS?) defines IOV_MAX instead */ | |
55 | # ifndef IOV_MAX | |
56 | # define RB_UIO_MAXIOV 16 | |
57 | # else | |
58 | # define RB_UIO_MAXIOV IOV_MAX | |
59 | # endif | |
60 | ||
61 | # elif defined(IOV_MAX) | |
62 | # define RB_UIO_MAXIOV IOV_MAX | |
63 | # else | |
64 | # define RB_UIO_MAXIOV 16 | |
65 | # endif | |
66 | #else | |
67 | #define RB_UIO_MAXIOV UIO_MAXIOV | |
68 | #endif | |
69 | #else | |
70 | #define RB_UIO_MAXIOV 16 | |
71 | #endif | |
72 | struct conndata | |
73 | { | |
74 | /* We don't need the host here ? */ | |
75 | struct rb_sockaddr_storage S; | |
76 | struct rb_sockaddr_storage hostaddr; | |
77 | time_t t; | |
78 | CNCB *callback; | |
79 | void *data; | |
80 | /* We'd also add the retry count here when we get to that -- adrian */ | |
81 | }; | |
82 | ||
83 | struct acceptdata | |
84 | { | |
85 | struct rb_sockaddr_storage S; | |
86 | rb_socklen_t addrlen; | |
87 | ACCB *callback; | |
88 | ACPRE *precb; | |
89 | void *data; | |
90 | }; | |
91 | ||
92 | /* Only have open flags for now, could be more later */ | |
93 | #define FLAG_OPEN 0x1 | |
94 | #define IsFDOpen(F) (F->flags & FLAG_OPEN) | |
95 | #define SetFDOpen(F) (F->flags |= FLAG_OPEN) | |
96 | #define ClearFDOpen(F) (F->flags &= ~FLAG_OPEN) | |
97 | ||
98 | ||
99 | struct _fde | |
100 | { | |
101 | /* New-school stuff, again pretty much ripped from squid */ | |
102 | /* | |
103 | * Yes, this gives us only one pending read and one pending write per | |
104 | * filedescriptor. Think though: when do you think we'll need more? | |
105 | */ | |
106 | rb_dlink_node node; | |
107 | int fd; /* So we can use the rb_fde_t as a callback ptr */ | |
108 | uint8_t flags; | |
109 | uint8_t type; | |
110 | int pflags; | |
111 | char *desc; | |
112 | PF *read_handler; | |
113 | void *read_data; | |
114 | PF *write_handler; | |
115 | void *write_data; | |
116 | struct timeout_data *timeout; | |
117 | struct conndata *connect; | |
118 | struct acceptdata *accept; | |
119 | void *ssl; | |
120 | unsigned int handshake_count; | |
121 | unsigned long ssl_errno; | |
122 | }; | |
123 | ||
124 | typedef void (*comm_event_cb_t) (void *); | |
125 | ||
126 | #ifdef USE_TIMER_CREATE | |
127 | typedef struct timer_data | |
128 | { | |
129 | timer_t td_timer_id; | |
130 | comm_event_cb_t td_cb; | |
131 | void *td_udata; | |
132 | int td_repeat; | |
133 | } *comm_event_id; | |
134 | #endif | |
135 | ||
136 | extern rb_dlink_list *rb_fd_table; | |
137 | ||
138 | static inline rb_fde_t * | |
139 | rb_find_fd(int fd) | |
140 | { | |
141 | rb_dlink_list *hlist; | |
142 | rb_dlink_node *ptr; | |
143 | ||
144 | if(rb_unlikely(fd < 0)) | |
145 | return NULL; | |
146 | ||
147 | hlist = &rb_fd_table[rb_hash_fd(fd)]; | |
148 | ||
149 | if(hlist->head == NULL) | |
150 | return NULL; | |
151 | ||
152 | RB_DLINK_FOREACH(ptr, hlist->head) | |
153 | { | |
154 | rb_fde_t *F = ptr->data; | |
155 | if(F->fd == fd) | |
156 | return F; | |
157 | } | |
158 | return NULL; | |
159 | } | |
160 | ||
161 | ||
162 | int rb_setup_fd(rb_fde_t *F); | |
163 | void rb_connect_callback(rb_fde_t *F, int status); | |
164 | ||
165 | ||
166 | int rb_io_sched_event(struct ev_entry *ev, int when); | |
167 | void rb_io_unsched_event(struct ev_entry *ev); | |
168 | int rb_io_supports_event(void); | |
169 | void rb_io_init_event(void); | |
170 | ||
171 | /* epoll versions */ | |
172 | void rb_setselect_epoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data); | |
173 | int rb_init_netio_epoll(void); | |
174 | int rb_select_epoll(long); | |
175 | int rb_setup_fd_epoll(rb_fde_t *F); | |
176 | ||
177 | void rb_epoll_init_event(void); | |
178 | int rb_epoll_sched_event(struct ev_entry *event, int when); | |
179 | void rb_epoll_unsched_event(struct ev_entry *event); | |
180 | int rb_epoll_supports_event(void); | |
181 | ||
182 | ||
183 | /* poll versions */ | |
184 | void rb_setselect_poll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data); | |
185 | int rb_init_netio_poll(void); | |
186 | int rb_select_poll(long); | |
187 | int rb_setup_fd_poll(rb_fde_t *F); | |
188 | ||
189 | /* devpoll versions */ | |
190 | void rb_setselect_devpoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data); | |
191 | int rb_init_netio_devpoll(void); | |
192 | int rb_select_devpoll(long); | |
193 | int rb_setup_fd_devpoll(rb_fde_t *F); | |
194 | ||
195 | /* sigio versions */ | |
196 | void rb_setselect_sigio(rb_fde_t *F, unsigned int type, PF * handler, void *client_data); | |
197 | int rb_init_netio_sigio(void); | |
198 | int rb_select_sigio(long); | |
199 | int rb_setup_fd_sigio(rb_fde_t *F); | |
200 | ||
201 | void rb_sigio_init_event(void); | |
202 | int rb_sigio_sched_event(struct ev_entry *event, int when); | |
203 | void rb_sigio_unsched_event(struct ev_entry *event); | |
204 | int rb_sigio_supports_event(void); | |
205 | ||
206 | ||
207 | /* ports versions */ | |
208 | void rb_setselect_ports(rb_fde_t *F, unsigned int type, PF * handler, void *client_data); | |
209 | int rb_init_netio_ports(void); | |
210 | int rb_select_ports(long); | |
211 | int rb_setup_fd_ports(rb_fde_t *F); | |
212 | ||
213 | void rb_ports_init_event(void); | |
214 | int rb_ports_sched_event(struct ev_entry *event, int when); | |
215 | void rb_ports_unsched_event(struct ev_entry *event); | |
216 | int rb_ports_supports_event(void); | |
217 | ||
218 | ||
219 | /* kqueue versions */ | |
220 | void rb_setselect_kqueue(rb_fde_t *F, unsigned int type, PF * handler, void *client_data); | |
221 | int rb_init_netio_kqueue(void); | |
222 | int rb_select_kqueue(long); | |
223 | int rb_setup_fd_kqueue(rb_fde_t *F); | |
224 | ||
225 | void rb_kqueue_init_event(void); | |
226 | int rb_kqueue_sched_event(struct ev_entry *event, int when); | |
227 | void rb_kqueue_unsched_event(struct ev_entry *event); | |
228 | int rb_kqueue_supports_event(void); | |
229 | ||
230 | ||
231 | /* select versions */ | |
232 | void rb_setselect_select(rb_fde_t *F, unsigned int type, PF * handler, void *client_data); | |
233 | int rb_init_netio_select(void); | |
234 | int rb_select_select(long); | |
235 | int rb_setup_fd_select(rb_fde_t *F); | |
236 | ||
237 | /* win32 versions */ | |
238 | void rb_setselect_win32(rb_fde_t *F, unsigned int type, PF * handler, void *client_data); | |
239 | int rb_init_netio_win32(void); | |
240 | int rb_select_win32(long); | |
241 | int rb_setup_fd_win32(rb_fde_t *F); | |
242 | #endif | |
243 |