| 19 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
|
* USA |
| 21 |
|
* |
| 22 |
< |
* $Id: fdlist.c,v 7.55 2005/09/26 02:21:44 adx Exp $ |
| 22 |
> |
* $Id$ |
| 23 |
|
*/ |
| 24 |
+ |
|
| 25 |
|
#include "stdinc.h" |
| 26 |
|
#include "fdlist.h" |
| 27 |
|
#include "client.h" /* struct Client */ |
| 27 |
– |
#include "common.h" |
| 28 |
|
#include "event.h" |
| 29 |
|
#include "ircd.h" /* GlobalSetOptions */ |
| 30 |
|
#include "irc_string.h" |
| 31 |
– |
#include "rlimits.h" |
| 31 |
|
#include "s_bsd.h" /* comm_setselect */ |
| 32 |
< |
#include "s_conf.h" /* ServerInfo */ |
| 32 |
> |
#include "conf.h" /* ServerInfo */ |
| 33 |
|
#include "send.h" |
| 34 |
|
#include "memory.h" |
| 35 |
|
#include "numeric.h" |
| 36 |
+ |
#include "s_misc.h" |
| 37 |
+ |
#include "irc_res.h" |
| 38 |
|
|
| 39 |
|
fde_t *fd_hash[FD_HASH_SIZE]; |
| 40 |
|
fde_t *fd_next_in_loop = NULL; |
| 75 |
|
void |
| 76 |
|
recalc_fdlimit(void *unused) |
| 77 |
|
{ |
| 77 |
– |
#ifdef _WIN32 |
| 78 |
– |
/* this is what WSAStartup() usually returns. Even though they say |
| 79 |
– |
* the value is for compatibility reasons and should be ignored, |
| 80 |
– |
* we actually can create even more sockets... */ |
| 81 |
– |
hard_fdlimit = 32767; |
| 82 |
– |
#else |
| 78 |
|
int fdmax; |
| 79 |
|
struct rlimit limit; |
| 80 |
|
|
| 81 |
< |
if (!getrlimit(RLIMIT_FD_MAX, &limit)) |
| 81 |
> |
if (!getrlimit(RLIMIT_NOFILE, &limit)) |
| 82 |
|
{ |
| 83 |
|
limit.rlim_cur = limit.rlim_max; |
| 84 |
< |
setrlimit(RLIMIT_FD_MAX, &limit); |
| 84 |
> |
setrlimit(RLIMIT_NOFILE, &limit); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
fdmax = getdtablesize(); |
| 96 |
|
|
| 97 |
|
if (fdmax != hard_fdlimit) |
| 98 |
|
execute_callback(fdlimit_cb, fdmax); |
| 104 |
– |
#endif |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
static inline unsigned int |
| 102 |
|
hash_fd(int fd) |
| 103 |
|
{ |
| 110 |
– |
#ifdef _WIN32 |
| 111 |
– |
return ((((unsigned) fd) >> 2) % FD_HASH_SIZE); |
| 112 |
– |
#else |
| 104 |
|
return (((unsigned) fd) % FD_HASH_SIZE); |
| 114 |
– |
#endif |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
fde_t * |
| 152 |
|
if (F->flags.is_socket) |
| 153 |
|
comm_setselect(F, COMM_SELECT_WRITE | COMM_SELECT_READ, NULL, NULL, 0); |
| 154 |
|
|
| 155 |
< |
if (F->dns_query != NULL) |
| 166 |
< |
{ |
| 167 |
< |
delete_resolver_queries(F->dns_query); |
| 168 |
< |
MyFree(F->dns_query); |
| 169 |
< |
} |
| 155 |
> |
delete_resolver_queries(F); |
| 156 |
|
|
| 157 |
|
#ifdef HAVE_LIBCRYPTO |
| 158 |
|
if (F->ssl) |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
/* Unlike squid, we're actually closing the FD here! -- adrian */ |
| 188 |
– |
#ifdef _WIN32 |
| 189 |
– |
if (F->flags.is_socket) |
| 190 |
– |
closesocket(F->fd); |
| 191 |
– |
else |
| 192 |
– |
CloseHandle((HANDLE)F->fd); |
| 193 |
– |
#else |
| 174 |
|
close(F->fd); |
| 195 |
– |
#endif |
| 175 |
|
number_fd--; |
| 176 |
< |
#ifdef INVARIANTS |
| 177 |
< |
memset(F, '\0', sizeof(fde_t)); |
| 199 |
< |
#endif |
| 176 |
> |
|
| 177 |
> |
memset(F, 0, sizeof(fde_t)); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
/* |
| 217 |
|
/* Make sure stdio descriptors (0-2) and profiler descriptor (3) |
| 218 |
|
* always go somewhere harmless. Use -foreground for profiling |
| 219 |
|
* or executing from gdb */ |
| 242 |
– |
#ifndef _WIN32 |
| 220 |
|
void |
| 221 |
|
close_standard_fds(void) |
| 222 |
|
{ |
| 225 |
|
for (i = 0; i < LOWEST_SAFE_FD; i++) |
| 226 |
|
{ |
| 227 |
|
close(i); |
| 228 |
< |
if (open(PATH_DEVNULL, O_RDWR) < 0) |
| 228 |
> |
if (open("/dev/null", O_RDWR) < 0) |
| 229 |
|
exit(-1); /* we're hosed if we can't even open /dev/null */ |
| 230 |
|
} |
| 231 |
|
} |
| 255 |
– |
#endif |
| 232 |
|
|
| 233 |
|
void |
| 234 |
|
close_fds(fde_t *one) |
| 239 |
|
for (i = 0; i < FD_HASH_SIZE; i++) |
| 240 |
|
for (F = fd_hash[i]; F != NULL; F = F->hnext) |
| 241 |
|
if (F != one) |
| 266 |
– |
{ |
| 267 |
– |
#ifdef _WIN32 |
| 268 |
– |
if (F->flags.is_socket) |
| 269 |
– |
closesocket(F->fd); |
| 270 |
– |
else |
| 271 |
– |
CloseHandle((HANDLE)F->fd); |
| 272 |
– |
#else |
| 242 |
|
close(F->fd); |
| 274 |
– |
#endif |
| 275 |
– |
} |
| 243 |
|
} |