]> git.ipfire.org Git - thirdparty/squid.git/blame - src/comm/Connection.cc
Fix eCAP issues after rev.14093
[thirdparty/squid.git] / src / comm / Connection.cc
CommitLineData
bbc27441 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
bbc27441
AJ
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
f7f3304a 9#include "squid.h"
a011edee 10#include "CachePeer.h"
cfd66529
AJ
11#include "cbdata.h"
12#include "comm.h"
13#include "comm/Connection.h"
be364179 14#include "fde.h"
e8dca475 15#include "neighbors.h"
c5c06f02 16#include "SquidConfig.h"
be364179 17#include "SquidTime.h"
cfd66529 18
a011edee 19class CachePeer;
97c81191
AJ
20bool
21Comm::IsConnOpen(const Comm::ConnectionPointer &conn)
22{
23 return conn != NULL && conn->isOpen();
24}
25
cfd66529 26Comm::Connection::Connection() :
f53969cc
SM
27 local(),
28 remote(),
29 peerType(HIER_NONE),
30 fd(-1),
31 tos(0),
32 nfmark(0),
33 flags(COMM_NONBLOCKING),
34 peer_(NULL),
35 startTime_(squid_curtime)
73c36fd9
AJ
36{
37 *rfc931 = 0; // quick init the head. the rest does not matter.
38}
cfd66529 39
be364179 40static int64_t lost_conn = 0;
aed188fd 41Comm::Connection::~Connection()
739b352a 42{
be364179 43 if (fd >= 0) {
c460b3d7
AJ
44 debugs(5, 4, "BUG #3329: Orphan Comm::Connection: " << *this);
45 debugs(5, 4, "NOTE: " << ++lost_conn << " Orphans since last started.");
42a61e53 46 close();
be364179
AJ
47 }
48
a3c6762c 49 cbdataReferenceDone(peer_);
739b352a
AJ
50}
51
5ae21d99 52Comm::ConnectionPointer
aed188fd 53Comm::Connection::copyDetails() const
739b352a 54{
aed188fd 55 ConnectionPointer c = new Comm::Connection;
739b352a 56
7fb5be3e 57 c->setAddrs(local, remote);
5229395c 58 c->peerType = peerType;
aed188fd 59 c->tos = tos;
f123f5e9 60 c->nfmark = nfmark;
aed188fd 61 c->flags = flags;
8aec3e1b 62 c->startTime_ = startTime_;
802540f2 63
aed188fd
AJ
64 // ensure FD is not open in the new copy.
65 c->fd = -1;
f9b72e0c 66
a3c6762c
FC
67 // ensure we have a cbdata reference to peer_ not a straight ptr copy.
68 c->peer_ = cbdataReference(getPeer());
cfd66529 69
aed188fd 70 return c;
cfd66529 71}
739b352a 72
55cbb02b
AJ
73void
74Comm::Connection::close()
75{
5229395c 76 if (isOpen()) {
55cbb02b 77 comm_close(fd);
5229395c 78 fd = -1;
a3c6762c 79 if (CachePeer *p=getPeer())
e8dca475 80 peerConnClosed(p);
5229395c 81 }
55cbb02b
AJ
82}
83
a3c6762c 84CachePeer *
418b3087
AJ
85Comm::Connection::getPeer() const
86{
a3c6762c
FC
87 if (cbdataReferenceValid(peer_))
88 return peer_;
418b3087
AJ
89
90 return NULL;
91}
92
739b352a 93void
a3c6762c 94Comm::Connection::setPeer(CachePeer *p)
739b352a
AJ
95{
96 /* set to self. nothing to do. */
418b3087 97 if (getPeer() == p)
739b352a
AJ
98 return;
99
a3c6762c 100 cbdataReferenceDone(peer_);
746beefe 101 if (p) {
a3c6762c 102 peer_ = cbdataReference(p);
746beefe 103 }
739b352a 104}
f53969cc 105
c5c06f02
CT
106time_t
107Comm::Connection::timeLeft(const time_t idleTimeout) const
108{
109 if (!Config.Timeout.pconnLifetime)
110 return idleTimeout;
111
112 const time_t lifeTimeLeft = lifeTime() < Config.Timeout.pconnLifetime ? Config.Timeout.pconnLifetime - lifeTime() : 1;
113 return min(lifeTimeLeft, idleTimeout);
114}
6a515ac4 115