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