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