2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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.
14 #include "ip/Address.h"
15 #include "ip/forward.h"
16 #include "security/forward.h"
17 #include "typedefs.h" //DRCB, DWCB
20 #include "MessageBucket.h"
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'.
29 typedef int READ_HANDLER(int, char *, int);
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'.
35 typedef int WRITE_HANDLER(int, const char *, int);
40 _fde_disk() { wrt_handle
= nullptr; }
43 void *wrt_handle_data
= nullptr;
44 dwrite_q
*write_q
= nullptr;
45 dwrite_q
*write_q_tail
= nullptr;
56 read_handler
= nullptr;
57 write_handler
= nullptr;
58 read_method
= nullptr;
59 write_method
= nullptr;
62 /// Clear the fde class back to NULL equivalent.
63 void clear() { *this = fde(); }
65 /// True if comm_close for this fd has been called
66 bool closing() const { return flags
.close_request
; }
68 /* NOTE: memset is used on fdes today. 20030715 RBC */
69 static void DumpStats(StoreEntry
*);
71 char const *remoteAddr() const;
72 void dumpStats(StoreEntry
&, int) const;
73 bool readPending(int) const;
75 /// record a transaction on this FD
76 void noteUse() { ++pconn
.uses
; }
80 /// global table of FD and their state.
83 unsigned int type
= 0;
84 unsigned short remote_port
= 0;
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 nfmarkFromServer. */
92 char ipaddr
[MAX_IPSTRLEN
]; /* dotted decimal address of peer */
93 char desc
[FD_DESC_SZ
];
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;
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;
111 int64_t bytes_read
= 0;
112 int64_t bytes_written
= 0;
115 int uses
= 0; /* ie # req's over persistent conn */
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
123 unsigned epoll_state
= 0;
127 void *read_data
= nullptr;
129 void *write_data
= nullptr;
130 AsyncCall::Pointer timeoutHandler
;
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
142 long handle
= (long)nullptr;
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
150 unsigned int nfmarkFromServer
= 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
157 #define fd_table fde::Table
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)
164 #endif /* SQUID_FDE_H */