opal-up 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/ext/up_ext/up_ext.c
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
#include <arpa/inet.h>
|
4
4
|
#include <ruby.h>
|
5
5
|
#include <ruby/encoding.h>
|
6
|
+
#include <signal.h>
|
6
7
|
#include <sys/socket.h>
|
7
8
|
#include <sys/wait.h>
|
8
9
|
#include <unistd.h>
|
@@ -65,6 +66,10 @@ static VALUE SERVER_NAME;
|
|
65
66
|
static VALUE SERVER_PORT;
|
66
67
|
static VALUE SERVER_PROTOCOL;
|
67
68
|
|
69
|
+
// both used when worker of a cluster
|
70
|
+
uws_app_t *cluster_app;
|
71
|
+
struct us_listen_socket_t *cluster_socket;
|
72
|
+
|
68
73
|
#define set_str_val(gl_name, str) \
|
69
74
|
rb_gc_register_address(&gl_name); \
|
70
75
|
(gl_name) = rb_enc_str_new((str), strlen((str)), binary_encoding); \
|
@@ -358,12 +363,23 @@ response_error:
|
|
358
363
|
uws_res_end_without_body(USE_SSL, res, false);
|
359
364
|
}
|
360
365
|
|
366
|
+
static void
|
367
|
+
up_server_cluster_listen_handler(struct us_listen_socket_t *listen_socket,
|
368
|
+
uws_app_listen_config_t config, void *arg) {
|
369
|
+
if (listen_socket) {
|
370
|
+
cluster_socket = listen_socket;
|
371
|
+
fprintf(stderr, "Internal Cluster communication on http://localhost:%d\n",
|
372
|
+
config.port);
|
373
|
+
}
|
374
|
+
}
|
375
|
+
|
361
376
|
static void up_server_listen_handler(struct us_listen_socket_t *listen_socket,
|
362
377
|
uws_app_listen_config_t config,
|
363
|
-
void *
|
364
|
-
if (listen_socket)
|
365
|
-
fprintf(stderr, "Server is
|
378
|
+
void *arg) {
|
379
|
+
if (listen_socket) {
|
380
|
+
fprintf(stderr, "Server is listening on http://%s:%d\n", config.host,
|
366
381
|
config.port);
|
382
|
+
}
|
367
383
|
}
|
368
384
|
|
369
385
|
const rb_data_type_t up_client_t = {.wrap_struct_name = "Up::Client",
|
@@ -721,6 +737,13 @@ upgrade_error:
|
|
721
737
|
fprintf(stderr, "upgrade error");
|
722
738
|
}
|
723
739
|
|
740
|
+
static void up_internal_close_sockets(int signal) {
|
741
|
+
if (cluster_socket)
|
742
|
+
us_listen_socket_close(false, cluster_socket);
|
743
|
+
if (cluster_app)
|
744
|
+
uws_app_close(USE_SSL, cluster_app);
|
745
|
+
}
|
746
|
+
|
724
747
|
static VALUE up_server_listen(VALUE self) {
|
725
748
|
server_s *s = DATA_PTR(self);
|
726
749
|
up_internal_check_arg_types(s->rapp, &s->host, &s->port);
|
@@ -747,8 +770,16 @@ static VALUE up_server_listen(VALUE self) {
|
|
747
770
|
.port = FIX2INT(s->port), .host = RSTRING_PTR(s->host), .options = 0};
|
748
771
|
VALUE rmember_id = rb_ivar_get(self, at_member_id);
|
749
772
|
if (rmember_id != Qnil) {
|
773
|
+
// got a cluster
|
750
774
|
s->member_id = FIX2INT(rmember_id);
|
751
|
-
//
|
775
|
+
// install signal handler
|
776
|
+
cluster_app = s->app;
|
777
|
+
cluster_socket = NULL;
|
778
|
+
struct sigaction upclcl = {.sa_handler = up_internal_close_sockets,
|
779
|
+
.sa_flags = 0};
|
780
|
+
sigemptyset(&upclcl.sa_mask);
|
781
|
+
sigaction(SIGINT, &upclcl, NULL);
|
782
|
+
// open publish ports
|
752
783
|
VALUE rworkers = rb_ivar_get(self, at_workers);
|
753
784
|
s->workers = FIX2INT(rworkers);
|
754
785
|
VALUE rsecret = rb_ivar_get(self, at_secret);
|
@@ -761,7 +792,14 @@ static VALUE up_server_listen(VALUE self) {
|
|
761
792
|
uws_app_listen_config_t config_internal = {
|
762
793
|
.port = config.port + s->member_id, .host = "localhost", .options = 0};
|
763
794
|
uws_app_listen_with_config(false, s->app, config_internal,
|
764
|
-
|
795
|
+
up_server_cluster_listen_handler, NULL);
|
796
|
+
} else {
|
797
|
+
cluster_app = s->app;
|
798
|
+
cluster_socket = NULL;
|
799
|
+
struct sigaction upclcl = {.sa_handler = up_internal_close_sockets,
|
800
|
+
.sa_flags = 0};
|
801
|
+
sigemptyset(&upclcl.sa_mask);
|
802
|
+
sigaction(SIGINT, &upclcl, NULL);
|
765
803
|
}
|
766
804
|
uws_app_any(USE_SSL, s->app, "/*", up_server_request_handler, (void *)s);
|
767
805
|
uws_ws(USE_SSL, s->app, "/*",
|
data/lib/up/ruby/cluster.rb
CHANGED
@@ -21,18 +21,41 @@ module Up
|
|
21
21
|
super
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Process.kill("KILL", member)
|
24
|
+
unless @member_id
|
25
|
+
install_signal_handlers
|
26
|
+
Process.waitall
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
30
|
def stop
|
32
31
|
if Up::CLI::stoppable?
|
33
|
-
|
34
|
-
|
32
|
+
kill_members
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def install_signal_handlers
|
39
|
+
Signal.trap('CHLD') do
|
40
|
+
warn "\nError: a cluster member died!"
|
41
|
+
kill_members
|
42
|
+
end
|
43
|
+
Signal.trap('INT') do
|
44
|
+
warn "\nReceived CTRL-C!"
|
45
|
+
kill_members
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def kill_members
|
50
|
+
Signal.trap('CHLD', 'IGNORE')
|
51
|
+
STDERR.print "Stopping workers: "
|
52
|
+
@members.each do |mid|
|
53
|
+
Process.kill('INT', mid) rescue nil
|
54
|
+
STDERR.print '.'
|
35
55
|
end
|
56
|
+
@members.clear
|
57
|
+
warn "\nCluster stopped."
|
58
|
+
Signal.trap('CHLD', 'DEFAULT')
|
36
59
|
end
|
37
60
|
end
|
38
61
|
end
|
data/lib/up/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logger
|