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