]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CommCalls.cc
Merge from upstream.
[thirdparty/squid.git] / src / CommCalls.cc
1 #include "squid.h"
2 #include "fde.h"
3 #include "CommCalls.h"
4
5 /* CommCommonCbParams */
6
7 CommCommonCbParams::CommCommonCbParams(void *aData):
8 data(cbdataReference(aData)), fd(-1), xerrno(0), flag(COMM_OK)
9 {
10 }
11
12 CommCommonCbParams::CommCommonCbParams(const CommCommonCbParams &p):
13 data(cbdataReference(p.data)), fd(p.fd), xerrno(p.xerrno), flag(p.flag)
14 {
15 }
16
17 CommCommonCbParams::~CommCommonCbParams()
18 {
19 cbdataReferenceDone(data);
20 }
21
22 void
23 CommCommonCbParams::print(std::ostream &os) const
24 {
25 os << "FD " << fd;
26 if (xerrno)
27 os << ", errno=" << xerrno;
28 if (flag != COMM_OK)
29 os << ", flag=" << flag;
30 if (data)
31 os << ", data=" << data;
32 }
33
34
35 /* CommAcceptCbParams */
36
37 CommAcceptCbParams::CommAcceptCbParams(void *aData): CommCommonCbParams(aData),
38 nfd(-1)
39 {
40 }
41
42 void
43 CommAcceptCbParams::print(std::ostream &os) const
44 {
45 CommCommonCbParams::print(os);
46 if (nfd >= 0)
47 os << ", newFD " << nfd;
48 }
49
50
51 /* CommConnectCbParams */
52
53 CommConnectCbParams::CommConnectCbParams(void *aData):
54 CommCommonCbParams(aData)
55 {
56 }
57
58
59 /* CommIoCbParams */
60
61 CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData),
62 buf(NULL), size(0)
63 {
64 }
65
66 void
67 CommIoCbParams::syncWithComm()
68 {
69 // change parameters if the call was scheduled before comm_close but
70 // is being fired after comm_close
71 if (fd >= 0 && fd_table[fd].closing() && flag != COMM_ERR_CLOSING) {
72 debugs(5, 3, HERE << "converting late call to COMM_ERR_CLOSING: FD " << fd);
73 flag = COMM_ERR_CLOSING;
74 size = 0;
75 }
76 }
77
78
79 void
80 CommIoCbParams::print(std::ostream &os) const
81 {
82 CommCommonCbParams::print(os);
83 if (buf) {
84 os << ", size=" << size;
85 os << ", buf=" << (void*)buf;
86 }
87 }
88
89
90 /* CommCloseCbParams */
91
92 CommCloseCbParams::CommCloseCbParams(void *aData):
93 CommCommonCbParams(aData)
94 {
95 }
96
97 /* CommTimeoutCbParams */
98
99 CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
100 CommCommonCbParams(aData)
101 {
102 }
103
104
105 /* CommAcceptCbPtrFun */
106
107 CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
108 const CommAcceptCbParams &aParams):
109 CommDialerParamsT<CommAcceptCbParams>(aParams),
110 handler(aHandler)
111 {
112 }
113
114 void
115 CommAcceptCbPtrFun::dial()
116 {
117 handler(params.fd, params.nfd, &params.details, params.flag, params.xerrno, params.data);
118 }
119
120 void
121 CommAcceptCbPtrFun::print(std::ostream &os) const
122 {
123 os << '(';
124 params.print(os);
125 os << ')';
126 }
127
128
129 /* CommConnectCbPtrFun */
130
131 CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB *aHandler,
132 const CommConnectCbParams &aParams):
133 CommDialerParamsT<CommConnectCbParams>(aParams),
134 handler(aHandler)
135 {
136 }
137
138 void
139 CommConnectCbPtrFun::dial()
140 {
141 handler(params.fd, params.flag, params.xerrno, params.data);
142 }
143
144 void
145 CommConnectCbPtrFun::print(std::ostream &os) const
146 {
147 os << '(';
148 params.print(os);
149 os << ')';
150 }
151
152
153 /* CommIoCbPtrFun */
154
155 CommIoCbPtrFun::CommIoCbPtrFun(IOCB *aHandler, const CommIoCbParams &aParams):
156 CommDialerParamsT<CommIoCbParams>(aParams),
157 handler(aHandler)
158 {
159 }
160
161 void
162 CommIoCbPtrFun::dial()
163 {
164 handler(params.fd, params.buf, params.size, params.flag, params.xerrno, params.data);
165 }
166
167 void
168 CommIoCbPtrFun::print(std::ostream &os) const
169 {
170 os << '(';
171 params.print(os);
172 os << ')';
173 }
174
175
176 /* CommCloseCbPtrFun */
177
178 CommCloseCbPtrFun::CommCloseCbPtrFun(PF *aHandler,
179 const CommCloseCbParams &aParams):
180 CommDialerParamsT<CommCloseCbParams>(aParams),
181 handler(aHandler)
182 {
183 }
184
185 void
186 CommCloseCbPtrFun::dial()
187 {
188 handler(params.fd, params.data);
189 }
190
191 void
192 CommCloseCbPtrFun::print(std::ostream &os) const
193 {
194 os << '(';
195 params.print(os);
196 os << ')';
197 }
198
199 /* CommTimeoutCbPtrFun */
200
201 CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(PF *aHandler,
202 const CommTimeoutCbParams &aParams):
203 CommDialerParamsT<CommTimeoutCbParams>(aParams),
204 handler(aHandler)
205 {
206 }
207
208 void
209 CommTimeoutCbPtrFun::dial()
210 {
211 handler(params.fd, params.data);
212 }
213
214 void
215 CommTimeoutCbPtrFun::print(std::ostream &os) const
216 {
217 os << '(';
218 params.print(os);
219 os << ')';
220 }