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
33void
34CommCommonCbParams::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
53{
54}
55
56// XXX: Add CommAcceptCbParams::syncWithComm(). Adjust syncWithComm() API if all
57// implementations always return true.
58
59void
60CommAcceptCbParams::print(std::ostream &os) const
61{
63
64 if (port && port->listenConn)
65 os << ", " << port->listenConn->codeContextGist();
66}
67
68/* CommConnectCbParams */
69
72{
73}
74
75bool
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);
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
105bool
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
117void
118CommIoCbParams::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
153{
154}
155
156void
158{
160}
161
162void
163CommAcceptCbPtrFun::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
179void
181{
183}
184
185void
186CommConnectCbPtrFun::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
201void
203{
205}
206
207void
208CommIoCbPtrFun::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
224void
226{
228}
229
230void
231CommCloseCbPtrFun::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
247void
249{
251}
252
253void
254CommTimeoutCbPtrFun::print(std::ostream &os) const
255{
256 os << '(';
257 params.print(os);
258 os << ')';
259}
260
void CTCB(const CommTimeoutCbParams &params)
Definition: CommCalls.h:37
void IOCB(const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag flag, int xerrno, void *data)
Definition: CommCalls.h:34
void IOACB(const CommAcceptCbParams &params)
Definition: CommCalls.h:31
void CLCB(const CommCloseCbParams &params)
Definition: CommCalls.h:40
void CNCB(const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno, void *data)
Definition: CommCalls.h:33
int size
Definition: ModDevPoll.cc:75
int conn
the current server connection FD
Definition: Transport.cc:26
#define assert(EX)
Definition: assert.h:17
#define cbdataReferenceDone(var)
Definition: cbdata.h:352
#define cbdataReference(var)
Definition: cbdata.h:343
AnyP::PortCfgPointer port
the configuration listening port this call relates to (may be nil)
Definition: CommCalls.h:100
void print(std::ostream &os) const
Definition: CommCalls.cc:60
CommAcceptCbParams(void *aData)
Definition: CommCalls.cc:51
CommAcceptCbPtrFun(IOACB *aHandler, const CommAcceptCbParams &aParams)
Definition: CommCalls.cc:143
void print(std::ostream &os) const override
Definition: CommCalls.cc:163
CommCloseCbParams(void *aData)
Definition: CommCalls.cc:129
void print(std::ostream &os) const override
Definition: CommCalls.cc:231
CommCloseCbPtrFun(CLCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:217
int xerrno
The last errno to occur. non-zero if flag is Comm::COMM_ERROR.
Definition: CommCalls.h:83
int fd
FD which the call was about. Set by the async call creator.
Definition: CommCalls.h:85
void print(std::ostream &os) const
Definition: CommCalls.cc:34
Comm::Flag flag
comm layer result status.
Definition: CommCalls.h:82
Comm::ConnectionPointer conn
Definition: CommCalls.h:80
CommCommonCbParams(void *aData)
Definition: CommCalls.cc:18
CommConnectCbParams(void *aData)
Definition: CommCalls.cc:70
void print(std::ostream &os) const override
Definition: CommCalls.cc:186
CommConnectCbPtrFun(CNCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:172
void print(std::ostream &os) const
Definition: CommCalls.cc:118
bool syncWithComm()
Definition: CommCalls.cc:106
CommIoCbParams(void *aData)
Definition: CommCalls.cc:100
CommIoCbPtrFun(IOCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:195
IOCB * handler
Definition: CommCalls.h:241
void print(std::ostream &os) const override
Definition: CommCalls.cc:208
CommTimeoutCbParams(void *aData)
Definition: CommCalls.cc:136
void print(std::ostream &os) const override
Definition: CommCalls.cc:254
CommTimeoutCbPtrFun(CTCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:240
bool isOpen() const
Definition: Connection.h:101
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:193
#define fd_table
Definition: fde.h:189
Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.
Definition: AcceptLimiter.h:17
@ OK
Definition: Flag.h:16
@ ERR_CLOSING
Definition: Flag.h:24
static void handler(int signo)
Definition: purge.cc:858

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors