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