]> git.ipfire.org Git - thirdparty/squid.git/blame - src/comm/Connection.h
FwdState::abort can happen mid-connect
[thirdparty/squid.git] / src / comm / Connection.h
CommitLineData
ee0989f2 1/*
45906573 2 * DEBUG: section 05 Socket Functions
93ad6f77 3 * AUTHOR: Amos Jeffries
ee0989f2 4 * AUTHOR: Robert Collins
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
26ac0430 22 *
ee0989f2 23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
26ac0430 27 *
ee0989f2 28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 *
33 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
93ad6f77 34 * Copyright (c) 2010, Amos Jeffries <amosjeffries@squid-cache.org>
ee0989f2 35 */
36
37#ifndef _SQUIDCONNECTIONDETAIL_H_
38#define _SQUIDCONNECTIONDETAIL_H_
39
cfd66529 40#include "hier_code.h"
96d89ea0 41#include "ip/Address.h"
93ad6f77 42#include "RefCount.h"
cc192b50 43
739b352a 44struct peer;
cfd66529
AJ
45
46namespace Comm {
47
27d1f0a0
AJ
48/* TODO: make these a struct of boolean flags members in the connection instead of a bitmap.
49 * we can't do that until all non-comm code uses Commm::Connection objects to create FD
50 * currently there is code still using comm_open() and comm_openex() synchronously!!
51 */
cfd66529
AJ
52#define COMM_UNSET 0x00
53#define COMM_NONBLOCKING 0x01
54#define COMM_NOCLOEXEC 0x02
55#define COMM_REUSEADDR 0x04
56#define COMM_TRANSPARENT 0x08
57#define COMM_DOBIND 0x10
62e76326 58
739b352a
AJ
59/**
60 * Store data about the physical and logical attributes of a connection.
61 *
62 * Some link state can be infered from the data, however this is not an
63 * object for state data. But a semantic equivalent for FD with easily
64 * accessible cached properties not requiring repeated complex lookups.
65 *
55cbb02b
AJ
66 * While the properties may be changed, this is for teh purpose of creating
67 * potential connection descriptors which may be opened. Properties should
68 * be considered read-only outside of the Comm layer code once the connection
69 * is open.
739b352a
AJ
70 *
71 * These objects must not be passed around directly,
f9b72e0c 72 * but a Comm::ConnectionPointer must be passed instead.
739b352a 73 */
93ad6f77 74class Connection : public RefCountable
cfd66529 75{
62e76326 76public:
739b352a 77 /** standard empty connection creation */
cfd66529 78 Connection();
739b352a 79
aed188fd
AJ
80 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
81 Connection(const Connection &c);
82
83 /** Clear the connection properties and close any open socket. */
cfd66529
AJ
84 ~Connection();
85
aed188fd
AJ
86 /** Copy an existing connections IP and properties.
87 * This excludes the FD. The new copy will be a closed connection.
739b352a 88 */
aed188fd
AJ
89 ConnectionPointer & copyDetails() const;
90
91 /** These objects may not be exactly duplicated. Use clone() instead. */
92 Connection & operator =(const Connection &c);
739b352a 93
aed188fd 94 /** Close any open socket. */
55cbb02b
AJ
95 void close();
96
97 /** determine whether this object describes an active connection or not. */
d6327017 98 bool isOpen() const { return (fd >= 0); }
55cbb02b 99
cfd66529
AJ
100 /** Address/Port for the Squid end of a TCP link. */
101 Ip::Address local;
62e76326 102
cfd66529
AJ
103 /** Address for the Remote end of a TCP link. */
104 Ip::Address remote;
2d8c0b1a 105
cfd66529
AJ
106 /** Hierarchy code for this connection link */
107 hier_code peer_type;
108
739b352a 109 /** Socket used by this connection. -1 if no socket has been opened. */
cfd66529
AJ
110 int fd;
111
739b352a 112 /** Quality of Service TOS values currently sent on this connection */
cfd66529
AJ
113 int tos;
114
115 /** COMM flags set on this connection */
116 int flags;
739b352a
AJ
117
118 /** retrieve the peer pointer for use.
119 * The caller is responsible for all CBDATA operations regarding the
120 * used of the pointer returned.
121 */
122 peer * const getPeer() const { return _peer; }
123
124 /** alter the stored peer pointer.
125 * Perform appropriate CBDATA operations for locking the peer pointer
126 */
127 void setPeer(peer * p);
128
129private:
130 /** cache_peer data object (if any) */
131 peer *_peer;
ee0989f2 132};
133
cfd66529
AJ
134}; // namespace Comm
135
ee0989f2 136#endif