]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Inquirer.cc
2 * DEBUG: section 16 Cache Manager API
7 #include "base/TextException.h"
9 #include "comm/Connection.h"
10 #include "comm/Write.h"
11 #include "CommCalls.h"
12 #include "HttpReply.h"
13 #include "HttpRequest.h"
14 #include "ipc/UdsOp.h"
15 #include "mgr/ActionWriter.h"
16 #include "mgr/IntParam.h"
17 #include "mgr/Inquirer.h"
18 #include "mgr/Command.h"
19 #include "mgr/Request.h"
20 #include "mgr/Response.h"
21 #include "SquidTime.h"
22 #include "errorpage.h"
26 CBDATA_NAMESPACED_CLASS_INIT(Mgr
, Inquirer
);
28 Mgr::Inquirer::Inquirer(Action::Pointer anAction
,
29 const Request
&aCause
, const Ipc::StrandCoords
&coords
):
30 Ipc::Inquirer(aCause
.clone(), applyQueryParams(coords
, aCause
.params
.queryParams
), anAction
->atomic() ? 10 : 100),
34 Ipc::ImportFdIntoComm(conn
, SOCK_STREAM
, IPPROTO_TCP
, Ipc::fdnHttpSocket
);
36 debugs(16, 5, HERE
<< conn
<< " action: " << aggrAction
);
38 closer
= asyncCall(16, 5, "Mgr::Inquirer::noteCommClosed",
39 CommCbMemFunT
<Inquirer
, CommCloseCbParams
>(this, &Inquirer::noteCommClosed
));
40 comm_add_close_handler(conn
->fd
, closer
);
43 /// closes our copy of the client HTTP connection socket
45 Mgr::Inquirer::cleanup()
47 if (Comm::IsConnOpen(conn
)) {
54 Mgr::Inquirer::removeCloseHandler()
57 comm_remove_close_handler(conn
->fd
, closer
);
63 Mgr::Inquirer::start()
66 Ipc::Inquirer::start();
67 Must(Comm::IsConnOpen(conn
));
68 Must(aggrAction
!= NULL
);
71 std::unique_ptr
<MemBuf
> replyBuf
;
73 std::auto_ptr
<MemBuf
> replyBuf
;
75 if (strands
.empty()) {
76 LOCAL_ARRAY(char, url
, MAX_URL
);
77 snprintf(url
, MAX_URL
, "%s", aggrAction
->command().params
.httpUri
.termedBuf());
78 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
79 ErrorState
err(ERR_INVALID_URL
, Http::scNotFound
, req
);
81 std::unique_ptr
<HttpReply
> reply(err
.BuildHttpReply());
83 std::auto_ptr
<HttpReply
> reply(err
.BuildHttpReply());
85 replyBuf
.reset(reply
->pack());
88 std::unique_ptr
<HttpReply
> reply(new HttpReply
);
90 std::auto_ptr
<HttpReply
> reply(new HttpReply
);
92 reply
->setHeaders(Http::scOkay
, NULL
, "text/plain", -1, squid_curtime
, squid_curtime
);
93 reply
->header
.putStr(HDR_CONNECTION
, "close"); // until we chunk response
94 replyBuf
.reset(reply
->pack());
96 writer
= asyncCall(16, 5, "Mgr::Inquirer::noteWroteHeader",
97 CommCbMemFunT
<Inquirer
, CommIoCbParams
>(this, &Inquirer::noteWroteHeader
));
98 Comm::Write(conn
, replyBuf
.get(), writer
);
101 /// called when we wrote the response header
103 Mgr::Inquirer::noteWroteHeader(const CommIoCbParams
& params
)
107 Must(params
.flag
== COMM_OK
);
108 Must(params
.conn
.getRaw() == conn
.getRaw());
109 Must(params
.size
!= 0);
110 // start inquiries at the initial pos
114 /// called when the HTTP client or some external force closed our socket
116 Mgr::Inquirer::noteCommClosed(const CommCloseCbParams
& params
)
119 Must(!Comm::IsConnOpen(conn
) && params
.conn
.getRaw() == conn
.getRaw());
121 mustStop("commClosed");
125 Mgr::Inquirer::aggregate(Ipc::Response::Pointer aResponse
)
127 Mgr::Response
& response
= static_cast<Response
&>(*aResponse
);
128 if (response
.hasAction())
129 aggrAction
->add(response
.getAction());
134 Mgr::Inquirer::sendResponse()
136 if (!strands
.empty() && aggrAction
->aggregatable()) {
137 removeCloseHandler();
138 AsyncJob::Start(new ActionWriter(aggrAction
, conn
));
139 conn
= NULL
; // should not close because we passed it to ActionWriter
144 Mgr::Inquirer::doneAll() const
146 return !writer
&& Ipc::Inquirer::doneAll();
150 Mgr::Inquirer::applyQueryParams(const Ipc::StrandCoords
& aStrands
, const QueryParams
& aParams
)
152 Ipc::StrandCoords sc
;
154 QueryParam::Pointer processesParam
= aParams
.get("processes");
155 QueryParam::Pointer workersParam
= aParams
.get("workers");
157 if (processesParam
== NULL
|| workersParam
== NULL
) {
158 if (processesParam
!= NULL
) {
159 IntParam
* param
= dynamic_cast<IntParam
*>(processesParam
.getRaw());
160 if (param
!= NULL
&& param
->type
== QueryParam::ptInt
) {
161 const std::vector
<int>& processes
= param
->value();
162 for (Ipc::StrandCoords::const_iterator iter
= aStrands
.begin();
163 iter
!= aStrands
.end(); ++iter
) {
164 if (std::find(processes
.begin(), processes
.end(), iter
->kidId
) != processes
.end())
168 } else if (workersParam
!= NULL
) {
169 IntParam
* param
= dynamic_cast<IntParam
*>(workersParam
.getRaw());
170 if (param
!= NULL
&& param
->type
== QueryParam::ptInt
) {
171 const std::vector
<int>& workers
= param
->value();
172 for (int i
= 0; i
< (int)aStrands
.size(); ++i
) {
173 if (std::find(workers
.begin(), workers
.end(), i
+ 1) != workers
.end())
174 sc
.push_back(aStrands
[i
]);
182 debugs(16, 4, HERE
<< "strands kid IDs = ");
183 for (Ipc::StrandCoords::const_iterator iter
= sc
.begin(); iter
!= sc
.end(); ++iter
) {
184 debugs(16, 4, HERE
<< iter
->kidId
);