]> git.ipfire.org Git - thirdparty/squid.git/blame - src/fde.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / fde.h
CommitLineData
528b2c61 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
528b2c61 3 *
bbc27441
AJ
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.
528b2c61 7 */
8
9#ifndef SQUID_FDE_H
10#define SQUID_FDE_H
cc192b50 11
a46d2c0e 12#include "comm.h"
1328cfb7 13#include "defines.h"
96d89ea0 14#include "ip/Address.h"
d9538350 15#include "ip/forward.h"
3aac8c26 16#include "security/forward.h"
e1ba42a4 17#include "typedefs.h" //DRCB, DWCB
a011edee 18
9a0a18de 19#if USE_DELAY_POOLS
b4cd430a
CT
20class ClientInfo;
21#endif
1328cfb7 22
541b581e
FC
23/**
24 * READ_HANDLER functions return < 0 if, and only if, they fail with an error.
25 * On error, they must pass back an error code in 'errno'.
26 */
27typedef int READ_HANDLER(int, char *, int);
28
822c0041
FC
29/**
30 * WRITE_HANDLER functions return < 0 if, and only if, they fail with an error.
31 * On error, they must pass back an error code in 'errno'.
32 */
33typedef int WRITE_HANDLER(int, const char *, int);
34
1328cfb7 35class dwrite_q;
e4a14600
A
36class _fde_disk
37{
1328cfb7
FC
38public:
39 DWCB *wrt_handle;
40 void *wrt_handle_data;
41 dwrite_q *write_q;
42 dwrite_q *write_q_tail;
43 off_t offset;
82afb125 44 _fde_disk() { memset(this, 0, sizeof(_fde_disk)); }
1328cfb7 45};
781ce8ff 46
62e76326 47class fde
48{
49
528b2c61 50public:
cc192b50 51 fde() { clear(); };
9e008dda 52
82ec8dfc
AR
53 /// True if comm_close for this fd has been called
54 bool closing() { return flags.close_request; }
cc192b50 55
75faaa7a 56 /* NOTE: memset is used on fdes today. 20030715 RBC */
528b2c61 57 static void DumpStats (StoreEntry *);
62e76326 58
528b2c61 59 char const *remoteAddr() const;
60 void dumpStats (StoreEntry &, int);
61 bool readPending(int);
e8dca475 62 void noteUse();
528b2c61 63
b115733c 64public:
f9fb22f5
AJ
65
66 /// global table of FD and their state.
67 static fde* Table;
68
528b2c61 69 unsigned int type;
f45dd259 70 unsigned short remote_port;
62e76326 71
b7ac5457 72 Ip::Address local_addr;
425de4c8
AJ
73 tos_t tosToServer; /**< The TOS value for packets going towards the server.
74 See also tosFromServer. */
75 nfmark_t nfmarkToServer; /**< The netfilter mark for packets going towards the server.
76 See also nfmarkFromServer. */
cc192b50 77 int sock_family;
78 char ipaddr[MAX_IPSTRLEN]; /* dotted decimal address of peer */
528b2c61 79 char desc[FD_DESC_SZ];
62e76326 80
b115733c 81 struct _fde_flags {
be4d35dc
FC
82 bool open;
83 bool close_request; ///< true if file_ or comm_close has been called
84 bool write_daemon;
85 bool socket_eof;
86 bool nolinger;
87 bool nonblocking;
88 bool ipc;
89 bool called_connect;
90 bool nodelay;
91 bool close_on_exec;
92 bool read_pending;
93 //bool write_pending; //XXX seems not to be used
94 bool transparent;
aeb090a2 95 } flags;
62e76326 96
47f6e231 97 int64_t bytes_read;
98 int64_t bytes_written;
781ce8ff 99
aeb090a2 100 struct {
781ce8ff 101 int uses; /* ie # req's over persistent conn */
aeb090a2 102 } pconn;
781ce8ff 103
9a0a18de 104#if USE_DELAY_POOLS
b4cd430a
CT
105 ClientInfo * clientInfo;/* pointer to client info used in client write limiter or NULL if not present */
106#endif
751406fe 107 unsigned epoll_state;
62e76326 108
82afb125 109 _fde_disk disk;
528b2c61 110 PF *read_handler;
111 void *read_data;
112 PF *write_handler;
113 void *write_data;
5c2c2194 114 AsyncCall::Pointer timeoutHandler;
528b2c61 115 time_t timeout;
5ef5e5cc 116 time_t writeStart;
528b2c61 117 void *lifetime_data;
5c2c2194 118 AsyncCall::Pointer closeHandler;
74257126 119 AsyncCall::Pointer halfClosedReader; /// read handler for half-closed fds
528b2c61 120 READ_HANDLER *read_method;
121 WRITE_HANDLER *write_method;
3aac8c26 122 Security::SessionPointer ssl;
0476ec45 123 Security::ContextPointer dynamicTlsContext; ///< cached and then freed when fd is closed
7aa9bb3e 124#if _SQUID_WINDOWS_
9e008dda 125 struct {
629b5f75 126 long handle;
aeb090a2 127 } win32;
629b5f75 128#endif
425de4c8
AJ
129 tos_t tosFromServer; /**< Stores the TOS flags of the packets from the remote server.
130 See FwdState::dispatch(). Note that this differs to
131 tosToServer in that this is the value we *receive* from the,
132 connection, whereas tosToServer is the value to set on packets
133 *leaving* Squid. */
134 unsigned int nfmarkFromServer; /**< Stores the Netfilter mark value of the connection from the remote
135 server. See FwdState::dispatch(). Note that this differs to
136 nfmarkToServer in that this is the value we *receive* from the,
137 connection, whereas nfmarkToServer is the value to set on packets
138 *leaving* Squid. */
629b5f75 139
bf81adb4
AR
140 /** Clear the fde class back to NULL equivalent. */
141 inline void clear() {
b115733c
AJ
142 type = 0;
143 remote_port = 0;
4dd643d5 144 local_addr.setEmpty();
f4f6c2e0
AJ
145 tosToServer = '\0';
146 nfmarkToServer = 0;
b115733c
AJ
147 sock_family = 0;
148 memset(ipaddr, '\0', MAX_IPSTRLEN);
149 memset(desc,'\0',FD_DESC_SZ);
9b8bdcab 150 memset(&flags,0,sizeof(_fde_flags));
b115733c
AJ
151 bytes_read = 0;
152 bytes_written = 0;
153 pconn.uses = 0;
9a0a18de 154#if USE_DELAY_POOLS
b4cd430a 155 clientInfo = NULL;
d15c7ffc 156#endif
b115733c 157 epoll_state = 0;
b115733c
AJ
158 read_handler = NULL;
159 read_data = NULL;
160 write_handler = NULL;
161 write_data = NULL;
bf81adb4 162 timeoutHandler = NULL;
b115733c
AJ
163 timeout = 0;
164 writeStart = 0;
165 lifetime_data = NULL;
bf81adb4 166 closeHandler = NULL;
74257126 167 halfClosedReader = NULL;
b115733c
AJ
168 read_method = NULL;
169 write_method = NULL;
1ca8bbfb 170 ssl.reset();
0476ec45 171 dynamicTlsContext.reset();
7aa9bb3e 172#if _SQUID_WINDOWS_
e802a427 173 win32.handle = (long)NULL;
b115733c 174#endif
f4f6c2e0
AJ
175 tosFromServer = '\0';
176 nfmarkFromServer = 0;
bf81adb4 177 }
528b2c61 178};
179
f9fb22f5
AJ
180#define fd_table fde::Table
181
d9c252f2 182int fdNFree(void);
04f55905 183
ef364f64
AJ
184#define FD_READ_METHOD(fd, buf, len) (*fd_table[fd].read_method)(fd, buf, len)
185#define FD_WRITE_METHOD(fd, buf, len) (*fd_table[fd].write_method)(fd, buf, len)
186
528b2c61 187#endif /* SQUID_FDE_H */
f53969cc 188