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
24 * $Id: commio.h 26 2006-09-20 18:02:06Z spb $
27 #ifndef INCLUDED_commio_h
28 #define INCLUDED_commio_h
32 #include "ircd_defs.h"
34 /* Callback for completed IO events */
35 typedef void PF(int fd
, void *);
37 /* Callback for completed connections */
38 /* int fd, int status, void * */
39 typedef void CNCB(int fd
, int, void *);
41 #define FD_DESC_SZ 128 /* hostlen + comment */
78 typedef struct _fde fde_t
;
81 extern int highest_fd
;
88 /* New-school stuff, again pretty much ripped from squid */
90 * Yes, this gives us only one pending read and one pending write per
91 * filedescriptor. Think though: when do you think we'll need more?
93 int fd
; /* So we can use the fde_t as a callback ptr */
95 fdlist_t list
; /* Which list this FD should sit on */
96 int comm_index
; /* where in the poll list we live */
97 char desc
[FD_DESC_SZ
];
107 time_t flush_timeout
;
108 struct DNSQuery
*dns_query
;
112 unsigned int close_request
:1;
113 unsigned int write_daemon
:1;
114 unsigned int closing
:1;
115 unsigned int socket_eof
:1;
116 unsigned int nolinger
:1;
117 unsigned int nonblocking
:1;
119 unsigned int called_connect
:1;
124 struct irc_sockaddr_storage hostaddr
;
127 /* We'd also add the retry count here when we get to that -- adrian */
134 extern fde_t
*fd_table
;
136 void fdlist_init(void);
138 extern void comm_open(int, unsigned int, const char *);
139 extern void comm_close(int);
140 extern void comm_dump(struct Client
*source_p
);
142 extern void comm_note(int fd
, const char *format
, ...);
144 extern void comm_note(int fd
, const char *format
, ...) __attribute__ ((format(printf
, 2, 3)));
151 /* Size of a read buffer */
152 #define READBUF_SIZE 16384 /* used by src/packet.c and src/s_serv.c */
155 #define COMM_SELECT_READ 0x1
156 #define COMM_SELECT_WRITE 0x2
157 #define COMM_SELECT_RETRY 0x4
158 extern int readcalls
;
159 extern const char *const NONB_ERROR_MSG
;
160 extern const char *const SETBUF_ERROR_MSG
;
162 extern void comm_close_all(void);
163 extern int comm_set_nb(int);
164 extern int comm_set_buffers(int, int);
166 extern int comm_get_sockerr(int);
167 extern int ignoreErrno(int ierrno
);
169 extern void comm_settimeout(int fd
, time_t, PF
*, void *);
170 extern void comm_setflush(int fd
, time_t, PF
*, void *);
171 extern void comm_checktimeouts(void *);
172 extern void comm_connect_tcp(int fd
, const char *, u_short
,
173 struct sockaddr
*, int, CNCB
*, void *, int, int);
174 extern const char *comm_errstr(int status
);
175 extern int comm_socket(int family
, int sock_type
, int proto
, const char *note
);
176 extern int comm_accept(int fd
, struct sockaddr
*pn
, socklen_t
*addrlen
);
178 /* These must be defined in the network IO loop code of your choice */
179 extern void comm_setselect(int fd
, fdlist_t list
, unsigned int type
,
180 PF
* handler
, void *client_data
, time_t timeout
);
181 extern void init_netio(void);
182 extern int read_message(time_t, unsigned char);
183 extern int comm_select(unsigned long);
184 extern int disable_sock_options(int);
186 extern void mangle_mapped_sockaddr(struct sockaddr
*in
);
188 #define mangle_mapped_sockaddr(x)
192 #endif /* INCLUDED_commio_h */