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