BVB Source Codes

uWebSockets Show Hub.h Source code

Return Download uWebSockets: download Hub.h Source code - Download uWebSockets Source code - Type:.h
  1. #ifndef HUB_UWS_H
  2. #define HUB_UWS_H
  3.  
  4. #include "Group.h"
  5. #include "Node.h"
  6. #include <string>
  7. #include <zlib.h>
  8. #include <mutex>
  9. #include <map>
  10.  
  11. namespace uWS {
  12.  
  13. struct WIN32_EXPORT Hub : private uS::Node, public Group<SERVER>, public Group<CLIENT> {
  14. protected:
  15.     struct ConnectionData {
  16.         std::string path;
  17.         void *user;
  18.         Group<CLIENT> *group;
  19.     };
  20.  
  21.     z_stream inflationStream = {};
  22.     char *inflationBuffer;
  23.     char *inflate(char *data, size_t &length, size_t maxPayload);
  24.     std::string dynamicInflationBuffer;
  25.     static const int LARGE_BUFFER_SIZE = 300 * 1024;
  26.  
  27.     static void onServerAccept(uS::Socket *s);
  28.     static void onClientConnection(uS::Socket *s, bool error);
  29.  
  30. public:
  31.     template <bool isServer>
  32.     Group<isServer> *createGroup(int extensionOptions = 0, unsigned int maxPayload = 16777216) {
  33.         return new Group<isServer>(extensionOptions, maxPayload, this, nodeData);
  34.     }
  35.  
  36.     template <bool isServer>
  37.     Group<isServer> &getDefaultGroup() {
  38.         return static_cast<Group<isServer> &>(*this);
  39.     }
  40.  
  41.     bool listen(int port, uS::TLS::Context sslContext = nullptr, int options = 0, Group<SERVER> *eh = nullptr);
  42.     bool listen(const char *host, int port, uS::TLS::Context sslContext = nullptr, int options = 0, Group<SERVER> *eh = nullptr);
  43.     void connect(std::string uri, void *user = nullptr, std::map<std::string, std::string> extraHeaders = {}, int timeoutMs = 5000, Group<CLIENT> *eh = nullptr);
  44.     void upgrade(uv_os_sock_t fd, const char *secKey, SSL *ssl, const char *extensions, size_t extensionsLength, const char *subprotocol, size_t subprotocolLength, Group<SERVER> *serverGroup = nullptr);
  45.  
  46.     Hub(int extensionOptions = 0, bool useDefaultLoop = false, unsigned int maxPayload = 16777216) : uS::Node(LARGE_BUFFER_SIZE, WebSocketProtocol<SERVER, WebSocket<SERVER>>::CONSUME_PRE_PADDING, WebSocketProtocol<SERVER, WebSocket<SERVER>>::CONSUME_POST_PADDING, useDefaultLoop),
  47.                                              Group<SERVER>(extensionOptions, maxPayload, this, nodeData), Group<CLIENT>(0, maxPayload, this, nodeData) {
  48.         inflateInit2(&inflationStream, -15);
  49.         inflationBuffer = new char[LARGE_BUFFER_SIZE];
  50.  
  51. #ifdef UWS_THREADSAFE
  52.         getLoop()->preCbData = nodeData;
  53.         getLoop()->preCb = [](void *nodeData) {
  54.             static_cast<uS::NodeData *>(nodeData)->asyncMutex->lock();
  55.         };
  56.  
  57.         getLoop()->postCbData = nodeData;
  58.         getLoop()->postCb = [](void *nodeData) {
  59.             static_cast<uS::NodeData *>(nodeData)->asyncMutex->unlock();
  60.         };
  61. #endif
  62.     }
  63.  
  64.     ~Hub() {
  65.         inflateEnd(&inflationStream);
  66.         delete [] inflationBuffer;
  67.     }
  68.  
  69.     using uS::Node::run;
  70.     using uS::Node::getLoop;
  71.     using Group<SERVER>::onConnection;
  72.     using Group<CLIENT>::onConnection;
  73.     using Group<SERVER>::onTransfer;
  74.     using Group<SERVER>::onMessage;
  75.     using Group<CLIENT>::onMessage;
  76.     using Group<SERVER>::onDisconnection;
  77.     using Group<CLIENT>::onDisconnection;
  78.     using Group<SERVER>::onPing;
  79.     using Group<CLIENT>::onPing;
  80.     using Group<SERVER>::onPong;
  81.     using Group<CLIENT>::onPong;
  82.     using Group<SERVER>::onError;
  83.     using Group<CLIENT>::onError;
  84.     using Group<SERVER>::onHttpRequest;
  85.     using Group<SERVER>::onHttpData;
  86.     using Group<SERVER>::onHttpConnection;
  87.     using Group<SERVER>::onHttpDisconnection;
  88.     using Group<SERVER>::onHttpUpgrade;
  89.     using Group<SERVER>::onCancelledHttpRequest;
  90.  
  91.     friend struct WebSocket<SERVER>;
  92.     friend struct WebSocket<CLIENT>;
  93. };
  94.  
  95. }
  96.  
  97. #endif // HUB_UWS_H
  98.  
downloadHub.h Source code - Download uWebSockets Source code
Related Source Codes/Software:
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11

 Back to top