]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/Connection.cc
2 * Copyright (C) 1996-2014 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"
15 #include "neighbors.h"
16 #include "SquidConfig.h"
17 #include "SquidTime.h"
21 Comm::IsConnOpen(const Comm::ConnectionPointer
&conn
)
23 return conn
!= NULL
&& conn
->isOpen();
26 Comm::Connection::Connection() :
33 flags(COMM_NONBLOCKING
),
35 startTime_(squid_curtime
)
37 *rfc931
= 0; // quick init the head. the rest does not matter.
40 static int64_t lost_conn
= 0;
41 Comm::Connection::~Connection()
44 debugs(5, 4, "BUG #3329: Orphan Comm::Connection: " << *this);
45 debugs(5, 4, "NOTE: " << ++lost_conn
<< " Orphans since last started.");
49 cbdataReferenceDone(peer_
);
52 Comm::ConnectionPointer
53 Comm::Connection::copyDetails() const
55 ConnectionPointer c
= new Comm::Connection
;
57 c
->setAddrs(local
, remote
);
58 c
->peerType
= peerType
;
62 c
->startTime_
= startTime_
;
64 // ensure FD is not open in the new copy.
67 // ensure we have a cbdata reference to peer_ not a straight ptr copy.
68 c
->peer_
= cbdataReference(getPeer());
74 Comm::Connection::close()
79 if (CachePeer
*p
=getPeer())
85 Comm::Connection::getPeer() const
87 if (cbdataReferenceValid(peer_
))
94 Comm::Connection::setPeer(CachePeer
*p
)
96 /* set to self. nothing to do. */
100 cbdataReferenceDone(peer_
);
102 peer_
= cbdataReference(p
);
107 Comm::Connection::timeLeft(const time_t idleTimeout
) const
109 if (!Config
.Timeout
.pconnLifetime
)
112 const time_t lifeTimeLeft
= lifeTime() < Config
.Timeout
.pconnLifetime
? Config
.Timeout
.pconnLifetime
- lifeTime() : 1;
113 return min(lifeTimeLeft
, idleTimeout
);