opal-up 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,92 +18,104 @@
18
18
  #ifndef UWS_WEBSOCKETCONTEXTDATA_H
19
19
  #define UWS_WEBSOCKETCONTEXTDATA_H
20
20
 
21
- #include "Loop.h"
22
21
  #include "AsyncSocket.h"
22
+ #include "Loop.h"
23
23
 
24
24
  #include "MoveOnlyFunction.h"
25
25
  #include <string_view>
26
26
  #include <vector>
27
27
 
28
- #include "WebSocketProtocol.h"
29
28
  #include "TopicTree.h"
30
29
  #include "WebSocketData.h"
30
+ #include "WebSocketProtocol.h"
31
31
 
32
32
  namespace uWS {
33
33
 
34
34
  /* Type queued up when publishing */
35
35
  struct TopicTreeMessage {
36
- std::string message;
37
- /*OpCode*/ int opCode;
38
- bool compress;
36
+ std::string message;
37
+ /*OpCode*/ int opCode;
38
+ bool compress;
39
39
  };
40
40
  struct TopicTreeBigMessage {
41
- std::string_view message;
42
- /*OpCode*/ int opCode;
43
- bool compress;
41
+ std::string_view message;
42
+ /*OpCode*/ int opCode;
43
+ bool compress;
44
44
  };
45
45
 
46
46
  template <bool, bool, typename> struct WebSocket;
47
47
 
48
- /* todo: this looks identical to WebSocketBehavior, why not just std::move that entire thing in? */
48
+ /* todo: this looks identical to WebSocketBehavior, why not just std::move that
49
+ * entire thing in? */
49
50
 
50
- template <bool SSL, typename USERDATA>
51
- struct WebSocketContextData {
51
+ template <bool SSL, typename USERDATA> struct WebSocketContextData {
52
52
  private:
53
-
54
53
  public:
55
-
56
- /* This one points to the App's shared topicTree */
57
- TopicTree<TopicTreeMessage, TopicTreeBigMessage> *topicTree;
58
-
59
- /* The callbacks for this context */
60
- MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *)> openHandler = nullptr;
61
- MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view, OpCode)> messageHandler = nullptr;
62
- MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view, OpCode)> droppedHandler = nullptr;
63
- MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *)> drainHandler = nullptr;
64
- MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view, int, int)> subscriptionHandler = nullptr;
65
- MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, int, std::string_view)> closeHandler = nullptr;
66
- MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view)> pingHandler = nullptr;
67
- MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view)> pongHandler = nullptr;
68
-
69
- /* Settings for this context */
70
- size_t maxPayloadLength = 0;
71
-
72
- /* We do need these for async upgrade */
73
- CompressOptions compression;
74
-
75
- /* There needs to be a maxBackpressure which will force close everything over that limit */
76
- size_t maxBackpressure = 0;
77
- bool closeOnBackpressureLimit;
78
- bool resetIdleTimeoutOnSend;
79
- bool sendPingsAutomatically;
80
- unsigned short maxLifetime;
81
-
82
- /* These are calculated on creation */
83
- std::pair<unsigned short, unsigned short> idleTimeoutComponents;
84
-
85
- /* This is run once on start-up */
86
- void calculateIdleTimeoutCompnents(unsigned short idleTimeout) {
87
- unsigned short margin = 4;
88
- /* 4, 8 or 16 seconds margin based on idleTimeout */
89
- while ((int) idleTimeout - margin * 2 >= margin * 2 && margin < 16) {
90
- margin = (unsigned short) (margin << 1);
91
- }
92
- idleTimeoutComponents = {
93
- idleTimeout - (sendPingsAutomatically ? margin : 0), /* reduce normal idleTimeout if it is extended by ping-timeout */
94
- margin /* ping-timeout - also used for end() timeout */
95
- };
96
- }
97
-
98
- ~WebSocketContextData() {
99
-
100
- }
101
-
102
- WebSocketContextData(TopicTree<TopicTreeMessage, TopicTreeBigMessage> *topicTree) : topicTree(topicTree) {
103
-
54
+ /* This one points to the App's shared topicTree */
55
+ TopicTree<TopicTreeMessage, TopicTreeBigMessage> *topicTree;
56
+
57
+ /* The callbacks for this context */
58
+ MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *)> openHandler =
59
+ nullptr;
60
+ MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view,
61
+ OpCode)>
62
+ messageHandler = nullptr;
63
+ MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view,
64
+ OpCode)>
65
+ droppedHandler = nullptr;
66
+ MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *)> drainHandler =
67
+ nullptr;
68
+ MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view, int,
69
+ int)>
70
+ subscriptionHandler = nullptr;
71
+ MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, int,
72
+ std::string_view)>
73
+ closeHandler = nullptr;
74
+ MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view)>
75
+ pingHandler = nullptr;
76
+ MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view)>
77
+ pongHandler = nullptr;
78
+
79
+ /* Settings for this context */
80
+ size_t maxPayloadLength = 0;
81
+
82
+ /* We do need these for async upgrade */
83
+ CompressOptions compression;
84
+
85
+ /* There needs to be a maxBackpressure which will force close everything over
86
+ * that limit */
87
+ size_t maxBackpressure = 0;
88
+ bool closeOnBackpressureLimit;
89
+ bool resetIdleTimeoutOnSend;
90
+ bool sendPingsAutomatically;
91
+ unsigned short maxLifetime;
92
+
93
+ /* These are calculated on creation */
94
+ std::pair<unsigned short, unsigned short> idleTimeoutComponents;
95
+
96
+ /* This is run once on start-up */
97
+ void calculateIdleTimeoutCompnents(unsigned short idleTimeout) {
98
+ unsigned short margin = 4;
99
+ /* 4, 8 or 16 seconds margin based on idleTimeout */
100
+ while ((int)idleTimeout - margin * 2 >= margin * 2 && margin < 16) {
101
+ margin = (unsigned short)(margin << 1);
104
102
  }
103
+ idleTimeoutComponents = {
104
+ idleTimeout - (sendPingsAutomatically
105
+ ? margin
106
+ : 0), /* reduce normal idleTimeout if it is extended
107
+ by ping-timeout */
108
+ margin /* ping-timeout - also used for end() timeout */
109
+ };
110
+ }
111
+
112
+ ~WebSocketContextData() {}
113
+
114
+ WebSocketContextData(
115
+ TopicTree<TopicTreeMessage, TopicTreeBigMessage> *topicTree)
116
+ : topicTree(topicTree) {}
105
117
  };
106
118
 
107
- }
119
+ } // namespace uWS
108
120
 
109
121
  #endif // UWS_WEBSOCKETCONTEXTDATA_H
@@ -18,69 +18,76 @@
18
18
  #ifndef UWS_WEBSOCKETDATA_H
19
19
  #define UWS_WEBSOCKETDATA_H
20
20
 
21
- #include "WebSocketProtocol.h"
22
21
  #include "AsyncSocketData.h"
23
22
  #include "PerMessageDeflate.h"
24
23
  #include "TopicTree.h"
24
+ #include "WebSocketProtocol.h"
25
25
 
26
26
  #include <string>
27
27
 
28
28
  namespace uWS {
29
29
 
30
30
  struct WebSocketData : AsyncSocketData<false>, WebSocketState<true> {
31
- /* This guy has a lot of friends - why? */
32
- template <bool, bool, typename> friend struct WebSocketContext;
33
- template <bool, typename> friend struct WebSocketContextData;
34
- template <bool, bool, typename> friend struct WebSocket;
35
- template <bool> friend struct HttpContext;
31
+ /* This guy has a lot of friends - why? */
32
+ template <bool, bool, typename> friend struct WebSocketContext;
33
+ template <bool, typename> friend struct WebSocketContextData;
34
+ template <bool, bool, typename> friend struct WebSocket;
35
+ template <bool> friend struct HttpContext;
36
+
36
37
  private:
37
- std::string fragmentBuffer;
38
- unsigned int controlTipLength = 0;
39
- bool isShuttingDown = 0;
40
- bool hasTimedOut = false;
41
- enum CompressionStatus : char {
42
- DISABLED,
43
- ENABLED,
44
- COMPRESSED_FRAME
45
- } compressionStatus;
46
-
47
- /* We might have a dedicated compressor */
48
- DeflationStream *deflationStream = nullptr;
49
- /* And / or a dedicated decompressor */
50
- InflationStream *inflationStream = nullptr;
51
-
52
- /* We could be a subscriber */
53
- Subscriber *subscriber = nullptr;
38
+ std::string fragmentBuffer;
39
+ unsigned int controlTipLength = 0;
40
+ bool isShuttingDown = 0;
41
+ bool hasTimedOut = false;
42
+ enum CompressionStatus : char {
43
+ DISABLED,
44
+ ENABLED,
45
+ COMPRESSED_FRAME
46
+ } compressionStatus;
47
+
48
+ /* We might have a dedicated compressor */
49
+ DeflationStream *deflationStream = nullptr;
50
+ /* And / or a dedicated decompressor */
51
+ InflationStream *inflationStream = nullptr;
52
+
53
+ /* We could be a subscriber */
54
+ Subscriber *subscriber = nullptr;
55
+
54
56
  public:
55
- WebSocketData(bool perMessageDeflate, CompressOptions compressOptions, BackPressure &&backpressure) : AsyncSocketData<false>(std::move(backpressure)), WebSocketState<true>() {
56
- compressionStatus = perMessageDeflate ? ENABLED : DISABLED;
57
-
58
- /* Initialize the dedicated sliding window(s) */
59
- if (perMessageDeflate) {
60
- if ((compressOptions & CompressOptions::_COMPRESSOR_MASK) != CompressOptions::SHARED_COMPRESSOR) {
61
- deflationStream = new DeflationStream(compressOptions);
62
- }
63
- if ((compressOptions & CompressOptions::_DECOMPRESSOR_MASK) != CompressOptions::SHARED_DECOMPRESSOR) {
64
- inflationStream = new InflationStream(compressOptions);
65
- }
66
- }
57
+ WebSocketData(bool perMessageDeflate, CompressOptions compressOptions,
58
+ BackPressure &&backpressure)
59
+ : AsyncSocketData<false>(std::move(backpressure)),
60
+ WebSocketState<true>() {
61
+ compressionStatus = perMessageDeflate ? ENABLED : DISABLED;
62
+
63
+ /* Initialize the dedicated sliding window(s) */
64
+ if (perMessageDeflate) {
65
+ if ((compressOptions & CompressOptions::_COMPRESSOR_MASK) !=
66
+ CompressOptions::SHARED_COMPRESSOR) {
67
+ deflationStream = new DeflationStream(compressOptions);
68
+ }
69
+ if ((compressOptions & CompressOptions::_DECOMPRESSOR_MASK) !=
70
+ CompressOptions::SHARED_DECOMPRESSOR) {
71
+ inflationStream = new InflationStream(compressOptions);
72
+ }
67
73
  }
74
+ }
68
75
 
69
- ~WebSocketData() {
70
- if (deflationStream) {
71
- delete deflationStream;
72
- }
76
+ ~WebSocketData() {
77
+ if (deflationStream) {
78
+ delete deflationStream;
79
+ }
73
80
 
74
- if (inflationStream) {
75
- delete inflationStream;
76
- }
81
+ if (inflationStream) {
82
+ delete inflationStream;
83
+ }
77
84
 
78
- if (subscriber) {
79
- delete subscriber;
80
- }
85
+ if (subscriber) {
86
+ delete subscriber;
81
87
  }
88
+ }
82
89
  };
83
90
 
84
- }
91
+ } // namespace uWS
85
92
 
86
93
  #endif // UWS_WEBSOCKETDATA_H