fde.h
Go to the documentation of this file.
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 "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  fde() {
56  *ipaddr = 0;
57  *desc = 0;
58  read_handler = nullptr;
59  write_handler = nullptr;
60  readMethod_ = nullptr;
61  writeMethod_ = nullptr;
62  }
63 
65  void clear() { *this = fde(); }
66 
68  bool closing() const { return flags.close_request; }
69 
71  void setIo(READ_HANDLER *, WRITE_HANDLER *);
72 
75  void useDefaultIo();
76 
78  void useBufferedIo(READ_HANDLER *, WRITE_HANDLER *);
79 
80  int read(int fd, char *buf, int len) { return readMethod_(fd, buf, len); }
81  int write(int fd, const char *buf, int len) { return writeMethod_(fd, buf, len); }
82 
83  /* NOTE: memset is used on fdes today. 20030715 RBC */
84  static void DumpStats(StoreEntry *);
85 
86  char const *remoteAddr() const;
87  void dumpStats(StoreEntry &, int) const;
88  bool readPending(int) const;
89 
91  void noteUse() { ++pconn.uses; }
92 
93 public:
94 
96  static fde* Table;
97 
98  unsigned int type = 0;
99  unsigned short remote_port = 0;
100 
102  tos_t tosToServer = '\0';
104  nfmark_t nfmarkToServer = 0;
106  int sock_family = 0;
107  char ipaddr[MAX_IPSTRLEN]; /* dotted decimal address of peer */
108  char desc[FD_DESC_SZ];
109 
110  struct _fde_flags {
111  bool open = false;
112  bool close_request = false;
113  bool write_daemon = false;
114  bool socket_eof = false;
115  bool nolinger = false;
116  bool nonblocking = false;
117  bool ipc = false;
118  bool called_connect = false;
119  bool nodelay = false;
120  bool close_on_exec = false;
122  bool read_pending = false;
123  //bool write_pending; //XXX seems not to be used
124  bool transparent = false;
125  } flags;
126 
127  int64_t bytes_read = 0;
128  int64_t bytes_written = 0;
129 
130  struct {
131  int uses = 0; /* ie # req's over persistent conn */
132  } pconn;
133 
134 #if USE_DELAY_POOLS
135  ClientInfo * clientInfo = nullptr;
138 #endif
139  unsigned epoll_state = 0;
140 
143  void *read_data = nullptr;
145  void *write_data = nullptr;
147  time_t timeout = 0;
148  time_t writeStart = 0;
149  void *lifetime_data = nullptr;
154 #if _SQUID_WINDOWS_
155  struct {
156  long handle = (long)nullptr;
157  } win32;
158 #endif
159  tos_t tosFromServer = '\0';
164  unsigned int nfConnmarkFromServer = 0;
170  // TODO: Remove: Auto-convert legacy SetSelect() callers to AsyncCalls like
171  // comm_add_close_handler(CLCB) does, making readMethod_/writeMethod_
172  // AsyncCalls and giving each read/write a dedicated context instead.
175 
176 private:
177  // I/O methods connect Squid to the device/stack/library fde represents
178  READ_HANDLER *readMethod_ = nullptr;
179  WRITE_HANDLER *writeMethod_ = nullptr;
180 };
181 
182 #define fd_table fde::Table
183 
184 int fdNFree(void);
185 
186 inline int
187 FD_READ_METHOD(int fd, char *buf, int len)
188 {
189  return fd_table[fd].read(fd, buf, len);
190 }
191 
192 inline int
193 FD_WRITE_METHOD(int fd, const char *buf, int len)
194 {
195  return fd_table[fd].write(fd, buf, len);
196 }
197 
198 #endif /* SQUID_FDE_H */
199 
Definition: fde.h:39
CodeContextPointer codeContext
What the I/O handlers are supposed to work on.
Definition: fde.h:174
#define fd_table
Definition: fde.h:182
_fde_disk disk
Definition: fde.h:141
Ip::Address local_addr
Definition: fde.h:101
int fdNFree(void)
Definition: fd.cc:295
int FD_READ_METHOD(int fd, char *buf, int len)
Definition: fde.h:187
int type
Definition: errorpage.cc:152
static fde * Table
global table of FD and their state.
Definition: fde.h:96
_fde_disk()
Definition: fde.h:42
dwrite_q * write_q_tail
Definition: fde.h:47
void DWCB(int, int, size_t, void *)
Definition: typedefs.h:18
Security::ContextPointer dynamicTlsContext
cached and then freed when fd is closed
Definition: fde.h:153
PF * write_handler
Definition: fde.h:144
AsyncCall::Pointer closeHandler
Definition: fde.h:150
unsigned char tos_t
Definition: forward.h:26
Definition: fs_io.h:34
void * wrt_handle_data
Definition: fde.h:45
PF * read_handler
Definition: fde.h:142
dwrite_q * write_q
Definition: fde.h:46
#define FD_DESC_SZ
Definition: defines.h:46
std::shared_ptr< SSL_CTX > ContextPointer
Definition: Context.h:29
void PF(int, void *)
Definition: forward.h:18
void noteUse()
record a transaction on this FD
Definition: fde.h:91
SMB_Handle_Type handle
int write(int fd, const char *buf, int len)
Definition: fde.h:81
int WRITE_HANDLER(int, const char *, int)
Definition: fde.h:37
AsyncCall::Pointer halfClosedReader
Definition: fde.h:151
Security::SessionPointer ssl
read handler for half-closed fds
Definition: fde.h:152
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
void const char * buf
Definition: stub_helper.cc:16
int READ_HANDLER(int, char *, int)
Definition: fde.h:31
bool closing() const
True if comm_close for this fd has been called.
Definition: fde.h:68
DWCB * wrt_handle
Definition: fde.h:44
void clear()
Clear the fde class back to NULL equivalent.
Definition: fde.h:65
AsyncCall::Pointer timeoutHandler
Definition: fde.h:146
off_t offset
Definition: fde.h:48
Definition: fde.h:51
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition: forward.h:23
fde()
Definition: fde.h:55
MessageBucket::Pointer writeQuotaHandler
response write limiter, if configured
Definition: fde.h:137
int FD_WRITE_METHOD(int fd, const char *buf, int len)
Definition: fde.h:193
uint32_t nfmark_t
Definition: forward.h:25
int read(int fd, char *buf, int len)
Definition: fde.h:80
std::shared_ptr< SSL > SessionPointer
Definition: Session.h:44

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors