surro-gate 1.0.0 → 1.0.1

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
- SHA256:
3
- metadata.gz: 542c462ea407735d332f61fd2a665ec27c151069c9b670da220592b30c4895bc
4
- data.tar.gz: 17cf01b8d553093d77afb8409b995d06ff0351893431d35cf92afa079ae87247
2
+ SHA1:
3
+ metadata.gz: 90e1123d3d92d4d2aa63a242e70b1cb892841f55
4
+ data.tar.gz: f49f4c35d280a89d1baf88b1bcca0ad4289d3320
5
5
  SHA512:
6
- metadata.gz: 06d2cbf0cfab641f3006ab85c7baf48977b2b2bb05514b92cce2e990b35e31b34054b0b985cb9cc746f235bc764946e1c2d958c713a41e68a5c967508ece795b
7
- data.tar.gz: a613ef079f5d878d5785139f2b215561252160f5f2bc1097ce13dce0eca47f063ac06a52d1e335df62bb1e08ec1eb117f56ef74ec93b858d5cb4ae6e6a4143ba
6
+ metadata.gz: 69ab774b8c3c9de0839cfaf00d63b0ba73e614ba058cee91f0bb6460726f32f2fc92261b3e3591b8662f3ae3735221eeca2adffca246a37e937c9850afd6003a
7
+ data.tar.gz: 6d4009bcaa479bd414a0dcf039e3a32d11f2a913041f560b8fc33c2486ef6f4ef76ffc4c8e25e17ab5b0d576be71e1a12998000273756682b30040886e675098
@@ -22,6 +22,13 @@ void epoll_rearm(int *epoll, int socket, int ltr, int rtl, int events) {
22
22
  epoll_ctl(*epoll, EPOLL_CTL_MOD, socket, &ev);
23
23
  }
24
24
 
25
+ void* wait_func(void *ptr) {
26
+ struct epoll_wait_args *args;
27
+ args = (struct epoll_wait_args*) ptr;
28
+ args->result = epoll_wait(args->epfd, args->events, args->maxevents, args->timeout);
29
+ return NULL;
30
+ }
31
+
25
32
  static VALUE pairing_compare(VALUE pair, VALUE sockets) {
26
33
  int i;
27
34
  VALUE left = rb_iv_get(pair, "@left");
@@ -139,16 +146,24 @@ static VALUE SurroGate_Selector_pop(VALUE self, VALUE sockets) {
139
146
  }
140
147
 
141
148
  static VALUE SurroGate_Selector_select(VALUE self, VALUE timeout) {
142
- int i, count, *selector, source, target;
149
+ int i, *selector, source, target;
143
150
  struct epoll_event events[256];
151
+ struct epoll_wait_args wait_args;
144
152
  VALUE read, write, socket;
145
153
 
146
154
  VALUE pairing = rb_iv_get(self, "@pairing");
147
155
  Data_Get_Struct(self, int, selector);
148
156
 
149
- count = epoll_wait(*selector, events, 256, NUM2INT(timeout));
157
+ // The code after the comments has the same result as the code below, but with GVL
158
+ // args.result = epoll_wait(*selector, events, 256, NUM2INT(timeout));
159
+ wait_args.epfd = *selector;
160
+ wait_args.events = events;
161
+ wait_args.maxevents = 256;
162
+ wait_args.timeout = NUM2INT(timeout);
163
+ wait_args.result = 0;
164
+ rb_thread_call_without_gvl(wait_func, &wait_args, NULL, NULL);
150
165
 
151
- for (i=0; i<count; i++) {
166
+ for (i=0; i<wait_args.result; i++) {
152
167
  source = (int)((events[i].data.u64 & 0xFFFFFFFF00000000LL) >> 32);
153
168
  target = (int)(events[i].data.u64 & 0xFFFFFFFFLL);
154
169
 
@@ -176,7 +191,7 @@ static VALUE SurroGate_Selector_select(VALUE self, VALUE timeout) {
176
191
  }
177
192
  }
178
193
 
179
- return INT2NUM(count);
194
+ return INT2NUM(wait_args.result);
180
195
  }
181
196
 
182
197
  static VALUE SurroGate_Selector_each_ready(VALUE self) {
@@ -3,12 +3,22 @@
3
3
 
4
4
  #include "ruby.h"
5
5
  #include "ruby/io.h"
6
+ #include "ruby/thread.h"
6
7
  #include "stdlib.h"
7
8
  #include "sys/epoll.h"
8
9
 
9
10
  #define SOCK_PTR(X) RFILE(X)->fptr->fd
10
11
  #define IVAR_TRUE(X, Y) rb_iv_get(X, Y) == Qtrue
11
12
 
13
+ struct epoll_wait_args {
14
+ unsigned int epfd;
15
+ struct epoll_event *events;
16
+ int maxevents;
17
+ int timeout;
18
+
19
+ int result;
20
+ };
21
+
12
22
  static VALUE SurroGate_Selector_allocate(VALUE self);
13
23
  static VALUE SurroGate_Selector_initialize(VALUE self, VALUE logger);
14
24
  static VALUE SurroGate_Selector_push(VALUE self, VALUE left, VALUE right);
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SurroGate
4
- VERSION = '1.0.0'.freeze
4
+ VERSION = '1.0.1'.freeze
5
5
  HAVE_EXT = RUBY_PLATFORM =~ /linux/ && !defined?(JRUBY_VERSION) && !ENV['SURRO_GATE_NOEXT']
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surro-gate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dávid Halász
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-29 00:00:00.000000000 Z
11
+ date: 2018-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.7.7
132
+ rubygems_version: 2.6.14.1
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: A generic purrpose TCP-to-TCP proxy in Ruby