fde.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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"
23class ClientInfo;
24#endif
25class dwrite_q;
26
31typedef int READ_HANDLER(int, char *, int);
32
37typedef int WRITE_HANDLER(int, const char *, int);
38
40{
41public:
42 _fde_disk() { wrt_handle = nullptr; }
43
45 void *wrt_handle_data = nullptr;
46 dwrite_q *write_q = nullptr;
48 off_t offset = 0;
49};
50
51class fde
52{
53
54public:
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
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
100public:
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;
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 */
140
141#if USE_DELAY_POOLS
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
183private:
184 // I/O methods connect Squid to the device/stack/library fde represents
187};
188
189#define fd_table fde::Table
190
191int fdNFree(void);
192
193inline int
194FD_READ_METHOD(int fd, char *buf, int len)
195{
196 return fd_table[fd].read(fd, buf, len);
197}
198
199inline int
200FD_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
Definition: fde.h:40
DWCB * wrt_handle
Definition: fde.h:44
dwrite_q * write_q
Definition: fde.h:46
off_t offset
Definition: fde.h:48
void * wrt_handle_data
Definition: fde.h:45
_fde_disk()
Definition: fde.h:42
dwrite_q * write_q_tail
Definition: fde.h:47
Definition: fs_io.h:35
Definition: fde.h:52
unsigned epoll_state
Definition: fde.h:146
void useDefaultIo()
Definition: fde.cc:33
bool closing() const
True if comm_close for this fd has been called.
Definition: fde.h:75
nfmark_t nfmarkToServer
Definition: fde.h:111
static fde * Table
global table of FD and their state.
Definition: fde.h:103
_fde_disk disk
Definition: fde.h:148
WRITE_HANDLER * writeMethod_
exports Squid bytes
Definition: fde.h:186
unsigned int type
Definition: fde.h:105
char desc[FD_DESC_SZ]
Definition: fde.h:115
char const * remoteAddr() const
Definition: fde.cc:125
int64_t bytes_written
Definition: fde.h:135
AsyncCall::Pointer timeoutHandler
Definition: fde.h:153
void useBufferedIo(READ_HANDLER *, WRITE_HANDLER *)
use I/O methods that maintain an internal-to-them buffer
Definition: fde.cc:49
CodeContextPointer codeContext
What the I/O handlers are supposed to work on.
Definition: fde.h:181
PF * read_handler
Definition: fde.h:149
bool readPending(int) const
Definition: fde.cc:63
void dumpStats(StoreEntry &, int) const
Definition: fde.cc:72
void * write_data
Definition: fde.h:152
void * lifetime_data
Definition: fde.h:156
tos_t tosToServer
Definition: fde.h:109
struct fde::_fde_flags flags
MessageBucket::Pointer writeQuotaHandler
response write limiter, if configured
Definition: fde.h:144
struct fde::@69 pconn
time_t writeStart
Definition: fde.h:155
Security::SessionPointer ssl
read handler for half-closed fds
Definition: fde.h:159
READ_HANDLER * readMethod_
imports bytes into Squid
Definition: fde.h:185
time_t timeout
Definition: fde.h:154
void setIo(READ_HANDLER *, WRITE_HANDLER *)
set I/O methods for a freshly opened descriptor
Definition: fde.cc:22
static void Init()
Definition: fde.cc:141
AsyncCall::Pointer closeHandler
Definition: fde.h:157
unsigned short remote_port
Definition: fde.h:106
int write(int fd, const char *buf, int len)
Definition: fde.h:88
ClientInfo * clientInfo
pointer to client info used in client write limiter or nullptr if not present
Definition: fde.h:143
char ipaddr[MAX_IPSTRLEN]
Definition: fde.h:114
AsyncCall::Pointer halfClosedReader
Definition: fde.h:158
void clear()
Clear the fde class back to NULL equivalent.
Definition: fde.h:72
Ip::Address local_addr
Definition: fde.h:108
int uses
Definition: fde.h:138
void * read_data
Definition: fde.h:150
PF * write_handler
Definition: fde.h:151
int64_t bytes_read
Definition: fde.h:134
unsigned int nfConnmarkFromServer
Definition: fde.h:171
fde()
Definition: fde.h:62
tos_t tosFromServer
Definition: fde.h:166
void noteUse()
record a transaction on this FD
Definition: fde.h:98
static void DumpStats(StoreEntry *)
Definition: fde.cc:96
Security::ContextPointer dynamicTlsContext
cached and then freed when fd is closed
Definition: fde.h:160
int sock_family
Definition: fde.h:113
int read(int fd, char *buf, int len)
Definition: fde.h:87
void PF(int, void *)
Definition: forward.h:18
#define FD_DESC_SZ
Definition: defines.h:32
#define fd_table
Definition: fde.h:189
int fdNFree(void)
Definition: fd.cc:266
int FD_READ_METHOD(int fd, char *buf, int len)
Definition: fde.h:194
int FD_WRITE_METHOD(int fd, const char *buf, int len)
Definition: fde.h:200
int READ_HANDLER(int, char *, int)
Definition: fde.h:31
int WRITE_HANDLER(int, const char *, int)
Definition: fde.h:37
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition: forward.h:25
unsigned char tos_t
Definition: forward.h:27
uint32_t nfmark_t
Definition: forward.h:26
std::shared_ptr< SSL_CTX > ContextPointer
Definition: Context.h:29
std::shared_ptr< SSL > SessionPointer
Definition: Session.h:49
SMB_Handle_Type handle
bool transparent
Definition: fde.h:131
bool ipc
Definition: fde.h:124
bool nodelay
Definition: fde.h:126
bool called_connect
Definition: fde.h:125
bool read_pending
buffering readMethod_ has data to give (regardless of socket state)
Definition: fde.h:129
bool nolinger
Definition: fde.h:122
bool socket_eof
Definition: fde.h:121
bool close_on_exec
Definition: fde.h:127
bool nonblocking
Definition: fde.h:123
bool open
Definition: fde.h:118
bool close_request
true if file_ or comm_close has been called
Definition: fde.h:119
bool write_daemon
Definition: fde.h:120
void DWCB(int, int, size_t, void *)
Definition: typedefs.h:18

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors