opal-up 0.0.10 → 0.0.11
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/up_ext.c +21 -13
- data/lib/up/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2ff34f74e1bd316c697965755add74c90000899b4f6c1f28ed260764e1cd39a
|
4
|
+
data.tar.gz: 6d770d34e96f0196f7fed27a0f8ceba019bdb9e8d3ec7422b4d1525e85c482c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2d8f327479eb1f4b32c8d137fcbbf580313a446452f6bc3711478318cacc37724f0778ddf021bd286d1c1639a268f2dcf7d3068fd3d7bf38f8bf7ce06133273
|
7
|
+
data.tar.gz: a5b122ed77934fd1d8a06bf64ff3075b44fa57497302fe5ed6b9734c1a8dfc804540f561c79a50760b488f5052eec7143998dea3c091ac06d54821868e07a90d
|
data/ext/up_ext/up_ext.c
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include "libusockets.h"
|
2
2
|
#include "libuwebsockets.h"
|
3
3
|
#include <arpa/inet.h>
|
4
|
+
#include <netinet/in.h>
|
4
5
|
#include <ruby.h>
|
5
6
|
#include <ruby/encoding.h>
|
6
7
|
#include <signal.h>
|
@@ -13,6 +14,12 @@
|
|
13
14
|
#define MAX_HEADER_KEY_LEN 255
|
14
15
|
#define INTERNAL_PUBLISH_PATH "/__up__cluster__publish__"
|
15
16
|
|
17
|
+
#undef close
|
18
|
+
|
19
|
+
#ifndef MSG_MORE
|
20
|
+
#define MSG_MORE 0
|
21
|
+
#endif
|
22
|
+
|
16
23
|
static VALUE mUp;
|
17
24
|
static VALUE mRuby;
|
18
25
|
static VALUE cServer;
|
@@ -126,8 +133,8 @@ typedef struct server_s {
|
|
126
133
|
VALUE env_template;
|
127
134
|
VALUE body;
|
128
135
|
VALUE env;
|
129
|
-
|
130
|
-
|
136
|
+
long workers;
|
137
|
+
long member_id;
|
131
138
|
char secret[37];
|
132
139
|
} server_s;
|
133
140
|
|
@@ -210,9 +217,9 @@ static int up_internal_res_header_handler(VALUE key, VALUE data, VALUE arg) {
|
|
210
217
|
return ST_CONTINUE;
|
211
218
|
}
|
212
219
|
char *key_s = RSTRING_PTR(key);
|
213
|
-
|
220
|
+
long key_len = RSTRING_LEN(key);
|
214
221
|
char *data_s = RSTRING_PTR(data);
|
215
|
-
|
222
|
+
long data_len = RSTRING_LEN(data);
|
216
223
|
|
217
224
|
if (key_len > MAX_HEADER_KEY_LEN)
|
218
225
|
key_len = MAX_HEADER_KEY_LEN;
|
@@ -479,8 +486,7 @@ static void up_client_cluster_publish(char *scrt, int st, VALUE channel,
|
|
479
486
|
MSG_DONTROUTE | MSG_MORE);
|
480
487
|
send(st, boundary_disposition, strlen(boundary_disposition),
|
481
488
|
MSG_DONTROUTE | MSG_MORE);
|
482
|
-
send(st, RSTRING_PTR(message), RSTRING_LEN(message),
|
483
|
-
MSG_DONTROUTE | MSG_MORE);
|
489
|
+
send(st, RSTRING_PTR(message), RSTRING_LEN(message), MSG_DONTROUTE);
|
484
490
|
|
485
491
|
// char read_buf[256];
|
486
492
|
// if (read(st, read_buf, 256)) {
|
@@ -490,7 +496,7 @@ static void up_client_cluster_publish(char *scrt, int st, VALUE channel,
|
|
490
496
|
}
|
491
497
|
|
492
498
|
static void up_internal_publish_to_member(server_s *s, VALUE channel,
|
493
|
-
VALUE message,
|
499
|
+
VALUE message, long member_idx) {
|
494
500
|
struct sockaddr_in member_addr = {.sin_addr.s_addr = inet_addr("127.0.0.1"),
|
495
501
|
.sin_family = AF_INET};
|
496
502
|
int st = socket(AF_INET, SOCK_STREAM, 0);
|
@@ -521,7 +527,7 @@ static VALUE up_client_publish(VALUE self, VALUE channel, VALUE message) {
|
|
521
527
|
if (s->member_id > 0) {
|
522
528
|
|
523
529
|
// publish to cluster members
|
524
|
-
|
530
|
+
long i;
|
525
531
|
for (i = 1; i <= s->workers; i++) {
|
526
532
|
if (i != s->member_id)
|
527
533
|
up_internal_publish_to_member(s, channel, message, i);
|
@@ -672,7 +678,7 @@ static void up_ws_close_handler(uws_websocket_t *ws, int code,
|
|
672
678
|
VALUE rhandler = rb_ivar_get(*client, at_handler);
|
673
679
|
if (rb_respond_to(rhandler, id_on_close))
|
674
680
|
rb_funcall(rhandler, id_on_close, 1, *client);
|
675
|
-
|
681
|
+
rb_gc_unregister_address(client);
|
676
682
|
DATA_PTR(*client) = NULL;
|
677
683
|
free(client);
|
678
684
|
}
|
@@ -729,7 +735,7 @@ static void up_ws_upgrade_handler(uws_res_t *res, uws_req_t *req,
|
|
729
735
|
// upgrade
|
730
736
|
|
731
737
|
VALUE *client = malloc(sizeof(VALUE));
|
732
|
-
|
738
|
+
rb_gc_register_address(client);
|
733
739
|
*client = rb_class_new_instance(0, NULL, cClient);
|
734
740
|
rb_ivar_set(*client, at_env, renv);
|
735
741
|
rb_ivar_set(*client, at_open, false);
|
@@ -836,8 +842,10 @@ static VALUE up_server_listen(VALUE self) {
|
|
836
842
|
s->secret[36] = '\0';
|
837
843
|
uws_app_any(USE_SSL, s->app, INTERNAL_PUBLISH_PATH,
|
838
844
|
up_internal_publish_handler, (void *)s);
|
839
|
-
uws_app_listen_config_t config_internal = {
|
840
|
-
|
845
|
+
uws_app_listen_config_t config_internal = {.port = config.port +
|
846
|
+
(int)s->member_id,
|
847
|
+
.host = "localhost",
|
848
|
+
.options = 0};
|
841
849
|
uws_app_listen_with_config(false, s->app, config_internal,
|
842
850
|
up_server_cluster_listen_handler, NULL);
|
843
851
|
} else {
|
@@ -885,7 +893,7 @@ static VALUE up_server_publish(VALUE self, VALUE channel, VALUE message) {
|
|
885
893
|
RSTRING_PTR(message), RSTRING_LEN(message), TEXT, false);
|
886
894
|
if (s->member_id > 0) {
|
887
895
|
// publish to cluster members
|
888
|
-
|
896
|
+
long i;
|
889
897
|
for (i = 1; i <= s->workers; i++) {
|
890
898
|
if (i != s->member_id)
|
891
899
|
up_internal_publish_to_member(s, channel, message, i);
|
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.11
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logger
|