]> git.ipfire.org Git - thirdparty/squid.git/blame - src/fd.cc
Changed error message generated when we read 0 bytes from the FTP
[thirdparty/squid.git] / src / fd.cc
CommitLineData
be335c22 1
d892b155 2/*
0e473d70 3 * $Id: fd.cc,v 1.19 1998/02/02 21:16:24 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 34static void fdUpdateBiggest(int fd, unsigned int status);
a7870688 35
36static void
37fdUpdateBiggest(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) {
6cf028ab 43 if (status != FD_OPEN)
0e473d70 44 debug(51, 1) ("fdUpdateBiggest: status != FD_OPEN\n");
edd1e84c 45 Biggest_FD = fd;
a7870688 46 return;
47 }
48 /* if we are here, then fd == Biggest_FD */
6cf028ab 49 if (status != FD_CLOSE)
0e473d70 50 debug(51, 1) ("fdUpdateBiggest: status != FD_CLOSE\n");
a7870688 51 while (fd_table[Biggest_FD].open != FD_OPEN)
52 Biggest_FD--;
53}
54
55void
4f92c80c 56fd_close(int fd)
a7870688 57{
76f87348 58 fde *F = &fd_table[fd];
59 if (F->type == FD_FILE) {
60 assert(F->read_handler == NULL);
61 assert(F->write_handler == NULL);
9e4ad609 62 }
76f87348 63 fdUpdateBiggest(fd, F->open = FD_CLOSE);
2524a4d5 64 Number_FD--;
76f87348 65 memset(F, '\0', sizeof(fde));
66 F->timeout = 0;
a7870688 67}
68
69void
70fd_open(int fd, unsigned int type, const char *desc)
71{
76f87348 72 fde *F = &fd_table[fd];
ceab4c00 73 assert(fd >= 0);
0e473d70 74 if (F->open != 0) {
6cf028ab 75 debug(51, 1) ("WARNING: Closing open FD %4d\n", fd);
76 fd_close(fd);
77 }
76f87348 78 assert(F->open == 0);
a7c05555 79 debug(51, 3) ("fd_open FD %d %s\n", fd, desc);
76f87348 80 F->type = type;
81 fdUpdateBiggest(fd, F->open = FD_OPEN);
a7870688 82 if (desc)
76f87348 83 xstrncpy(F->desc, desc, FD_DESC_SZ);
2524a4d5 84 Number_FD++;
a7870688 85}
86
87void
88fd_note(int fd, const char *s)
89{
76f87348 90 fde *F = &fd_table[fd];
91 xstrncpy(F->desc, s, FD_DESC_SZ);
a7870688 92}
4f92c80c 93
94void
95fd_bytes(int fd, int len, unsigned int type)
96{
76f87348 97 fde *F = &fd_table[fd];
4f92c80c 98 if (len < 0)
99 return;
365e5b34 100 assert(type == FD_READ || type == FD_WRITE);
4f92c80c 101 if (type == FD_READ)
76f87348 102 F->bytes_read += len;
4f92c80c 103 else
76f87348 104 F->bytes_written += len;
4f92c80c 105}
f17936ab 106
107void
108fdFreeMemory(void)
109{
9e4ad609 110 safe_free(fd_table);
111}
112
113void
114fdDumpOpen(void)
115{
116 int i;
76f87348 117 fde *F;
9e4ad609 118 for (i = 0; i < Squid_MaxFD; i++) {
76f87348 119 F = &fd_table[i];
120 if (!F->open)
9e4ad609 121 continue;
122 if (i == fileno(debug_log))
123 continue;
d892b155 124 debug(51, 1) ("Open FD %4d %s\n", i, F->desc);
9e4ad609 125 }
f17936ab 126}