]>
Commit | Line | Data |
---|---|---|
cfd66529 AJ |
1 | #include "config.h" |
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 AJ |
20 | flags(COMM_NONBLOCKING), |
21 | _peer(NULL) | |
cfd66529 AJ |
22 | {} |
23 | ||
be364179 | 24 | static int64_t lost_conn = 0; |
aed188fd | 25 | Comm::Connection::~Connection() |
739b352a | 26 | { |
be364179 AJ |
27 | if (fd >= 0) { |
28 | debugs(5, 8, "NOTE: Orphaned Comm::Connections: " << ++lost_conn); | |
29 | } | |
30 | ||
aed188fd | 31 | close(); |
bfdd3674 | 32 | cbdataReferenceDone(_peer); |
739b352a AJ |
33 | } |
34 | ||
5ae21d99 | 35 | Comm::ConnectionPointer |
aed188fd | 36 | Comm::Connection::copyDetails() const |
739b352a | 37 | { |
aed188fd | 38 | ConnectionPointer c = new Comm::Connection; |
739b352a | 39 | |
aed188fd AJ |
40 | c->local = local; |
41 | c->remote = remote; | |
5229395c | 42 | c->peerType = peerType; |
aed188fd AJ |
43 | c->tos = tos; |
44 | c->flags = flags; | |
802540f2 | 45 | |
aed188fd AJ |
46 | // ensure FD is not open in the new copy. |
47 | c->fd = -1; | |
f9b72e0c | 48 | |
aed188fd | 49 | // ensure we have a cbdata reference to _peer not a straight ptr copy. |
418b3087 | 50 | c->_peer = cbdataReference(getPeer()); |
cfd66529 | 51 | |
aed188fd | 52 | return c; |
cfd66529 | 53 | } |
739b352a | 54 | |
55cbb02b AJ |
55 | void |
56 | Comm::Connection::close() | |
57 | { | |
5229395c | 58 | if (isOpen()) { |
55cbb02b | 59 | comm_close(fd); |
5229395c | 60 | fd = -1; |
418b3087 AJ |
61 | if (getPeer()) |
62 | getPeer()->stats.conn_open--; | |
5229395c | 63 | } |
55cbb02b AJ |
64 | } |
65 | ||
802540f2 | 66 | peer * const |
418b3087 AJ |
67 | Comm::Connection::getPeer() const |
68 | { | |
69 | if (cbdataReferenceValid(_peer)) | |
70 | return _peer; | |
71 | ||
72 | return NULL; | |
73 | } | |
74 | ||
739b352a AJ |
75 | void |
76 | Comm::Connection::setPeer(peer *p) | |
77 | { | |
78 | /* set to self. nothing to do. */ | |
418b3087 | 79 | if (getPeer() == p) |
739b352a AJ |
80 | return; |
81 | ||
bfdd3674 | 82 | cbdataReferenceDone(_peer); |
746beefe | 83 | if (p) { |
739b352a | 84 | _peer = cbdataReference(p); |
746beefe | 85 | } |
739b352a | 86 | } |