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