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