opal-up 0.0.9 → 0.0.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bb6a2cde4f3f4cc8415d17f9d6c471dd5a991cf8ef3a588c528370b4330683d
4
- data.tar.gz: 697d463336883f4259a27804239642fca35915f7991de7cc92260b6adcda44e1
3
+ metadata.gz: d2ff34f74e1bd316c697965755add74c90000899b4f6c1f28ed260764e1cd39a
4
+ data.tar.gz: 6d770d34e96f0196f7fed27a0f8ceba019bdb9e8d3ec7422b4d1525e85c482c4
5
5
  SHA512:
6
- metadata.gz: '09e5af566f909d626a00e0b865b5bb7d7e717d7488f7111a5cc6b9fd8ad2b53d2c9e9aa651492ff76e6ef5eb61da63f208d719af2a593b458033b1eec3a90a10'
7
- data.tar.gz: f96190488e44fac00d338f639b9167e80ac0a48cd9ee108a75474e99d982834514b94f4a01c8769ef399091c6cab2c6e54381e3e1e524215b2a028a8039abf75
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
- int workers;
130
- int member_id;
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
- int key_len = RSTRING_LEN(key);
220
+ long key_len = RSTRING_LEN(key);
214
221
  char *data_s = RSTRING_PTR(data);
215
- int data_len = RSTRING_LEN(data);
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, int member_idx) {
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
- int i;
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
- // rb_gc_unregister_address(client);
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
- // rb_gc_register_address(client);
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
- .port = config.port + s->member_id, .host = "localhost", .options = 0};
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
- int i;
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);
@@ -12,6 +12,7 @@ module Up
12
12
  @secret = Random.uuid
13
13
  @workers = workers || Etc.nprocessors
14
14
  @members = []
15
+ @localhost_addr = TCPSocket.getaddress('localhost')
15
16
  end
16
17
 
17
18
  def listen
@@ -64,7 +65,7 @@ module Up
64
65
 
65
66
  def members_alive?
66
67
  @workers.times do |i|
67
- TCPSocket.new('localhost', @port + i + 1).close
68
+ TCPSocket.new(@localhost_addr , @port + i + 1).close
68
69
  end
69
70
  true
70
71
  rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL
data/lib/up/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Up
2
- VERSION = '0.0.9'.freeze
2
+ VERSION = '0.0.11'.freeze
3
3
  end
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.9
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-18 00:00:00.000000000 Z
11
+ date: 2024-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger