fde.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 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 "base/CodeContext.h" /* XXX: Remove by de-inlining ctor and clear() */
13 #include "base/forward.h"
14 #include "comm.h"
15 #include "defines.h"
16 #include "ip/Address.h"
17 #include "ip/forward.h"
18 #include "security/forward.h"
19 #include "typedefs.h" //DRCB, DWCB
20 
21 #if USE_DELAY_POOLS
22 #include "MessageBucket.h"
23 class ClientInfo;
24 #endif
25 class dwrite_q;
26 
31 typedef int READ_HANDLER(int, char *, int);
32 
37 typedef int WRITE_HANDLER(int, const char *, int);
38 
39 class _fde_disk
40 {
41 public:
42  _fde_disk() { wrt_handle = nullptr; }
43 
45  void *wrt_handle_data = nullptr;
46  dwrite_q *write_q = nullptr;
47  dwrite_q *write_q_tail = nullptr;
48  off_t offset = 0;
49 };
50 
51 class fde
52 {
53 
54 public:
55 
56  // TODO: Merge with comm_init() to reduce initialization order dependencies.
60  static void Init();
61 
62  fde() {
63  *ipaddr = 0;
64  *desc = 0;
65  read_handler = nullptr;
66  write_handler = nullptr;
67  readMethod_ = nullptr;
68  writeMethod_ = nullptr;
69  }
70 
72  void clear() { *this = fde(); }
73 
75  bool closing() const { return flags.close_request; }
76 
78  void setIo(READ_HANDLER *, WRITE_HANDLER *);
79 
82  void useDefaultIo();
83 
86 
87  int read(int fd, char *buf, int len) { return readMethod_(fd, buf, len); }
88  int write(int fd, const char *buf, int len) { return writeMethod_(fd, buf, len); }
89 
90  /* NOTE: memset is used on fdes today. 20030715 RBC */
91  static void DumpStats(StoreEntry *);
92 
93  char const *remoteAddr() const;
94  void dumpStats(StoreEntry &, int) const;
95  bool readPending(int) const;
96 
98  void noteUse() { ++pconn.uses; }
99 
100 public:
101 
103  static fde* Table;
104 
105  unsigned int type = 0;
106  unsigned short remote_port = 0;
107 
113  int sock_family = 0;
114  char ipaddr[MAX_IPSTRLEN]; /* dotted decimal address of peer */
116 
117  struct _fde_flags {
118  bool open = false;
119  bool close_request = false;
120  bool write_daemon = false;
121  bool socket_eof = false;
122  bool nolinger = false;
123  bool nonblocking = false;
124  bool ipc = false;
125  bool called_connect = false;
126  bool nodelay = false;
127  bool close_on_exec = false;
129  bool read_pending = false;
130  //bool write_pending; //XXX seems not to be used
131  bool transparent = false;
132  } flags;
133 
134  int64_t bytes_read = 0;
135  int64_t bytes_written = 0;
136 
137  struct {
138  int uses = 0; /* ie # req's over persistent conn */
139  } pconn;
140 
141 #if USE_DELAY_POOLS
142  ClientInfo * clientInfo = nullptr;
145 #endif
146  unsigned epoll_state = 0;
147 
150  void *read_data = nullptr;
152  void *write_data = nullptr;
154  time_t timeout = 0;
155  time_t writeStart = 0;
156  void *lifetime_data = nullptr;
161 #if _SQUID_WINDOWS_
162  struct {
163  long handle = (long)nullptr;
164  } win32;
165 #endif
171  unsigned int nfConnmarkFromServer = 0;
177  // TODO: Remove: Auto-convert legacy SetSelect() callers to AsyncCalls like
178  // comm_add_close_handler(CLCB) does, making readMethod_/writeMethod_
179  // AsyncCalls and giving each read/write a dedicated context instead.
182 
183 private:
184  // I/O methods connect Squid to the device/stack/library fde represents
187 };
188 
189 #define fd_table fde::Table
190 
191 int fdNFree(void);
192 
193 inline int
194 FD_READ_METHOD(int fd, char *buf, int len)
195 {
196  return fd_table[fd].read(fd, buf, len);
197 }
198 
199 inline int
200 FD_WRITE_METHOD(int fd, const char *buf, int len)
201 {
202  return fd_table[fd].write(fd, buf, len);
203 }
204 
205 #endif /* SQUID_FDE_H */
206 
#define FD_DESC_SZ
Definition: defines.h:46
fde()
Definition: fde.h:62
bool called_connect
Definition: fde.h:125
bool read_pending
buffering readMethod_ has data to give (regardless of socket state)
Definition: fde.h:129
_fde_disk disk
Definition: fde.h:148
dwrite_q * write_q
Definition: fde.h:46
bool write_daemon
Definition: fde.h:120
std::shared_ptr< SSL_CTX > ContextPointer
Definition: Context.h:29
bool ipc
Definition: fde.h:124
Definition: fde.h:39
const char * remoteAddr() const
Definition: fde.cc:126
int WRITE_HANDLER(int, const char *, int)
Definition: fde.h:37
static fde * Table
global table of FD and their state.
Definition: fde.h:103
unsigned int nfConnmarkFromServer
Definition: fde.h:171
static void DumpStats(StoreEntry *)
Definition: fde.cc:97
ClientInfo * clientInfo
pointer to client info used in client write limiter or nullptr if not present
Definition: fde.h:143
void useDefaultIo()
Definition: fde.cc:34
bool nonblocking
Definition: fde.h:123
bool close_on_exec
Definition: fde.h:127
Security::SessionPointer ssl
read handler for half-closed fds
Definition: fde.h:159
int64_t bytes_read
Definition: fde.h:134
unsigned char tos_t
Definition: forward.h:26
struct fde::@68 pconn
Ip::Address local_addr
Definition: fde.h:108
WRITE_HANDLER * writeMethod_
exports Squid bytes
Definition: fde.h:186
off_t offset
Definition: fde.h:48
unsigned short remote_port
Definition: fde.h:106
int READ_HANDLER(int, char *, int)
Definition: fde.h:31
void * lifetime_data
Definition: fde.h:156
int write(int fd, const char *buf, int len)
Definition: fde.h:88
void * read_data
Definition: fde.h:150
Definition: fde.h:51
void noteUse()
record a transaction on this FD
Definition: fde.h:98
bool close_request
true if file_ or comm_close has been called
Definition: fde.h:119
time_t writeStart
Definition: fde.h:155
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition: forward.h:23
bool readPending(int) const
Definition: fde.cc:64
AsyncCall::Pointer closeHandler
Definition: fde.h:157
DWCB * wrt_handle
Definition: fde.h:44
PF * write_handler
Definition: fde.h:151
bool nolinger
Definition: fde.h:122
bool transparent
Definition: fde.h:131
time_t timeout
Definition: fde.h:154
struct fde::_fde_flags flags
dwrite_q * write_q_tail
Definition: fde.h:47
SMB_Handle_Type handle
void * write_data
Definition: fde.h:152
int64_t bytes_written
Definition: fde.h:135
static void Init()
Definition: fde.cc:142
unsigned int type
Definition: fde.h:105
bool open
Definition: fde.h:118
tos_t tosFromServer
Definition: fde.h:166
int sock_family
Definition: fde.h:113
uint32_t nfmark_t
Definition: forward.h:25
PF * read_handler
Definition: fde.h:149
int FD_WRITE_METHOD(int fd, const char *buf, int len)
Definition: fde.h:200
void dumpStats(StoreEntry &, int) const
Definition: fde.cc:73
int FD_READ_METHOD(int fd, char *buf, int len)
Definition: fde.h:194
#define fd_table
Definition: fde.h:189
nfmark_t nfmarkToServer
Definition: fde.h:111
AsyncCall::Pointer halfClosedReader
Definition: fde.h:158
int uses
Definition: fde.h:138
std::shared_ptr< SSL > SessionPointer
Definition: Session.h:44
unsigned epoll_state
Definition: fde.h:146
char desc[FD_DESC_SZ]
Definition: fde.h:115
void setIo(READ_HANDLER *, WRITE_HANDLER *)
set I/O methods for a freshly opened descriptor
Definition: fde.cc:23
CodeContextPointer codeContext
What the I/O handlers are supposed to work on.
Definition: fde.h:181
READ_HANDLER * readMethod_
imports bytes into Squid
Definition: fde.h:185
int fdNFree(void)
Definition: fd.cc:295
bool closing() const
True if comm_close for this fd has been called.
Definition: fde.h:75
Definition: fs_io.h:34
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
void clear()
Clear the fde class back to NULL equivalent.
Definition: fde.h:72
void useBufferedIo(READ_HANDLER *, WRITE_HANDLER *)
use I/O methods that maintain an internal-to-them buffer
Definition: fde.cc:50
tos_t tosToServer
Definition: fde.h:109
AsyncCall::Pointer timeoutHandler
Definition: fde.h:153
_fde_disk()
Definition: fde.h:42
MessageBucket::Pointer writeQuotaHandler
response write limiter, if configured
Definition: fde.h:144
int read(int fd, char *buf, int len)
Definition: fde.h:87
bool nodelay
Definition: fde.h:126
char ipaddr[MAX_IPSTRLEN]
Definition: fde.h:114
void * wrt_handle_data
Definition: fde.h:45
void const char * buf
Definition: stub_helper.cc:16
void DWCB(int, int, size_t, void *)
Definition: typedefs.h:18
void PF(int, void *)
Definition: forward.h:18
Security::ContextPointer dynamicTlsContext
cached and then freed when fd is closed
Definition: fde.h:160
bool socket_eof
Definition: fde.h:121

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors