Logo ROOT   6.14/05
Reference Guide
THttpLongPollEngine.h
Go to the documentation of this file.
1 // $Id$
2 // Author: Sergey Linev 8/01/2018
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_THttpLongPollEngine
13 #define ROOT_THttpLongPollEngine
14 
15 #include "THttpWSEngine.h"
16 
17 #include <string>
18 #include <queue>
19 
20 class THttpServer;
21 
23  friend class THttpServer;
24 
25 protected:
26  struct QueueItem {
27  bool fBinary{false}; ///<! is binary data
28  std::string fData; ///<! text or binary data
29  std::string fHdr; ///<! optional header for raw data
30  QueueItem(bool bin, std::string &&data, const std::string &hdr = "") : fBinary(bin), fData(data), fHdr(hdr) {}
31  };
32 
33  bool fRaw{false}; ///!< if true, only content can be used for data transfer
34  std::shared_ptr<THttpCallArg> fPoll; ///!< hold polling request, which can be immediately used for the next sending
35  std::queue<QueueItem> fQueue; ///!< entries submitted to client
36  static const std::string gLongPollNope; ///!< default reply on the longpoll request
37 
38  std::string MakeBuffer(const void *buf, int len, const char *hdr = nullptr);
39 
40 public:
41  THttpLongPollEngine(bool raw = false);
42 
43  virtual UInt_t GetId() const;
44 
45  virtual void ClearHandle();
46 
47  virtual void Send(const void *buf, int len);
48 
49  virtual void SendCharStar(const char *buf);
50 
51  virtual void SendHeader(const char *hdr, const void *buf, int len);
52 
53  virtual Bool_t PreviewData(std::shared_ptr<THttpCallArg> &arg);
54 
55  virtual void PostProcess(std::shared_ptr<THttpCallArg> &arg);
56 };
57 
58 #endif
virtual void PostProcess(std::shared_ptr< THttpCallArg > &arg)
Normally requests from client does not replied directly for longpoll socket Therefore one can use suc...
virtual UInt_t GetId() const
returns ID of the engine, created from this pointer
std::string fHdr
! optional header for raw data
virtual void Send(const void *buf, int len)
Send binary data via connection - not supported.
bool Bool_t
Definition: RtypesCore.h:59
static const std::string gLongPollNope
!< entries submitted to client
std::string MakeBuffer(const void *buf, int len, const char *hdr=nullptr)
!< default reply on the longpoll request
std::shared_ptr< THttpCallArg > fPoll
!< if true, only content can be used for data transfer
std::queue< QueueItem > fQueue
!< hold polling request, which can be immediately used for the next sending
virtual void ClearHandle()
clear request, waiting for next portion of data
virtual void SendCharStar(const char *buf)
Send const char data Either do it immediately or keep in internal buffer.
THttpLongPollEngine(bool raw=false)
constructor
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SendHeader(const char *hdr, const void *buf, int len)
Send binary data with text header via connection - not supported.
virtual Bool_t PreviewData(std::shared_ptr< THttpCallArg > &arg)
Preview data for given socket function called in the user code before processing correspondent websoc...
std::string fData
! text or binary data
QueueItem(bool bin, std::string &&data, const std::string &hdr="")