43 const void *ptr = (
const void *)
this;
52 std::shared_ptr<THttpCallArg> poll;
55 std::lock_guard<std::mutex> grd(
fMutex);
56 poll = std::move(
fPoll);
61 poll->NotifyCondition();
75 std::copy((
const char *)buf, (
const char *)buf + len, res.begin());
79 int hdrlen = hdr ? strlen(hdr) : 0;
80 std::string hdrstr =
"bin:";
81 hdrstr.append(std::to_string(hdrlen));
83 while ((hdrstr.length() + 1 + hdrlen) % 8 != 0)
89 res.resize(hdrstr.length() + len);
90 std::copy(hdrstr.begin(), hdrstr.begin() + hdrstr.length(), res.begin());
91 std::copy((
const char *)buf, (
const char *)buf + len, res.begin() + hdrstr.length());
101 std::shared_ptr<THttpCallArg> poll;
106 std::lock_guard<std::mutex> grd(
fMutex);
108 poll = std::move(
fPoll);
111 std::swap(
fBuf, sendbuf);
117 Error(
"Send",
"Operation invoked before polling request obtained");
121 poll->SetBinaryContent(std::move(sendbuf));
122 poll->NotifyCondition();
130 std::shared_ptr<THttpCallArg> poll;
132 std::string sendbuf =
MakeBuffer(buf, len, hdr);
135 std::lock_guard<std::mutex> grd(
fMutex);
137 poll = std::move(
fPoll);
141 std::swap(
fBuf, sendbuf);
147 Error(
"SendHeader",
"Operation invoked before polling request obtained");
151 poll->SetBinaryContent(std::move(sendbuf));
153 poll->SetExtraHeader(
"LongpollHeader", hdr);
154 poll->NotifyCondition();
163 std::shared_ptr<THttpCallArg> poll;
165 std::string sendbuf(
fRaw ?
"txt:" :
"");
169 std::lock_guard<std::mutex> grd(
fMutex);
171 poll = std::move(
fPoll);
174 std::swap(
fBuf, sendbuf);
180 Error(
"SendCharStart",
"Operation invoked before polling request obtained");
184 if (
fRaw) poll->SetBinaryContent(std::move(sendbuf));
185 else poll->SetTextContent(std::move(sendbuf));
186 poll->NotifyCondition();
196 if (!strstr(arg->GetQuery(),
"&dummy"))
199 std::shared_ptr<THttpCallArg> poll;
202 if (arg->CanPostpone()) {
203 std::lock_guard<std::mutex> grd(
fMutex);
209 poll = std::move(
fPoll);
220 poll->NotifyCondition();
234 std::string sendbuf, sendhdr;
237 std::lock_guard<std::mutex> grd(
fMutex);
241 std::swap(sendbuf,
fBuf);
247 arg->SetTextContent(std::move(sendbuf));
249 arg->SetBinaryContent(std::move(sendbuf));
250 if (!sendhdr.empty())
251 arg->SetExtraHeader(
"LongpollHeader", sendhdr.c_str());
264 std::lock_guard<std::mutex> grd(
fMutex);
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
std::string fBufHeader
!< buffered data
std::string MakeBuffer(const void *buf, int len, const char *hdr=nullptr)
!< default reply on the longpoll request
std::shared_ptr< THttpCallArg > fPoll
!< protect polling request to use it from different threads
void Send(const void *buf, int len) override
Send binary data via connection.
void SendHeader(const char *hdr, const void *buf, int len) override
Send binary data with text header via connection.
std::mutex fMutex
!< if true, only content can be used for data transfer
virtual Bool_t CanSendDirectly() override
Indicate that polling requests is there or buffer empty and can be immediately invoked.
THttpLongPollEngine(bool raw=false)
constructor
static const std::string gLongPollNope
!< buffered header
void ClearHandle(Bool_t) override
clear request, normally called shortly before destructor
void SendCharStar(const char *buf) override
Send const char data Either do it immediately or keep in internal buffer.
Bool_t PreProcess(std::shared_ptr< THttpCallArg > &arg) override
Preview data for given socket Method called by WS handler before processing websocket data Returns kT...
EBufKind fBufKind
!< hold polling request, which can be immediately used for the next sending
UInt_t GetId() const override
returns ID of the engine, created from this pointer
void PostProcess(std::shared_ptr< THttpCallArg > &arg) override
Normally requests from client does not replied directly for longpoll socket Therefore one can use suc...
std::string fBuf
!< if buffered data available
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.