opal-up 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/up_ext/App.h +665 -544
- data/ext/up_ext/AsyncSocket.h +307 -284
- data/ext/up_ext/AsyncSocketData.h +35 -51
- data/ext/up_ext/BloomFilter.h +37 -42
- data/ext/up_ext/ChunkedEncoding.h +174 -175
- data/ext/up_ext/ClientApp.h +20 -23
- data/ext/up_ext/HttpContext.h +476 -381
- data/ext/up_ext/HttpContextData.h +20 -20
- data/ext/up_ext/HttpErrors.h +14 -10
- data/ext/up_ext/HttpParser.h +631 -563
- data/ext/up_ext/HttpResponse.h +526 -460
- data/ext/up_ext/HttpResponseData.h +59 -55
- data/ext/up_ext/HttpRouter.h +328 -310
- data/ext/up_ext/Loop.h +174 -168
- data/ext/up_ext/LoopData.h +60 -67
- data/ext/up_ext/MoveOnlyFunction.h +71 -80
- data/ext/up_ext/PerMessageDeflate.h +218 -198
- data/ext/up_ext/ProxyParser.h +100 -99
- data/ext/up_ext/QueryParser.h +91 -84
- data/ext/up_ext/TopicTree.h +273 -268
- data/ext/up_ext/Utilities.h +25 -25
- data/ext/up_ext/WebSocket.h +376 -310
- data/ext/up_ext/WebSocketContext.h +487 -372
- data/ext/up_ext/WebSocketContextData.h +74 -62
- data/ext/up_ext/WebSocketData.h +53 -46
- data/ext/up_ext/WebSocketExtensions.h +194 -178
- data/ext/up_ext/WebSocketHandshake.h +115 -110
- data/ext/up_ext/WebSocketProtocol.h +441 -398
- data/ext/up_ext/up_ext.c +43 -5
- data/lib/up/ruby/cluster.rb +29 -6
- data/lib/up/version.rb +1 -1
- metadata +2 -2
@@ -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
|
-
|
37
|
-
|
38
|
-
|
36
|
+
std::string message;
|
37
|
+
/*OpCode*/ int opCode;
|
38
|
+
bool compress;
|
39
39
|
};
|
40
40
|
struct TopicTreeBigMessage {
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
data/ext/up_ext/WebSocketData.h
CHANGED
@@ -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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
76
|
+
~WebSocketData() {
|
77
|
+
if (deflationStream) {
|
78
|
+
delete deflationStream;
|
79
|
+
}
|
73
80
|
|
74
|
-
|
75
|
-
|
76
|
-
|
81
|
+
if (inflationStream) {
|
82
|
+
delete inflationStream;
|
83
|
+
}
|
77
84
|
|
78
|
-
|
79
|
-
|
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
|