]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fde.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / fde.h
1 /*
2 * Copyright (C) 1996-2019 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
9 #ifndef SQUID_FDE_H
10 #define SQUID_FDE_H
11
12 #include "comm.h"
13 #include "defines.h"
14 #include "ip/Address.h"
15 #include "ip/forward.h"
16 #include "security/forward.h"
17 #include "typedefs.h" //DRCB, DWCB
18
19 #if USE_DELAY_POOLS
20 #include "MessageBucket.h"
21 class ClientInfo;
22 #endif
23 class dwrite_q;
24
25 /**
26 * READ_HANDLER functions return < 0 if, and only if, they fail with an error.
27 * On error, they must pass back an error code in 'errno'.
28 */
29 typedef int READ_HANDLER(int, char *, int);
30
31 /**
32 * WRITE_HANDLER functions return < 0 if, and only if, they fail with an error.
33 * On error, they must pass back an error code in 'errno'.
34 */
35 typedef int WRITE_HANDLER(int, const char *, int);
36
37 class _fde_disk
38 {
39 public:
40 _fde_disk() { wrt_handle = nullptr; }
41
42 DWCB *wrt_handle;
43 void *wrt_handle_data = nullptr;
44 dwrite_q *write_q = nullptr;
45 dwrite_q *write_q_tail = nullptr;
46 off_t offset = 0;
47 };
48
49 class fde
50 {
51
52 public:
53 fde() {
54 *ipaddr = 0;
55 *desc = 0;
56 read_handler = nullptr;
57 write_handler = nullptr;
58 read_method = nullptr;
59 write_method = nullptr;
60 }
61
62 /// Clear the fde class back to NULL equivalent.
63 void clear() { *this = fde(); }
64
65 /// True if comm_close for this fd has been called
66 bool closing() const { return flags.close_request; }
67
68 /* NOTE: memset is used on fdes today. 20030715 RBC */
69 static void DumpStats(StoreEntry *);
70
71 char const *remoteAddr() const;
72 void dumpStats(StoreEntry &, int) const;
73 bool readPending(int) const;
74
75 /// record a transaction on this FD
76 void noteUse() { ++pconn.uses; }
77
78 public:
79
80 /// global table of FD and their state.
81 static fde* Table;
82
83 unsigned int type = 0;
84 unsigned short remote_port = 0;
85
86 Ip::Address local_addr;
87 tos_t tosToServer = '\0'; /**< The TOS value for packets going towards the server.
88 See also tosFromServer. */
89 nfmark_t nfmarkToServer = 0; /**< The netfilter mark for packets going towards the server.
90 See also nfConnmarkFromServer. */
91 int sock_family = 0;
92 char ipaddr[MAX_IPSTRLEN]; /* dotted decimal address of peer */
93 char desc[FD_DESC_SZ];
94
95 struct _fde_flags {
96 bool open = false;
97 bool close_request = false; ///< true if file_ or comm_close has been called
98 bool write_daemon = false;
99 bool socket_eof = false;
100 bool nolinger = false;
101 bool nonblocking = false;
102 bool ipc = false;
103 bool called_connect = false;
104 bool nodelay = false;
105 bool close_on_exec = false;
106 bool read_pending = false;
107 //bool write_pending; //XXX seems not to be used
108 bool transparent = false;
109 } flags;
110
111 int64_t bytes_read = 0;
112 int64_t bytes_written = 0;
113
114 struct {
115 int uses = 0; /* ie # req's over persistent conn */
116 } pconn;
117
118 #if USE_DELAY_POOLS
119 /// pointer to client info used in client write limiter or nullptr if not present
120 ClientInfo * clientInfo = nullptr;
121 MessageBucket::Pointer writeQuotaHandler; ///< response write limiter, if configured
122 #endif
123 unsigned epoll_state = 0;
124
125 _fde_disk disk;
126 PF *read_handler;
127 void *read_data = nullptr;
128 PF *write_handler;
129 void *write_data = nullptr;
130 AsyncCall::Pointer timeoutHandler;
131 time_t timeout = 0;
132 time_t writeStart = 0;
133 void *lifetime_data = nullptr;
134 AsyncCall::Pointer closeHandler;
135 AsyncCall::Pointer halfClosedReader; /// read handler for half-closed fds
136 READ_HANDLER *read_method;
137 WRITE_HANDLER *write_method;
138 Security::SessionPointer ssl;
139 Security::ContextPointer dynamicTlsContext; ///< cached and then freed when fd is closed
140 #if _SQUID_WINDOWS_
141 struct {
142 long handle = (long)nullptr;
143 } win32;
144 #endif
145 tos_t tosFromServer = '\0'; /**< Stores the TOS flags of the packets from the remote server.
146 See FwdState::dispatch(). Note that this differs to
147 tosToServer in that this is the value we *receive* from the,
148 connection, whereas tosToServer is the value to set on packets
149 *leaving* Squid. */
150 unsigned int nfConnmarkFromServer = 0; /**< Stores the Netfilter mark value of the connection from the remote
151 server. See FwdState::dispatch(). Note that this differs to
152 nfmarkToServer in that this is the value we *receive* from the,
153 connection, whereas nfmarkToServer is the value to set on packets
154 *leaving* Squid. */
155 };
156
157 #define fd_table fde::Table
158
159 int fdNFree(void);
160
161 #define FD_READ_METHOD(fd, buf, len) (*fde::Table[fd].read_method)(fd, buf, len)
162 #define FD_WRITE_METHOD(fd, buf, len) (*fde::Table[fd].write_method)(fd, buf, len)
163
164 #endif /* SQUID_FDE_H */
165