]> jfr.im git - irc/rqf/shadowircd.git/blame - libcharybdis/commio.h
[svn] - update config files
[irc/rqf/shadowircd.git] / libcharybdis / commio.h
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * commio.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-2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
6fcb8629 24 * $Id: commio.h 3354 2007-04-03 09:21:31Z nenolod $
212380e3 25 */
26
27#ifndef INCLUDED_commio_h
28#define INCLUDED_commio_h
29
30#include "setup.h"
31#include "config.h"
32#include "ircd_defs.h"
e70f8e92 33#include "tools.h"
212380e3 34
35/* Callback for completed IO events */
36typedef void PF(int fd, void *);
37
38/* Callback for completed connections */
39/* int fd, int status, void * */
40typedef void CNCB(int fd, int, void *);
41
42#define FD_DESC_SZ 128 /* hostlen + comment */
43
44
45/* FD type values */
46enum
47{
48 FD_NONE,
49 FD_LOG,
50 FD_FILE,
51 FD_FILECLOSE,
52 FD_SOCKET,
53 FD_PIPE,
54 FD_UNKNOWN
55};
56
57enum
58{
59 COMM_OK,
60 COMM_ERR_BIND,
61 COMM_ERR_DNS,
62 COMM_ERR_TIMEOUT,
63 COMM_ERR_CONNECT,
64 COMM_ERROR,
65 COMM_ERR_MAX
66};
67
68typedef enum fdlist_t
69{
70 FDLIST_NONE,
71 FDLIST_SERVICE,
72 FDLIST_SERVER,
73 FDLIST_IDLECLIENT,
74 FDLIST_BUSYCLIENT,
75 FDLIST_MAX
76}
77fdlist_t;
78
79typedef struct _fde fde_t;
80
81
82extern int highest_fd;
83extern int number_fd;
84
85struct Client;
86
87struct _fde
88{
89 /* New-school stuff, again pretty much ripped from squid */
90 /*
91 * Yes, this gives us only one pending read and one pending write per
92 * filedescriptor. Think though: when do you think we'll need more?
93 */
94 int fd; /* So we can use the fde_t as a callback ptr */
95 int type;
96 fdlist_t list; /* Which list this FD should sit on */
97 int comm_index; /* where in the poll list we live */
98 char desc[FD_DESC_SZ];
99 PF *read_handler;
100 void *read_data;
101 PF *write_handler;
102 void *write_data;
103 PF *timeout_handler;
104 void *timeout_data;
105 time_t timeout;
106 PF *flush_handler;
107 void *flush_data;
108 time_t flush_timeout;
109 struct DNSQuery *dns_query;
110 struct
111 {
112 unsigned int open:1;
113 unsigned int close_request:1;
114 unsigned int write_daemon:1;
115 unsigned int closing:1;
116 unsigned int socket_eof:1;
117 unsigned int nolinger:1;
118 unsigned int nonblocking:1;
119 unsigned int ipc:1;
120 unsigned int called_connect:1;
121 }
122 flags;
123 struct
124 {
125 struct irc_sockaddr_storage hostaddr;
126 CNCB *callback;
127 void *data;
128 /* We'd also add the retry count here when we get to that -- adrian */
129 }
130 connect;
131 int pflags;
e70f8e92 132 dlink_node node;
212380e3 133};
134
135
212380e3 136void fdlist_init(void);
137
138extern void comm_open(int, unsigned int, const char *);
139extern void comm_close(int);
140extern void comm_dump(struct Client *source_p);
141#ifndef __GNUC__
142extern void comm_note(int fd, const char *format, ...);
143#else
144extern void comm_note(int fd, const char *format, ...) __attribute__ ((format(printf, 2, 3)));
145#endif
146
147#define FB_EOF 0x01
148#define FB_FAIL 0x02
149
150
151/* Size of a read buffer */
152#define READBUF_SIZE 16384 /* used by src/packet.c and src/s_serv.c */
153
154/* Type of IO */
155#define COMM_SELECT_READ 0x1
156#define COMM_SELECT_WRITE 0x2
157#define COMM_SELECT_RETRY 0x4
158extern int readcalls;
159extern const char *const NONB_ERROR_MSG;
160extern const char *const SETBUF_ERROR_MSG;
161
162extern void comm_close_all(void);
163extern int comm_set_nb(int);
164extern int comm_set_buffers(int, int);
165
166extern int comm_get_sockerr(int);
167extern int ignoreErrno(int ierrno);
168
169extern void comm_settimeout(int fd, time_t, PF *, void *);
170extern void comm_setflush(int fd, time_t, PF *, void *);
171extern void comm_checktimeouts(void *);
172extern void comm_connect_tcp(int fd, const char *, u_short,
173 struct sockaddr *, int, CNCB *, void *, int, int);
174extern const char *comm_errstr(int status);
175extern int comm_socket(int family, int sock_type, int proto, const char *note);
176extern int comm_accept(int fd, struct sockaddr *pn, socklen_t *addrlen);
177
178/* These must be defined in the network IO loop code of your choice */
179extern void comm_setselect(int fd, fdlist_t list, unsigned int type,
180 PF * handler, void *client_data, time_t timeout);
181extern void init_netio(void);
182extern int read_message(time_t, unsigned char);
183extern int comm_select(unsigned long);
184extern int disable_sock_options(int);
185#ifdef IPV6
186extern void mangle_mapped_sockaddr(struct sockaddr *in);
187#else
188#define mangle_mapped_sockaddr(x)
189#endif
190
6fcb8629 191extern int comm_get_maxconnections(void);
192
e70f8e92 193extern fde_t *comm_locate_fd(int fd);
212380e3 194
195#endif /* INCLUDED_commio_h */