]>
Commit | Line | Data |
---|---|---|
f7f3304a | 1 | #include "squid.h" |
cfd66529 AJ |
2 | #include "cbdata.h" |
3 | #include "comm.h" | |
4 | #include "comm/Connection.h" | |
be364179 AJ |
5 | #include "fde.h" |
6 | #include "SquidTime.h" | |
cfd66529 | 7 | |
97c81191 AJ |
8 | bool |
9 | Comm::IsConnOpen(const Comm::ConnectionPointer &conn) | |
10 | { | |
11 | return conn != NULL && conn->isOpen(); | |
12 | } | |
13 | ||
cfd66529 AJ |
14 | Comm::Connection::Connection() : |
15 | local(), | |
16 | remote(), | |
5229395c | 17 | peerType(HIER_NONE), |
cfd66529 AJ |
18 | fd(-1), |
19 | tos(0), | |
739b352a | 20 | flags(COMM_NONBLOCKING), |
a3c6762c | 21 | peer_(NULL) |
73c36fd9 AJ |
22 | { |
23 | *rfc931 = 0; // quick init the head. the rest does not matter. | |
24 | } | |
cfd66529 | 25 | |
be364179 | 26 | static int64_t lost_conn = 0; |
aed188fd | 27 | Comm::Connection::~Connection() |
739b352a | 28 | { |
be364179 | 29 | if (fd >= 0) { |
fa84c01d FC |
30 | debugs(5, DBG_CRITICAL, "BUG: Orphan Comm::Connection: " << *this); |
31 | debugs(5, DBG_CRITICAL, "NOTE: " << ++lost_conn << " Orphans since last started."); | |
42a61e53 | 32 | close(); |
be364179 AJ |
33 | } |
34 | ||
a3c6762c | 35 | cbdataReferenceDone(peer_); |
739b352a AJ |
36 | } |
37 | ||
5ae21d99 | 38 | Comm::ConnectionPointer |
aed188fd | 39 | Comm::Connection::copyDetails() const |
739b352a | 40 | { |
aed188fd | 41 | ConnectionPointer c = new Comm::Connection; |
739b352a | 42 | |
aed188fd AJ |
43 | c->local = local; |
44 | c->remote = remote; | |
5229395c | 45 | c->peerType = peerType; |
aed188fd AJ |
46 | c->tos = tos; |
47 | c->flags = flags; | |
802540f2 | 48 | |
aed188fd AJ |
49 | // ensure FD is not open in the new copy. |
50 | c->fd = -1; | |
f9b72e0c | 51 | |
a3c6762c FC |
52 | // ensure we have a cbdata reference to peer_ not a straight ptr copy. |
53 | c->peer_ = cbdataReference(getPeer()); | |
cfd66529 | 54 | |
aed188fd | 55 | return c; |
cfd66529 | 56 | } |
739b352a | 57 | |
55cbb02b AJ |
58 | void |
59 | Comm::Connection::close() | |
60 | { | |
5229395c | 61 | if (isOpen()) { |
55cbb02b | 62 | comm_close(fd); |
5229395c | 63 | fd = -1; |
a3c6762c | 64 | if (CachePeer *p=getPeer()) |
a2f5277a | 65 | -- p->stats.conn_open; |
5229395c | 66 | } |
55cbb02b AJ |
67 | } |
68 | ||
a3c6762c | 69 | CachePeer * |
418b3087 AJ |
70 | Comm::Connection::getPeer() const |
71 | { | |
a3c6762c FC |
72 | if (cbdataReferenceValid(peer_)) |
73 | return peer_; | |
418b3087 AJ |
74 | |
75 | return NULL; | |
76 | } | |
77 | ||
739b352a | 78 | void |
a3c6762c | 79 | Comm::Connection::setPeer(CachePeer *p) |
739b352a AJ |
80 | { |
81 | /* set to self. nothing to do. */ | |
418b3087 | 82 | if (getPeer() == p) |
739b352a AJ |
83 | return; |
84 | ||
a3c6762c | 85 | cbdataReferenceDone(peer_); |
746beefe | 86 | if (p) { |
a3c6762c | 87 | peer_ = cbdataReference(p); |
746beefe | 88 | } |
739b352a | 89 | } |