]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CommCalls.cc
Comm restructure part 2 - outbound connections
[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 bool
59 CommConnectCbParams::syncWithComm()
60 {
61 // drop the call if the call was scheduled before comm_close but
62 // is being fired after comm_close
63 if (fd >= 0 && fd_table[fd].closing()) {
64 debugs(5, 3, HERE << "droppin late connect call: FD " << fd);
65 return false;
66 }
67 return true; // now we are in sync and can handle the call
68 }
69
70 void
71 CommConnectCbParams::print(std::ostream &os) const
72 {
73 CommCommonCbParams::print(os);
74 }
75
76 /* CommIoCbParams */
77
78 CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData),
79 buf(NULL), size(0)
80 {
81 }
82
83 bool
84 CommIoCbParams::syncWithComm()
85 {
86 // change parameters if the call was scheduled before comm_close but
87 // is being fired after comm_close
88 if (fd >= 0 && fd_table[fd].closing() && flag != COMM_ERR_CLOSING) {
89 debugs(5, 3, HERE << "converting late call to COMM_ERR_CLOSING: FD " << fd);
90 flag = COMM_ERR_CLOSING;
91 size = 0;
92 }
93 return true; // now we are in sync and can handle the call
94 }
95
96
97 void
98 CommIoCbParams::print(std::ostream &os) const
99 {
100 CommCommonCbParams::print(os);
101 if (buf) {
102 os << ", size=" << size;
103 os << ", buf=" << (void*)buf;
104 }
105 }
106
107
108 /* CommCloseCbParams */
109
110 CommCloseCbParams::CommCloseCbParams(void *aData):
111 CommCommonCbParams(aData)
112 {
113 }
114
115 /* CommTimeoutCbParams */
116
117 CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
118 CommCommonCbParams(aData)
119 {
120 }
121
122
123 /* CommAcceptCbPtrFun */
124
125 CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
126 const CommAcceptCbParams &aParams):
127 CommDialerParamsT<CommAcceptCbParams>(aParams),
128 handler(aHandler)
129 {
130 }
131
132 void
133 CommAcceptCbPtrFun::dial()
134 {
135 handler(params.fd, params.nfd, params.details, params.flag, params.xerrno, params.data);
136 }
137
138 void
139 CommAcceptCbPtrFun::print(std::ostream &os) const
140 {
141 os << '(';
142 params.print(os);
143 os << ')';
144 }
145
146
147 /* CommConnectCbPtrFun */
148
149 CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB *aHandler,
150 const CommConnectCbParams &aParams):
151 CommDialerParamsT<CommConnectCbParams>(aParams),
152 handler(aHandler)
153 {
154 }
155
156 void
157 CommConnectCbPtrFun::dial()
158 {
159 handler(params.conn, params.paths, params.flag, params.xerrno, params.data);
160 }
161
162 void
163 CommConnectCbPtrFun::print(std::ostream &os) const
164 {
165 os << '(';
166 params.print(os);
167 os << ')';
168 }
169
170
171 /* CommIoCbPtrFun */
172
173 CommIoCbPtrFun::CommIoCbPtrFun(IOCB *aHandler, const CommIoCbParams &aParams):
174 CommDialerParamsT<CommIoCbParams>(aParams),
175 handler(aHandler)
176 {
177 }
178
179 void
180 CommIoCbPtrFun::dial()
181 {
182 handler(params.fd, params.buf, params.size, params.flag, params.xerrno, params.data);
183 }
184
185 void
186 CommIoCbPtrFun::print(std::ostream &os) const
187 {
188 os << '(';
189 params.print(os);
190 os << ')';
191 }
192
193
194 /* CommCloseCbPtrFun */
195
196 CommCloseCbPtrFun::CommCloseCbPtrFun(PF *aHandler,
197 const CommCloseCbParams &aParams):
198 CommDialerParamsT<CommCloseCbParams>(aParams),
199 handler(aHandler)
200 {
201 }
202
203 void
204 CommCloseCbPtrFun::dial()
205 {
206 handler(params.fd, params.data);
207 }
208
209 void
210 CommCloseCbPtrFun::print(std::ostream &os) const
211 {
212 os << '(';
213 params.print(os);
214 os << ')';
215 }
216
217 /* CommTimeoutCbPtrFun */
218
219 CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(PF *aHandler,
220 const CommTimeoutCbParams &aParams):
221 CommDialerParamsT<CommTimeoutCbParams>(aParams),
222 handler(aHandler)
223 {
224 }
225
226 void
227 CommTimeoutCbPtrFun::dial()
228 {
229 handler(params.fd, params.data);
230 }
231
232 void
233 CommTimeoutCbPtrFun::print(std::ostream &os) const
234 {
235 os << '(';
236 params.print(os);
237 os << ')';
238 }