]> git.ipfire.org Git - thirdparty/squid.git/blame - src/fd.cc
adding
[thirdparty/squid.git] / src / fd.cc
CommitLineData
a7870688 1#include "squid.h"
2
3static void fdUpdateBiggest _PARAMS((int fd, unsigned int status));
4
5static void
6fdUpdateBiggest(int fd, unsigned int status)
7{
8 if (fd < Biggest_FD)
9 return;
10 if (fd >= Squid_MaxFD) {
11 debug_trap("Running out of file descriptors.\n");
12 return;
13 }
14 if (fd > Biggest_FD) {
15 if (status == FD_OPEN)
16 Biggest_FD = fd;
17 else
18 debug_trap("Biggest_FD inconsistency");
19 return;
20 }
21 /* if we are here, then fd == Biggest_FD */
22 if (status != FD_CLOSE) {
23 debug_trap("re-opening Biggest_FD?");
24 return;
25 }
26 while (fd_table[Biggest_FD].open != FD_OPEN)
27 Biggest_FD--;
28}
29
30void
31fd_close (int fd)
32{
33 FD_ENTRY *fde = &fd_table[fd];
34 fdUpdateBiggest(fd, FD_CLOSE);
35 memset(fde, '\0', sizeof(FD_ENTRY));
36 fde->timeout = 0;
37}
38
39void
40fd_open(int fd, unsigned int type, const char *desc)
41{
42 FD_ENTRY *fde = &fd_table[fd];
43 fde->type = type;
44 fdUpdateBiggest(fd, fde->open = FD_OPEN);
45 if (desc)
46 xstrncpy(fde->desc, desc, FD_DESC_SZ);
47}
48
49void
50fd_note(int fd, const char *s)
51{
52 FD_ENTRY *fde = &fd_table[fd];
53 xstrncpy(fde->desc, s, FD_DESC_SZ);
54}