opal-up 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +66 -51
  3. data/ext/up_ext/App.h +665 -544
  4. data/ext/up_ext/AsyncSocket.h +307 -284
  5. data/ext/up_ext/AsyncSocketData.h +35 -51
  6. data/ext/up_ext/BloomFilter.h +37 -42
  7. data/ext/up_ext/ChunkedEncoding.h +174 -175
  8. data/ext/up_ext/ClientApp.h +20 -23
  9. data/ext/up_ext/HttpContext.h +476 -381
  10. data/ext/up_ext/HttpContextData.h +20 -20
  11. data/ext/up_ext/HttpErrors.h +14 -10
  12. data/ext/up_ext/HttpParser.h +631 -563
  13. data/ext/up_ext/HttpResponse.h +526 -460
  14. data/ext/up_ext/HttpResponseData.h +59 -55
  15. data/ext/up_ext/HttpRouter.h +328 -310
  16. data/ext/up_ext/Loop.h +174 -168
  17. data/ext/up_ext/LoopData.h +60 -67
  18. data/ext/up_ext/MoveOnlyFunction.h +71 -80
  19. data/ext/up_ext/PerMessageDeflate.h +218 -198
  20. data/ext/up_ext/ProxyParser.h +100 -99
  21. data/ext/up_ext/QueryParser.h +91 -84
  22. data/ext/up_ext/TopicTree.h +273 -268
  23. data/ext/up_ext/Utilities.h +25 -25
  24. data/ext/up_ext/WebSocket.h +376 -310
  25. data/ext/up_ext/WebSocketContext.h +487 -372
  26. data/ext/up_ext/WebSocketContextData.h +74 -62
  27. data/ext/up_ext/WebSocketData.h +53 -46
  28. data/ext/up_ext/WebSocketExtensions.h +194 -178
  29. data/ext/up_ext/WebSocketHandshake.h +115 -110
  30. data/ext/up_ext/WebSocketProtocol.h +441 -398
  31. data/ext/up_ext/extconf.rb +1 -1
  32. data/ext/up_ext/libuwebsockets.cpp +1262 -1292
  33. data/ext/up_ext/libuwebsockets.h +337 -201
  34. data/ext/up_ext/up_ext.c +853 -163
  35. data/lib/up/bun/rack_env.rb +1 -13
  36. data/lib/up/bun/server.rb +93 -19
  37. data/lib/up/cli.rb +3 -0
  38. data/lib/up/client.rb +68 -0
  39. data/lib/up/ruby/cluster.rb +62 -0
  40. data/lib/up/ruby/rack_cluster.rb +1 -1
  41. data/lib/up/ruby/rack_server.rb +0 -1
  42. data/lib/up/u_web_socket/cluster.rb +18 -3
  43. data/lib/up/u_web_socket/server.rb +108 -15
  44. data/lib/up/version.rb +1 -1
  45. metadata +4 -15
  46. data/bin/up_node +0 -12
  47. data/bin/up_node_cluster +0 -12
  48. data/lib/up/node/cluster.rb +0 -39
  49. data/lib/up/node/cluster_cli.rb +0 -15
  50. data/lib/up/node/rack_cluster.rb +0 -25
  51. data/lib/up/node/rack_env.rb +0 -106
  52. data/lib/up/node/rack_server.rb +0 -25
  53. data/lib/up/node/server.rb +0 -84
  54. data/lib/up/node/server_cli.rb +0 -15
  55. data/lib/up/ruby/rack_env.rb +0 -97
  56. data/lib/up/u_web_socket/rack_env.rb +0 -101
@@ -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