30 const std::string THttpLongPollEngine::gLongPollNope =
"<<nope>>";
35 THttpLongPollEngine::THttpLongPollEngine(
bool raw) : THttpWSEngine(), fRaw(raw)
42 UInt_t THttpLongPollEngine::GetId()
const
44 const void *ptr = (
const void *)
this;
45 return TString::Hash((
void *)&ptr,
sizeof(
void *));
51 void THttpLongPollEngine::ClearHandle(Bool_t)
53 std::shared_ptr<THttpCallArg> poll;
56 std::lock_guard<std::mutex> grd(fMutex);
57 poll = std::move(fPoll);
62 poll->NotifyCondition();
70 std::string THttpLongPollEngine::MakeBuffer(
const void *buf,
int len,
const char *hdr)
76 std::copy((
const char *)buf, (
const char *)buf + len, res.begin());
80 int hdrlen = hdr ? strlen(hdr) : 0;
81 std::string hdrstr =
"bin:";
82 hdrstr.append(std::to_string(hdrlen));
84 while ((hdrstr.length() + 1 + hdrlen) % 8 != 0)
90 res.resize(hdrstr.length() + len);
91 std::copy(hdrstr.begin(), hdrstr.begin() + hdrstr.length(), res.begin());
92 std::copy((
const char *)buf, (
const char *)buf + len, res.begin() + hdrstr.length());
100 void THttpLongPollEngine::Send(
const void *buf,
int len)
102 std::shared_ptr<THttpCallArg> poll;
105 std::lock_guard<std::mutex> grd(fMutex);
106 poll = std::move(fPoll);
110 Error(
"Send",
"Operation invoked before polling request obtained");
114 std::string buf2 = MakeBuffer(buf, len);
116 poll->SetBinaryContent(std::move(buf2));
117 poll->NotifyCondition();
123 void THttpLongPollEngine::SendHeader(
const char *hdr,
const void *buf,
int len)
125 std::shared_ptr<THttpCallArg> poll;
128 std::lock_guard<std::mutex> grd(fMutex);
129 poll = std::move(fPoll);
133 Error(
"SendHeader",
"Operation invoked before polling request obtained");
137 std::string buf2 = MakeBuffer(buf, len, hdr);
139 poll->SetBinaryContent(std::move(buf2));
141 poll->SetExtraHeader(
"LongpollHeader", hdr);
142 poll->NotifyCondition();
149 void THttpLongPollEngine::SendCharStar(
const char *buf)
151 std::shared_ptr<THttpCallArg> poll;
154 std::lock_guard<std::mutex> grd(fMutex);
155 poll = std::move(fPoll);
159 Error(
"SendCharStart",
"Operation invoked before polling request obtained");
163 std::string sendbuf(fRaw ?
"txt:" :
"");
166 if (fRaw) poll->SetBinaryContent(std::move(sendbuf));
167 else poll->SetTextContent(std::move(sendbuf));
168 poll->NotifyCondition();
176 Bool_t THttpLongPollEngine::PreProcess(std::shared_ptr<THttpCallArg> &arg)
178 if (!strstr(arg->GetQuery(),
"&dummy"))
183 std::shared_ptr<THttpCallArg> poll;
186 std::lock_guard<std::mutex> grd(fMutex);
187 poll = std::move(fPoll);
192 Fatal(
"PreviewData",
"Submit same THttpCallArg object once again");
195 Error(
"PreviewData",
"Get next dummy request when previous not completed");
198 if (fRaw) poll->SetBinaryContent(std::string(
"txt:") + gLongPollNope);
199 else poll->SetTextContent(std::string(gLongPollNope));
200 poll->NotifyCondition();
211 void THttpLongPollEngine::PostProcess(std::shared_ptr<THttpCallArg> &arg)
213 if (fRaw) arg->SetBinaryContent(std::string(
"txt:") + gLongPollNope);
214 else arg->SetTextContent(std::string(gLongPollNope));
220 Bool_t THttpLongPollEngine::CanSendDirectly()
222 std::lock_guard<std::mutex> grd(fMutex);
223 return fPoll ? kTRUE : kFALSE;