]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/Connection.cc
4401dab5bd1efdbf59e5516dfb025e7c2c441f69
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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.
10 #include "CachePeer.h"
13 #include "comm/Connection.h"
16 #include "neighbors.h"
17 #include "security/NegotiationHistory.h"
18 #include "SquidConfig.h"
19 #include "SquidTime.h"
24 Comm::IsConnOpen(const Comm::ConnectionPointer
&conn
)
26 return conn
!= NULL
&& conn
->isOpen();
29 Comm::Connection::Connection() :
34 flags(COMM_NONBLOCKING
),
36 startTime_(squid_curtime
),
39 *rfc931
= 0; // quick init the head. the rest does not matter.
42 static int64_t lost_conn
= 0;
43 Comm::Connection::~Connection()
46 debugs(5, 4, "BUG #3329: Orphan Comm::Connection: " << *this);
47 debugs(5, 4, "NOTE: " << ++lost_conn
<< " Orphans since last started.");
51 cbdataReferenceDone(peer_
);
56 Comm::ConnectionPointer
57 Comm::Connection::copyDetails() const
59 ConnectionPointer c
= new Comm::Connection
;
61 c
->setAddrs(local
, remote
);
62 c
->peerType
= peerType
;
66 c
->startTime_
= startTime_
;
68 // ensure FD is not open in the new copy.
71 // ensure we have a cbdata reference to peer_ not a straight ptr copy.
72 c
->peer_
= cbdataReference(getPeer());
78 Comm::Connection::close()
87 Comm::Connection::noteClosure()
91 if (CachePeer
*p
=getPeer())
97 Comm::Connection::getPeer() const
99 if (cbdataReferenceValid(peer_
))
106 Comm::Connection::setPeer(CachePeer
*p
)
108 /* set to self. nothing to do. */
112 cbdataReferenceDone(peer_
);
114 peer_
= cbdataReference(p
);
119 Comm::Connection::timeLeft(const time_t idleTimeout
) const
121 if (!Config
.Timeout
.pconnLifetime
)
124 const time_t lifeTimeLeft
= lifeTime() < Config
.Timeout
.pconnLifetime
? Config
.Timeout
.pconnLifetime
- lifeTime() : 1;
125 return min(lifeTimeLeft
, idleTimeout
);
128 Security::NegotiationHistory
*
129 Comm::Connection::tlsNegotiations()
132 tlsHistory
= new Security::NegotiationHistory
;
137 Comm::Connection::connectTimeout(const time_t fwdStart
) const
139 // a connection opening timeout (ignoring forwarding time limits for now)
140 const CachePeer
*peer
= getPeer();
141 const time_t ctimeout
= peer
? peerConnectTimeout(peer
) : Config
.Timeout
.connect
;
143 // time we have left to finish the whole forwarding process
144 const time_t fwdTimeLeft
= FwdState::ForwardTimeout(fwdStart
);
146 // The caller decided to connect. If there is no time left, to protect
147 // connecting code from trying to establish a connection while a zero (i.e.,
148 // "immediate") timeout notification is firing, ensure a positive timeout.
149 // XXX: This hack gives some timed-out forwarding sequences more time than
150 // some sequences that have not quite reached the forwarding timeout yet!
151 const time_t ftimeout
= fwdTimeLeft
? fwdTimeLeft
: 5; // seconds
153 return min(ctimeout
, ftimeout
);
157 operator << (std::ostream
&os
, const Comm::Connection
&conn
)
159 os
<< "local=" << conn
.local
<< " remote=" << conn
.remote
;
161 os
<< ' ' << hier_code_str
[conn
.peerType
];
163 os
<< " FD " << conn
.fd
;
164 if (conn
.flags
!= COMM_UNSET
)
165 os
<< " flags=" << conn
.flags
;
168 os
<< " IDENT::" << conn
.rfc931
;