fde.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 = nullptr;
20 
21 bool
22 fde::readPending(int fdNumber) const
23 {
24  if (type == FD_SOCKET)
25  return Comm::MonitorsRead(fdNumber);
26 
27  return read_handler != nullptr;
28 }
29 
30 void
31 fde::dumpStats(StoreEntry &dumpEntry, int fdNumber) const
32 {
33  if (!flags.open)
34  return;
35 
36 #if _SQUID_WINDOWS_
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 ? (int) (timeout - squid_curtime) : 0,
46  bytes_read,
47  readPending(fdNumber) ? '*' : ' ',
49  write_handler ? '*' : ' ',
50  remoteAddr(),
51  desc);
52 }
53 
54 void
56 {
57  storeAppendPrintf(dumpEntry, "Active file descriptors:\n");
58 #if _SQUID_WINDOWS_
59  storeAppendPrintf(dumpEntry, "%-4s %-10s %-6s %-4s %-7s* %-7s* %-21s %s\n",
60  "File",
61  "Handle",
62 #else
63  storeAppendPrintf(dumpEntry, "%-4s %-6s %-4s %-7s* %-7s* %-21s %s\n",
64  "File",
65 #endif
66  "Type",
67  "Tout",
68  "Nread",
69  "Nwrite",
70  "Remote Address",
71  "Description");
72 #if _SQUID_WINDOWS_
73  storeAppendPrintf(dumpEntry, "---- ---------- ------ ---- -------- -------- --------------------- ------------------------------\n");
74 #else
75  storeAppendPrintf(dumpEntry, "---- ------ ---- -------- -------- --------------------- ------------------------------\n");
76 #endif
77 
78  for (int i = 0; i < Squid_MaxFD; ++i) {
79  fde::Table[i].dumpStats(*dumpEntry, i);
80  }
81 }
82 
83 char const *
85 {
86  static char buf[MAX_IPSTRLEN+7]; // 7 = length of ':port' strings
87  *buf = 0;
88 
89  if (type == FD_SOCKET) {
90  if (*ipaddr)
91  snprintf(buf, sizeof(buf), "%s:%u", ipaddr, remote_port);
92  else
93  local_addr.toUrl(buf, sizeof(buf)); // toHostStr does not include port.
94  }
95 
96  return buf;
97 }
98 
int Squid_MaxFD
struct fde::_fde_flags flags
static void DumpStats(StoreEntry *)
Definition: fde.cc:55
Ip::Address local_addr
Definition: fde.h:86
unsigned short remote_port
Definition: fde.h:84
int i
Definition: membanger.c:49
#define PRId64
Definition: types.h:110
int64_t bytes_written
Definition: fde.h:112
unsigned int type
Definition: fde.h:83
const char * fdTypeStr[]
Definition: fd.cc:40
char const * remoteAddr() const
Definition: fde.cc:84
PF * write_handler
Definition: fde.h:128
time_t squid_curtime
Definition: stub_time.cc:17
int64_t bytes_read
Definition: fde.h:111
PF * read_handler
Definition: fde.h:126
bool MonitorsRead(int fd)
whether the FD socket is being monitored for read
Definition: Read.cc:28
char * toUrl(char *buf, unsigned int len) const
Definition: Address.cc:892
bool readPending(int) const
Definition: fde.cc:22
void dumpStats(StoreEntry &, int) const
Definition: fde.cc:31
void const char * buf
Definition: stub_helper.cc:16
AsyncCall::Pointer timeoutHandler
Definition: fde.h:130
bool open
Definition: fde.h:96
Definition: fde.h:49
time_t timeout
Definition: fde.h:131
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition: forward.h:23
char ipaddr[MAX_IPSTRLEN]
Definition: fde.h:92
char desc[FD_DESC_SZ]
Definition: fde.h:93
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:904

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors