]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HierarchyLogEntry.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / HierarchyLogEntry.h
1 /*
2 * Copyright (C) 1996-2018 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 #ifndef SQUID_HTTPHIERARCHYLOGENTRY_H
10 #define SQUID_HTTPHIERARCHYLOGENTRY_H
11
12 #include "comm/Connection.h"
13 #include "enums.h"
14 #include "hier_code.h"
15 #include "http/StatusCode.h"
16 #include "lookup_t.h"
17 #include "PingData.h"
18 #include "rfc2181.h"
19
20 /// Maintains peer selection details and peer I/O stats.
21 /// Here, "peer" is an origin server or CachePeer.
22 class HierarchyLogEntry
23 {
24
25 public:
26 HierarchyLogEntry();
27
28 /// Start recording new origin server or cache peer connection details.
29 /// Call this when trying to connect to a peer.
30 void resetPeerNotes(const Comm::ConnectionPointer &server, const char *requestedHost);
31
32 /// Account for a TCP peer read. Maintains peer response time stats (%<pt).
33 /// Call this after each successful peer socket read(2).
34 void notePeerRead();
35
36 /// Account for a TCP peer write. Maintains peer response time stats (%<pt).
37 /// Call this after each peer socket write(2), including failed ones.
38 void notePeerWrite();
39
40 /// Start recording total time spent communicating with peers
41 void startPeerClock();
42 /**
43 * Record total time spent communicating with peers
44 * \param force whether to overwrite old recorded value if any
45 */
46 void stopPeerClock(const bool force);
47
48 /// Estimates response generation and sending delay at the last peer.
49 /// \returns whether the estimate (stored in `responseTime`) is available.
50 bool peerResponseTime(struct timeval &responseTime);
51
52 /// Estimates the total time spent communicating with peers.
53 /// \returns whether the estimate (stored in `responseTime`) is available.
54 bool totalResponseTime(struct timeval &responseTime);
55
56 public:
57 hier_code code;
58 char host[SQUIDHOSTNAMELEN];
59 ping_data ping;
60 char cd_host[SQUIDHOSTNAMELEN]; /* the host of selected by cd peer */
61 lookup_t cd_lookup; /* cd prediction: none, miss, hit */
62 int n_choices; /* #peers we selected from (cd only) */
63 int n_ichoices; /* #peers with known rtt we selected from (cd only) */
64
65 struct timeval peer_select_start;
66
67 struct timeval store_complete_stop;
68
69 Http::StatusCode peer_reply_status; ///< last HTTP status code received
70 Comm::ConnectionPointer tcpServer; ///< TCP/IP level details of the last peer/server connection
71 int64_t bodyBytesRead; ///< number of body bytes received from the next hop or -1
72
73 private:
74 void clearPeerNotes();
75
76 timeval firstConnStart_; ///< first connection use among all peers
77 struct timeval peer_last_read_; ///< time of the last read from the last peer
78 struct timeval peer_last_write_; ///< time of the last write to the last peer
79 struct timeval totalResponseTime_; ///< cumulative for all peers
80 };
81
82 #endif /* SQUID_HTTPHIERARCHYLOGENTRY_H */
83