1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* fdlist.h: The file descriptor list header. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#define FILEIO_V2 |
26 |
|
27 |
#define FD_DESC_SZ 128 /* hostlen + comment */ |
28 |
#define LOWEST_SAFE_FD 4 /* skip stdin, stdout, stderr, and profiler */ |
29 |
|
30 |
enum { |
31 |
COMM_OK, |
32 |
COMM_ERR_BIND, |
33 |
COMM_ERR_DNS, |
34 |
COMM_ERR_TIMEOUT, |
35 |
COMM_ERR_CONNECT, |
36 |
COMM_ERROR, |
37 |
COMM_ERR_MAX |
38 |
}; |
39 |
|
40 |
struct _fde; |
41 |
struct DNSQuery; |
42 |
|
43 |
/* Callback for completed IO events */ |
44 |
typedef void PF(struct _fde *, void *); |
45 |
|
46 |
/* Callback for completed connections */ |
47 |
typedef void CNCB(struct _fde *, int, void *); |
48 |
|
49 |
/* This is to get around the fact that some implementations have ss_len and |
50 |
* others do not |
51 |
*/ |
52 |
struct irc_ssaddr |
53 |
{ |
54 |
struct sockaddr_storage ss; |
55 |
unsigned char ss_len; |
56 |
in_port_t ss_port; |
57 |
}; |
58 |
|
59 |
typedef struct _fde { |
60 |
/* New-school stuff, again pretty much ripped from squid */ |
61 |
/* |
62 |
* Yes, this gives us only one pending read and one pending write per |
63 |
* filedescriptor. Think though: when do you think we'll need more? |
64 |
*/ |
65 |
int fd; /* So we can use the fde_t as a callback ptr */ |
66 |
int comm_index; /* where in the poll list we live */ |
67 |
int evcache; /* current fd events as set up by the underlying I/O */ |
68 |
char desc[FD_DESC_SZ]; |
69 |
PF *read_handler; |
70 |
void *read_data; |
71 |
PF *write_handler; |
72 |
void *write_data; |
73 |
PF *timeout_handler; |
74 |
void *timeout_data; |
75 |
time_t timeout; |
76 |
PF *flush_handler; |
77 |
void *flush_data; |
78 |
time_t flush_timeout; |
79 |
struct DNSQuery *dns_query; |
80 |
struct { |
81 |
unsigned int open:1; |
82 |
unsigned int is_socket:1; |
83 |
#ifdef HAVE_LIBCRYPTO |
84 |
unsigned int pending_read:1; |
85 |
#endif |
86 |
} flags; |
87 |
|
88 |
struct { |
89 |
/* We don't need the host here ? */ |
90 |
struct irc_ssaddr S; |
91 |
struct irc_ssaddr hostaddr; |
92 |
CNCB *callback; |
93 |
void *data; |
94 |
/* We'd also add the retry count here when we get to that -- adrian */ |
95 |
} connect; |
96 |
#ifdef HAVE_LIBCRYPTO |
97 |
SSL *ssl; |
98 |
#endif |
99 |
struct _fde *hnext; |
100 |
} fde_t; |
101 |
|
102 |
#define FD_HASH_SIZE CLIENT_HEAP_SIZE |
103 |
|
104 |
extern int number_fd; |
105 |
extern int hard_fdlimit; |
106 |
extern fde_t *fd_hash[]; |
107 |
extern fde_t *fd_next_in_loop; |
108 |
extern struct Callback *fdlimit_cb; |
109 |
|
110 |
extern void fdlist_init(void); |
111 |
extern fde_t *lookup_fd(int); |
112 |
extern void fd_open(fde_t *, int, int, const char *); |
113 |
extern void fd_close(fde_t *); |
114 |
#ifndef __GNUC__ |
115 |
extern void fd_note(fde_t *, const char *format, ...); |
116 |
#else |
117 |
extern void fd_note(fde_t *, const char *format, ...) |
118 |
__attribute__((format (printf, 2, 3))); |
119 |
#endif |
120 |
extern void close_standard_fds(void); |
121 |
extern void close_fds(fde_t *); |
122 |
extern void recalc_fdlimit(void *); |