CommCalls.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 #include "squid.h"
10 #include "anyp/PortCfg.h"
11 #include "comm/Connection.h"
12 #include "CommCalls.h"
13 #include "fde.h"
14 #include "globals.h"
15 
16 /* CommCommonCbParams */
17 
19  data(cbdataReference(aData)), conn(), flag(Comm::OK), xerrno(0), fd(-1)
20 {
21 }
22 
24  data(cbdataReference(p.data)), conn(p.conn), flag(p.flag), xerrno(p.xerrno), fd(p.fd)
25 {
26 }
27 
29 {
31 }
32 
33 void
34 CommCommonCbParams::print(std::ostream &os) const
35 {
36  if (conn != nullptr)
37  os << conn;
38  else
39  os << "FD " << fd;
40 
41  if (xerrno)
42  os << ", errno=" << xerrno;
43  if (flag != Comm::OK)
44  os << ", flag=" << flag;
45  if (data)
46  os << ", data=" << data;
47 }
48 
49 /* CommAcceptCbParams */
50 
52  CommCommonCbParams(aData)
53 {
54 }
55 
56 // XXX: Add CommAcceptCbParams::syncWithComm(). Adjust syncWithComm() API if all
57 // implementations always return true.
58 
59 void
60 CommAcceptCbParams::print(std::ostream &os) const
61 {
63 
64  if (port && port->listenConn)
65  os << ", " << port->listenConn->codeContextGist();
66 }
67 
68 /* CommConnectCbParams */
69 
71  CommCommonCbParams(aData)
72 {
73 }
74 
75 bool
77 {
78  assert(conn);
79 
80  // change parameters if this is a successful callback that was scheduled
81  // after its Comm-registered connection started to close
82 
83  if (flag != Comm::OK) {
84  assert(!conn->isOpen());
85  return true; // not a successful callback; cannot go out of sync
86  }
87 
88  assert(conn->isOpen());
89  if (!fd_table[conn->fd].closing())
90  return true; // no closing in progress; in sync (for now)
91 
92  debugs(5, 3, "converting to Comm::ERR_CLOSING: " << conn);
93  conn->noteClosure();
95  return true; // now the callback is in sync with Comm again
96 }
97 
98 /* CommIoCbParams */
99 
101  buf(nullptr), size(0)
102 {
103 }
104 
105 bool
107 {
108  // change parameters if the call was scheduled before comm_close but
109  // is being fired after comm_close
110  if ((conn->fd < 0 || fd_table[conn->fd].closing()) && flag != Comm::ERR_CLOSING) {
111  debugs(5, 3, "converting late call to Comm::ERR_CLOSING: " << conn);
113  }
114  return true; // now we are in sync and can handle the call
115 }
116 
117 void
118 CommIoCbParams::print(std::ostream &os) const
119 {
121  if (buf) {
122  os << ", size=" << size;
123  os << ", buf=" << (void*)buf;
124  }
125 }
126 
127 /* CommCloseCbParams */
128 
130  CommCommonCbParams(aData)
131 {
132 }
133 
134 /* CommTimeoutCbParams */
135 
137  CommCommonCbParams(aData)
138 {
139 }
140 
141 /* CommAcceptCbPtrFun */
142 
144  const CommAcceptCbParams &aParams):
146  handler(aHandler)
147 {
148 }
149 
152  handler(o.handler)
153 {
154 }
155 
156 void
158 {
159  handler(params);
160 }
161 
162 void
163 CommAcceptCbPtrFun::print(std::ostream &os) const
164 {
165  os << '(';
166  params.print(os);
167  os << ')';
168 }
169 
170 /* CommConnectCbPtrFun */
171 
173  const CommConnectCbParams &aParams):
175  handler(aHandler)
176 {
177 }
178 
179 void
181 {
183 }
184 
185 void
186 CommConnectCbPtrFun::print(std::ostream &os) const
187 {
188  os << '(';
189  params.print(os);
190  os << ')';
191 }
192 
193 /* CommIoCbPtrFun */
194 
197  handler(aHandler)
198 {
199 }
200 
201 void
203 {
205 }
206 
207 void
208 CommIoCbPtrFun::print(std::ostream &os) const
209 {
210  os << '(';
211  params.print(os);
212  os << ')';
213 }
214 
215 /* CommCloseCbPtrFun */
216 
218  const CommCloseCbParams &aParams):
220  handler(aHandler)
221 {
222 }
223 
224 void
226 {
227  handler(params);
228 }
229 
230 void
231 CommCloseCbPtrFun::print(std::ostream &os) const
232 {
233  os << '(';
234  params.print(os);
235  os << ')';
236 }
237 
238 /* CommTimeoutCbPtrFun */
239 
241  const CommTimeoutCbParams &aParams):
243  handler(aHandler)
244 {
245 }
246 
247 void
249 {
250  handler(params);
251 }
252 
253 void
254 CommTimeoutCbPtrFun::print(std::ostream &os) const
255 {
256  os << '(';
257  params.print(os);
258  os << ')';
259 }
260 
void IOACB(const CommAcceptCbParams &params)
Definition: CommCalls.h:31
CommConnectCbParams(void *aData)
Definition: CommCalls.cc:70
CommAcceptCbParams(void *aData)
Definition: CommCalls.cc:51
bool syncWithComm()
Definition: CommCalls.cc:106
void print(std::ostream &os) const
Definition: CommCalls.cc:34
CommConnectCbPtrFun(CNCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:172
AnyP::PortCfgPointer port
the configuration listening port this call relates to (may be nil)
Definition: CommCalls.h:100
void print(std::ostream &os) const override
Definition: CommCalls.cc:231
CommAcceptCbPtrFun(IOACB *aHandler, const CommAcceptCbParams &aParams)
Definition: CommCalls.cc:143
Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.
Definition: AcceptLimiter.h:16
int fd
FD which the call was about. Set by the async call creator.
Definition: CommCalls.h:85
@ OK
Definition: Flag.h:16
CommCloseCbPtrFun(CLCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:217
void CLCB(const CommCloseCbParams &params)
Definition: CommCalls.h:40
@ ERR_CLOSING
Definition: Flag.h:24
#define cbdataReference(var)
Definition: cbdata.h:348
void print(std::ostream &os) const override
Definition: CommCalls.cc:163
int xerrno
The last errno to occur. non-zero if flag is Comm::COMM_ERROR.
Definition: CommCalls.h:83
CommCommonCbParams(void *aData)
Definition: CommCalls.cc:18
void print(std::ostream &os) const
Definition: CommCalls.cc:118
void CNCB(const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno, void *data)
Definition: CommCalls.h:33
int size
Definition: ModDevPoll.cc:69
void CTCB(const CommTimeoutCbParams &params)
Definition: CommCalls.h:37
void print(std::ostream &os) const override
Definition: CommCalls.cc:254
void IOCB(const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag flag, int xerrno, void *data)
Definition: CommCalls.h:34
IOCB * handler
Definition: CommCalls.h:241
Comm::ConnectionPointer conn
Definition: CommCalls.h:80
#define assert(EX)
Definition: assert.h:17
Comm::Flag flag
comm layer result status.
Definition: CommCalls.h:82
#define cbdataReferenceDone(var)
Definition: cbdata.h:357
void print(std::ostream &os) const override
Definition: CommCalls.cc:208
#define fd_table
Definition: fde.h:189
CommCloseCbParams(void *aData)
Definition: CommCalls.cc:129
CommIoCbParams(void *aData)
Definition: CommCalls.cc:100
CommIoCbPtrFun(IOCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:195
void print(std::ostream &os) const
Definition: CommCalls.cc:60
bool isOpen() const
Definition: Connection.h:101
CommTimeoutCbPtrFun(CTCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:240
void print(std::ostream &os) const override
Definition: CommCalls.cc:186
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
CommTimeoutCbParams(void *aData)
Definition: CommCalls.cc:136

 

Introduction

Documentation

Support

Miscellaneous