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 "comm.h"
13 #include "defines.h"
14 #include "ip/Address.h"
15 #include "ip/forward.h"
16 #include "security/forward.h"
17 #include "typedefs.h" //DRCB, DWCB
18 
19 #if USE_DELAY_POOLS
20 #include "MessageBucket.h"
21 class ClientInfo;
22 #endif
23 class dwrite_q;
24 
29 typedef int READ_HANDLER(int, char *, int);
30 
35 typedef int WRITE_HANDLER(int, const char *, int);
36 
37 class _fde_disk
38 {
39 public:
40  _fde_disk() { wrt_handle = nullptr; }
41 
43  void *wrt_handle_data = nullptr;
44  dwrite_q *write_q = nullptr;
45  dwrite_q *write_q_tail = nullptr;
46  off_t offset = 0;
47 };
48 
49 class fde
50 {
51 
52 public:
53  fde() {
54  *ipaddr = 0;
55  *desc = 0;
56  read_handler = nullptr;
57  write_handler = nullptr;
58  readMethod_ = nullptr;
59  writeMethod_ = nullptr;
60  }
61 
63  void clear() { *this = fde(); }
64 
66  bool closing() const { return flags.close_request; }
67 
69  void setIo(READ_HANDLER *, WRITE_HANDLER *);
70 
73  void useDefaultIo();
74 
76  void useBufferedIo(READ_HANDLER *, WRITE_HANDLER *);
77 
78  int read(int fd, char *buf, int len) { return readMethod_(fd, buf, len); }
79  int write(int fd, const char *buf, int len) { return writeMethod_(fd, buf, len); }
80 
81  /* NOTE: memset is used on fdes today. 20030715 RBC */
82  static void DumpStats(StoreEntry *);
83 
84  char const *remoteAddr() const;
85  void dumpStats(StoreEntry &, int) const;
86  bool readPending(int) const;
87 
89  void noteUse() { ++pconn.uses; }
90 
91 public:
92 
94  static fde* Table;
95 
96  unsigned int type = 0;
97  unsigned short remote_port = 0;
98 
100  tos_t tosToServer = '\0';
102  nfmark_t nfmarkToServer = 0;
104  int sock_family = 0;
105  char ipaddr[MAX_IPSTRLEN]; /* dotted decimal address of peer */
106  char desc[FD_DESC_SZ];
107 
108  struct _fde_flags {
109  bool open = false;
110  bool close_request = false;
111  bool write_daemon = false;
112  bool socket_eof = false;
113  bool nolinger = false;
114  bool nonblocking = false;
115  bool ipc = false;
116  bool called_connect = false;
117  bool nodelay = false;
118  bool close_on_exec = false;
120  bool read_pending = false;
121  //bool write_pending; //XXX seems not to be used
122  bool transparent = false;
123  } flags;
124 
125  int64_t bytes_read = 0;
126  int64_t bytes_written = 0;
127 
128  struct {
129  int uses = 0; /* ie # req's over persistent conn */
130  } pconn;
131 
132 #if USE_DELAY_POOLS
133  ClientInfo * clientInfo = nullptr;
136 #endif
137  unsigned epoll_state = 0;
138 
141  void *read_data = nullptr;
143  void *write_data = nullptr;
145  time_t timeout = 0;
146  time_t writeStart = 0;
147  void *lifetime_data = nullptr;
152 #if _SQUID_WINDOWS_
153  struct {
154  long handle = (long)nullptr;
155  } win32;
156 #endif
157  tos_t tosFromServer = '\0';
162  unsigned int nfConnmarkFromServer = 0;
168 private:
169  // I/O methods connect Squid to the device/stack/library fde represents
170  READ_HANDLER *readMethod_ = nullptr;
171  WRITE_HANDLER *writeMethod_ = nullptr;
172 };
173 
174 #define fd_table fde::Table
175 
176 int fdNFree(void);
177 
178 inline int
179 FD_READ_METHOD(int fd, char *buf, int len)
180 {
181  return fd_table[fd].read(fd, buf, len);
182 }
183 
184 inline int
185 FD_WRITE_METHOD(int fd, const char *buf, int len)
186 {
187  return fd_table[fd].write(fd, buf, len);
188 }
189 
190 #endif /* SQUID_FDE_H */
191 
Definition: fde.h:37
#define fd_table
Definition: fde.h:174
_fde_disk disk
Definition: fde.h:139
Ip::Address local_addr
Definition: fde.h:99
int fdNFree(void)
Definition: fd.cc:295
int FD_READ_METHOD(int fd, char *buf, int len)
Definition: fde.h:179
int type
Definition: errorpage.cc:152
static fde * Table
global table of FD and their state.
Definition: fde.h:94
_fde_disk()
Definition: fde.h:40
dwrite_q * write_q_tail
Definition: fde.h:45
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:151
PF * write_handler
Definition: fde.h:142
AsyncCall::Pointer closeHandler
Definition: fde.h:148
unsigned char tos_t
Definition: forward.h:26
Definition: fs_io.h:34
void * wrt_handle_data
Definition: fde.h:43
PF * read_handler
Definition: fde.h:140
dwrite_q * write_q
Definition: fde.h:44
#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:89
SMB_Handle_Type handle
int write(int fd, const char *buf, int len)
Definition: fde.h:79
int WRITE_HANDLER(int, const char *, int)
Definition: fde.h:35
AsyncCall::Pointer halfClosedReader
Definition: fde.h:149
Security::SessionPointer ssl
read handler for half-closed fds
Definition: fde.h:150
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:29
bool closing() const
True if comm_close for this fd has been called.
Definition: fde.h:66
DWCB * wrt_handle
Definition: fde.h:42
void clear()
Clear the fde class back to NULL equivalent.
Definition: fde.h:63
AsyncCall::Pointer timeoutHandler
Definition: fde.h:144
off_t offset
Definition: fde.h:46
Definition: fde.h:49
#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:53
MessageBucket::Pointer writeQuotaHandler
response write limiter, if configured
Definition: fde.h:135
int FD_WRITE_METHOD(int fd, const char *buf, int len)
Definition: fde.h:185
uint32_t nfmark_t
Definition: forward.h:25
int read(int fd, char *buf, int len)
Definition: fde.h:78
std::shared_ptr< SSL > SessionPointer
Definition: Session.h:44

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors