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