Clean a bit - to be continued...
[seven-1.x.git] / libseven / commio.h
blob0cdf4db3208409b16fda61eee97daa438beabbcb
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * commio.h: A header for the network subsystem.
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
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.
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.
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
26 #ifndef INCLUDED_commio_h
27 #define INCLUDED_commio_h
29 #include "setup.h"
30 #include "config.h"
31 #include "ircd_defs.h"
33 /* Callback for completed IO events */
34 typedef void PF(int fd, void *);
36 /* Callback for completed connections */
37 /* int fd, int status, void * */
38 typedef void CNCB(int fd, int, void *);
40 #define FD_DESC_SZ 128 /* hostlen + comment */
43 /* FD type values */
44 enum
46 FD_NONE,
47 FD_LOG,
48 FD_FILE,
49 FD_FILECLOSE,
50 FD_SOCKET,
51 FD_PIPE,
52 FD_UNKNOWN
55 enum
57 COMM_OK,
58 COMM_ERR_BIND,
59 COMM_ERR_DNS,
60 COMM_ERR_TIMEOUT,
61 COMM_ERR_CONNECT,
62 COMM_ERROR,
63 COMM_ERR_MAX
66 typedef enum fdlist_t
68 FDLIST_NONE,
69 FDLIST_SERVICE,
70 FDLIST_SERVER,
71 FDLIST_IDLECLIENT,
72 FDLIST_BUSYCLIENT,
73 FDLIST_MAX
75 fdlist_t;
77 typedef struct _fde fde_t;
80 extern int highest_fd;
81 extern int number_fd;
83 struct Client;
85 struct _fde
87 /* New-school stuff, again pretty much ripped from squid */
89 * Yes, this gives us only one pending read and one pending write per
90 * filedescriptor. Think though: when do you think we'll need more?
92 int fd; /* So we can use the fde_t as a callback ptr */
93 int type;
94 fdlist_t list; /* Which list this FD should sit on */
95 int comm_index; /* where in the poll list we live */
96 char desc[FD_DESC_SZ];
97 PF *read_handler;
98 void *read_data;
99 PF *write_handler;
100 void *write_data;
101 PF *timeout_handler;
102 void *timeout_data;
103 time_t timeout;
104 PF *flush_handler;
105 void *flush_data;
106 time_t flush_timeout;
107 struct DNSQuery *dns_query;
108 struct
110 unsigned int open:1;
111 unsigned int close_request:1;
112 unsigned int write_daemon:1;
113 unsigned int closing:1;
114 unsigned int socket_eof:1;
115 unsigned int nolinger:1;
116 unsigned int nonblocking:1;
117 unsigned int ipc:1;
118 unsigned int called_connect:1;
120 flags;
121 struct
123 struct irc_sockaddr_storage hostaddr;
124 CNCB *callback;
125 void *data;
126 /* We'd also add the retry count here when we get to that -- adrian */
128 connect;
129 int pflags;
133 extern fde_t *fd_table;
135 void fdlist_init(void);
137 extern void comm_open(int, unsigned int, const char *);
138 extern void comm_close(int);
139 extern void comm_dump(struct Client *source_p);
140 #ifndef __GNUC__
141 extern void comm_note(int fd, const char *format, ...);
142 #else
143 extern void comm_note(int fd, const char *format, ...) __attribute__ ((format(printf, 2, 3)));
144 #endif
146 #define FB_EOF 0x01
147 #define FB_FAIL 0x02
150 /* Size of a read buffer */
151 #define READBUF_SIZE 16384 /* used by src/packet.c and src/s_serv.c */
153 /* Type of IO */
154 #define COMM_SELECT_READ 0x1
155 #define COMM_SELECT_WRITE 0x2
156 #define COMM_SELECT_RETRY 0x4
157 extern int readcalls;
158 extern const char *const NONB_ERROR_MSG;
159 extern const char *const SETBUF_ERROR_MSG;
161 extern void comm_close_all(void);
162 extern int comm_set_nb(int);
163 extern int comm_set_buffers(int, int);
165 extern int comm_get_sockerr(int);
166 extern int ignoreErrno(int ierrno);
168 extern void comm_settimeout(int fd, time_t, PF *, void *);
169 extern void comm_setflush(int fd, time_t, PF *, void *);
170 extern void comm_checktimeouts(void *);
171 extern void comm_connect_tcp(int fd, const char *, u_short,
172 struct sockaddr *, int, CNCB *, void *, int, int);
173 extern const char *comm_errstr(int status);
174 extern int comm_socket(int family, int sock_type, int proto, const char *note);
175 extern int comm_accept(int fd, struct sockaddr *pn, socklen_t *addrlen);
177 /* These must be defined in the network IO loop code of your choice */
178 extern void comm_setselect(int fd, fdlist_t list, unsigned int type,
179 PF * handler, void *client_data, time_t timeout);
180 extern void init_netio(void);
181 extern int read_message(time_t, unsigned char);
182 extern int comm_select(unsigned long);
183 extern int disable_sock_options(int);
184 #ifdef IPV6
185 extern void mangle_mapped_sockaddr(struct sockaddr *in);
186 #else
187 #define mangle_mapped_sockaddr(x)
188 #endif
191 #endif /* INCLUDED_commio_h */