]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fde.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / fde.cc
1 /*
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 /* DEBUG: none FDE */
10
11 #include "squid.h"
12 #include "comm/Read.h"
13 #include "fd.h"
14 #include "fde.h"
15 #include "globals.h"
16 #include "SquidTime.h"
17 #include "Store.h"
18
19 fde *fde::Table = NULL;
20
21 bool
22 fde::readPending(int fdNumber)
23 {
24 if (type == FD_SOCKET)
25 return Comm::MonitorsRead(fdNumber);
26
27 return read_handler ? true : false ;
28 }
29
30 void
31 fde::dumpStats (StoreEntry &dumpEntry, int fdNumber)
32 {
33 if (!flags.open)
34 return;
35
36 #if _SQUID_WINDOWS_
37
38 storeAppendPrintf(&dumpEntry, "%4d 0x%-8lX %-6.6s %4d %7" PRId64 "%c %7" PRId64 "%c %-21s %s\n",
39 fdNumber,
40 win32.handle,
41 #else
42 storeAppendPrintf(&dumpEntry, "%4d %-6.6s %4d %7" PRId64 "%c %7" PRId64 "%c %-21s %s\n",
43 fdNumber,
44 #endif
45 fdTypeStr[type],
46 timeoutHandler != NULL ? (int) (timeout - squid_curtime) : 0,
47 bytes_read,
48 readPending(fdNumber) ? '*' : ' ',
49 bytes_written,
50 write_handler ? '*' : ' ',
51 remoteAddr(),
52 desc);
53 }
54
55 void
56 fde::DumpStats (StoreEntry *dumpEntry)
57 {
58 int i;
59 storeAppendPrintf(dumpEntry, "Active file descriptors:\n");
60 #if _SQUID_WINDOWS_
61
62 storeAppendPrintf(dumpEntry, "%-4s %-10s %-6s %-4s %-7s* %-7s* %-21s %s\n",
63 "File",
64 "Handle",
65 #else
66 storeAppendPrintf(dumpEntry, "%-4s %-6s %-4s %-7s* %-7s* %-21s %s\n",
67 "File",
68 #endif
69 "Type",
70 "Tout",
71 "Nread",
72 "Nwrite",
73 "Remote Address",
74 "Description");
75 #if _SQUID_WINDOWS_
76 storeAppendPrintf(dumpEntry, "---- ---------- ------ ---- -------- -------- --------------------- ------------------------------\n");
77 #else
78 storeAppendPrintf(dumpEntry, "---- ------ ---- -------- -------- --------------------- ------------------------------\n");
79 #endif
80
81 for (i = 0; i < Squid_MaxFD; ++i) {
82 fd_table[i].dumpStats(*dumpEntry, i);
83 }
84 }
85
86 char const *
87 fde::remoteAddr() const
88 {
89 LOCAL_ARRAY(char, buf, MAX_IPSTRLEN );
90
91 if (type != FD_SOCKET)
92 return null_string;
93
94 if ( *ipaddr )
95 snprintf( buf, MAX_IPSTRLEN, "%s:%d", ipaddr, (int)remote_port);
96 else
97 local_addr.toUrl(buf,MAX_IPSTRLEN); // toHostStr does not include port.
98
99 return buf;
100 }
101
102 void
103 fde::noteUse()
104 {
105 ++ pconn.uses;
106 }
107