]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Inquirer.cc
4 * DEBUG: section 16 Cache Manager API
9 #include "base/TextException.h"
10 #include "comm/Connection.h"
11 #include "comm/Write.h"
12 #include "CommCalls.h"
13 #include "HttpReply.h"
14 #include "HttpRequest.h"
15 #include "ipc/UdsOp.h"
16 #include "mgr/ActionWriter.h"
17 #include "mgr/IntParam.h"
18 #include "mgr/Inquirer.h"
19 #include "mgr/Command.h"
20 #include "mgr/Request.h"
21 #include "mgr/Response.h"
22 #include "SquidTime.h"
23 #include "errorpage.h"
28 CBDATA_NAMESPACED_CLASS_INIT(Mgr
, Inquirer
);
31 Mgr::Inquirer::Inquirer(Action::Pointer anAction
,
32 const Request
&aCause
, const Ipc::StrandCoords
&coords
):
33 Ipc::Inquirer(aCause
.clone(), applyQueryParams(coords
, aCause
.params
.queryParams
), anAction
->atomic() ? 10 : 100),
37 Ipc::ImportFdIntoComm(conn
, SOCK_STREAM
, IPPROTO_TCP
, Ipc::fdnHttpSocket
);
39 debugs(16, 5, HERE
<< conn
<< " action: " << aggrAction
);
41 closer
= asyncCall(16, 5, "Mgr::Inquirer::noteCommClosed",
42 CommCbMemFunT
<Inquirer
, CommCloseCbParams
>(this, &Inquirer::noteCommClosed
));
43 comm_add_close_handler(conn
->fd
, closer
);
46 /// closes our copy of the client HTTP connection socket
48 Mgr::Inquirer::cleanup()
50 if (Comm::IsConnOpen(conn
)) {
57 Mgr::Inquirer::removeCloseHandler()
60 comm_remove_close_handler(conn
->fd
, closer
);
66 Mgr::Inquirer::start()
69 Ipc::Inquirer::start();
70 Must(Comm::IsConnOpen(conn
));
71 Must(aggrAction
!= NULL
);
73 std::auto_ptr
<MemBuf
> replyBuf
;
74 if (strands
.empty()) {
75 LOCAL_ARRAY(char, url
, MAX_URL
);
76 snprintf(url
, MAX_URL
, "%s", aggrAction
->command().params
.httpUri
.termedBuf());
77 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
78 ErrorState
*err
= errorCon(ERR_INVALID_URL
, HTTP_NOT_FOUND
, req
);
79 std::auto_ptr
<HttpReply
> reply(err
->BuildHttpReply());
80 replyBuf
.reset(reply
->pack());
83 std::auto_ptr
<HttpReply
> reply(new HttpReply
);
84 reply
->setHeaders(HTTP_OK
, NULL
, "text/plain", -1, squid_curtime
, squid_curtime
);
85 reply
->header
.putStr(HDR_CONNECTION
, "close"); // until we chunk response
86 replyBuf
.reset(reply
->pack());
88 writer
= asyncCall(16, 5, "Mgr::Inquirer::noteWroteHeader",
89 CommCbMemFunT
<Inquirer
, CommIoCbParams
>(this, &Inquirer::noteWroteHeader
));
90 Comm::Write(conn
, replyBuf
.get(), writer
);
93 /// called when we wrote the response header
95 Mgr::Inquirer::noteWroteHeader(const CommIoCbParams
& params
)
99 Must(params
.flag
== COMM_OK
);
100 Must(params
.conn
.getRaw() == conn
.getRaw());
101 Must(params
.size
!= 0);
102 // start inquiries at the initial pos
106 /// called when the HTTP client or some external force closed our socket
108 Mgr::Inquirer::noteCommClosed(const CommCloseCbParams
& params
)
111 Must(!Comm::IsConnOpen(conn
) && params
.conn
.getRaw() == conn
.getRaw());
113 mustStop("commClosed");
117 Mgr::Inquirer::aggregate(Ipc::Response::Pointer aResponse
)
119 Mgr::Response
& response
= static_cast<Response
&>(*aResponse
);
120 if (response
.hasAction())
121 aggrAction
->add(response
.getAction());
126 Mgr::Inquirer::sendResponse()
128 if (!strands
.empty() && aggrAction
->aggregatable()) {
129 removeCloseHandler();
130 AsyncJob::Start(new ActionWriter(aggrAction
, conn
));
131 conn
= NULL
; // should not close because we passed it to ActionWriter
136 Mgr::Inquirer::doneAll() const
138 return !writer
&& Ipc::Inquirer::doneAll();
142 Mgr::Inquirer::applyQueryParams(const Ipc::StrandCoords
& aStrands
, const QueryParams
& aParams
)
144 Ipc::StrandCoords sc
;
146 QueryParam::Pointer processesParam
= aParams
.get("processes");
147 QueryParam::Pointer workersParam
= aParams
.get("workers");
149 if (processesParam
== NULL
|| workersParam
== NULL
) {
150 if (processesParam
!= NULL
) {
151 IntParam
* param
= dynamic_cast<IntParam
*>(processesParam
.getRaw());
152 if (param
!= NULL
&& param
->type
== QueryParam::ptInt
) {
153 const std::vector
<int>& processes
= param
->value();
154 for (Ipc::StrandCoords::const_iterator iter
= aStrands
.begin();
155 iter
!= aStrands
.end(); ++iter
) {
156 if (std::find(processes
.begin(), processes
.end(), iter
->kidId
) != processes
.end())
160 } else if (workersParam
!= NULL
) {
161 IntParam
* param
= dynamic_cast<IntParam
*>(workersParam
.getRaw());
162 if (param
!= NULL
&& param
->type
== QueryParam::ptInt
) {
163 const std::vector
<int>& workers
= param
->value();
164 for (int i
= 0; i
< (int)aStrands
.size(); ++i
) {
165 if (std::find(workers
.begin(), workers
.end(), i
+ 1) != workers
.end())
166 sc
.push_back(aStrands
[i
]);
174 debugs(0, 0, HERE
<< "strands kid IDs = ");
175 for (Ipc::StrandCoords::const_iterator iter
= sc
.begin(); iter
!= sc
.end(); ++iter
) {
176 debugs(0, 0, HERE
<< iter
->kidId
);