]>
Commit | Line | Data |
---|---|---|
be335c22 | 1 | |
d892b155 | 2 | /* |
a7c05555 | 3 | * $Id: fd.cc,v 1.17 1998/01/31 05:31:57 wessels Exp $ |
d892b155 | 4 | * |
5 | * DEBUG: section 51 Filedescriptor Functions | |
6 | * AUTHOR: Duane Wessels | |
7 | * | |
8 | * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ | |
9 | * -------------------------------------------------------- | |
10 | * | |
11 | * Squid is the result of efforts by numerous individuals from the | |
12 | * Internet community. Development is led by Duane Wessels of the | |
13 | * National Laboratory for Applied Network Research and funded by | |
14 | * the National Science Foundation. | |
15 | * | |
16 | * This program is free software; you can redistribute it and/or modify | |
17 | * it under the terms of the GNU General Public License as published by | |
18 | * the Free Software Foundation; either version 2 of the License, or | |
19 | * (at your option) any later version. | |
20 | * | |
21 | * This program is distributed in the hope that it will be useful, | |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | * GNU General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU General Public License | |
27 | * along with this program; if not, write to the Free Software | |
28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
29 | * | |
30 | */ | |
31 | ||
a7870688 | 32 | #include "squid.h" |
33 | ||
f5b8bbc4 | 34 | static void fdUpdateBiggest(int fd, unsigned int status); |
a7870688 | 35 | |
36 | static void | |
37 | fdUpdateBiggest(int fd, unsigned int status) | |
38 | { | |
39 | if (fd < Biggest_FD) | |
40 | return; | |
edd1e84c | 41 | assert(fd < Squid_MaxFD); |
a7870688 | 42 | if (fd > Biggest_FD) { |
edd1e84c | 43 | assert(status == FD_OPEN); |
44 | Biggest_FD = fd; | |
a7870688 | 45 | return; |
46 | } | |
47 | /* if we are here, then fd == Biggest_FD */ | |
edd1e84c | 48 | assert(status == FD_CLOSE); |
a7870688 | 49 | while (fd_table[Biggest_FD].open != FD_OPEN) |
50 | Biggest_FD--; | |
51 | } | |
52 | ||
53 | void | |
4f92c80c | 54 | fd_close(int fd) |
a7870688 | 55 | { |
76f87348 | 56 | fde *F = &fd_table[fd]; |
57 | if (F->type == FD_FILE) { | |
58 | assert(F->read_handler == NULL); | |
59 | assert(F->write_handler == NULL); | |
9e4ad609 | 60 | } |
76f87348 | 61 | fdUpdateBiggest(fd, F->open = FD_CLOSE); |
2524a4d5 | 62 | Number_FD--; |
76f87348 | 63 | memset(F, '\0', sizeof(fde)); |
64 | F->timeout = 0; | |
a7870688 | 65 | } |
66 | ||
67 | void | |
68 | fd_open(int fd, unsigned int type, const char *desc) | |
69 | { | |
76f87348 | 70 | fde *F = &fd_table[fd]; |
ceab4c00 | 71 | assert(fd >= 0); |
76f87348 | 72 | assert(F->open == 0); |
a7c05555 | 73 | debug(51, 3) ("fd_open FD %d %s\n", fd, desc); |
76f87348 | 74 | F->type = type; |
75 | fdUpdateBiggest(fd, F->open = FD_OPEN); | |
a7870688 | 76 | if (desc) |
76f87348 | 77 | xstrncpy(F->desc, desc, FD_DESC_SZ); |
2524a4d5 | 78 | Number_FD++; |
a7870688 | 79 | } |
80 | ||
81 | void | |
82 | fd_note(int fd, const char *s) | |
83 | { | |
76f87348 | 84 | fde *F = &fd_table[fd]; |
85 | xstrncpy(F->desc, s, FD_DESC_SZ); | |
a7870688 | 86 | } |
4f92c80c | 87 | |
88 | void | |
89 | fd_bytes(int fd, int len, unsigned int type) | |
90 | { | |
76f87348 | 91 | fde *F = &fd_table[fd]; |
4f92c80c | 92 | if (len < 0) |
93 | return; | |
365e5b34 | 94 | assert(type == FD_READ || type == FD_WRITE); |
4f92c80c | 95 | if (type == FD_READ) |
76f87348 | 96 | F->bytes_read += len; |
4f92c80c | 97 | else |
76f87348 | 98 | F->bytes_written += len; |
4f92c80c | 99 | } |
f17936ab | 100 | |
101 | void | |
102 | fdFreeMemory(void) | |
103 | { | |
9e4ad609 | 104 | safe_free(fd_table); |
105 | } | |
106 | ||
107 | void | |
108 | fdDumpOpen(void) | |
109 | { | |
110 | int i; | |
76f87348 | 111 | fde *F; |
9e4ad609 | 112 | for (i = 0; i < Squid_MaxFD; i++) { |
76f87348 | 113 | F = &fd_table[i]; |
114 | if (!F->open) | |
9e4ad609 | 115 | continue; |
116 | if (i == fileno(debug_log)) | |
117 | continue; | |
d892b155 | 118 | debug(51, 1) ("Open FD %4d %s\n", i, F->desc); |
9e4ad609 | 119 | } |
f17936ab | 120 | } |