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