polyphony 0.43 → 0.43.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/docs/_sass/custom/custom.scss +10 -0
- data/docs/favicon.ico +0 -0
- data/docs/index.md +5 -1
- data/docs/polyphony-logo.png +0 -0
- data/ext/polyphony/polyphony.c +0 -6
- data/ext/polyphony/polyphony_ext.c +0 -2
- data/ext/polyphony/thread.c +0 -6
- data/lib/polyphony/extensions/socket.rb +2 -2
- data/lib/polyphony/version.rb +1 -1
- metadata +4 -3
- data/ext/polyphony/socket.c +0 -213
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bb75fb77b087726e1ff77ed4f82331e9855467965e55bda8e64a6bc93a922b9
|
4
|
+
data.tar.gz: 7167af95b9a02463c81478d5f485c8dd33a14ce579b437580307554f1ad9b23e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6df70953e104c7742248532b2cb1eaa2a0e96867a0480614e5b4966381b53b0d19236a26f8eb3986fa4e59b10e1bd32ec2517d684d17dc820ef6f558b91e624c
|
7
|
+
data.tar.gz: 06e123256b1c1d66ecc4c02109341436b2c802f41358ce8531b89e64792c156435995c6fa2516b002921cf1db4679beb3a92449cc9ac5613e26d60642772cb56
|
data/Gemfile.lock
CHANGED
data/docs/favicon.ico
ADDED
Binary file
|
data/docs/index.md
CHANGED
@@ -6,7 +6,11 @@ permalink: /
|
|
6
6
|
next_title: Installing Polyphony
|
7
7
|
---
|
8
8
|
|
9
|
-
# Polyphony
|
9
|
+
# Polyphony
|
10
|
+
{:.text-center .logo-title}
|
11
|
+
|
12
|
+
## Fine-grained concurrency for Ruby
|
13
|
+
{:.text-center .logo-title}
|
10
14
|
|
11
15
|
Polyphony is a library for building concurrent applications in Ruby. Polyphony
|
12
16
|
implements a comprehensive
|
Binary file
|
data/ext/polyphony/polyphony.c
CHANGED
@@ -7,11 +7,8 @@ ID ID_call;
|
|
7
7
|
ID ID_caller;
|
8
8
|
ID ID_clear;
|
9
9
|
ID ID_each;
|
10
|
-
ID ID_empty;
|
11
10
|
ID ID_inspect;
|
12
11
|
ID ID_new;
|
13
|
-
ID ID_pop;
|
14
|
-
ID ID_push;
|
15
12
|
ID ID_raise;
|
16
13
|
ID ID_ivar_running;
|
17
14
|
ID ID_ivar_thread;
|
@@ -62,13 +59,10 @@ void Init_Polyphony() {
|
|
62
59
|
ID_caller = rb_intern("caller");
|
63
60
|
ID_clear = rb_intern("clear");
|
64
61
|
ID_each = rb_intern("each");
|
65
|
-
ID_empty = rb_intern("empty?");
|
66
62
|
ID_inspect = rb_intern("inspect");
|
67
63
|
ID_ivar_running = rb_intern("@running");
|
68
64
|
ID_ivar_thread = rb_intern("@thread");
|
69
65
|
ID_new = rb_intern("new");
|
70
|
-
ID_pop = rb_intern("pop");
|
71
|
-
ID_push = rb_intern("push");
|
72
66
|
ID_raise = rb_intern("raise");
|
73
67
|
ID_runnable = rb_intern("runnable");
|
74
68
|
ID_runnable_value = rb_intern("runnable_value");
|
@@ -4,7 +4,6 @@ void Init_Fiber();
|
|
4
4
|
void Init_Polyphony();
|
5
5
|
void Init_LibevAgent();
|
6
6
|
void Init_LibevQueue();
|
7
|
-
void Init_Socket();
|
8
7
|
void Init_Thread();
|
9
8
|
void Init_Tracing();
|
10
9
|
|
@@ -16,7 +15,6 @@ void Init_polyphony_ext() {
|
|
16
15
|
Init_LibevQueue();
|
17
16
|
|
18
17
|
Init_Fiber();
|
19
|
-
Init_Socket();
|
20
18
|
Init_Thread();
|
21
19
|
|
22
20
|
Init_Tracing();
|
data/ext/polyphony/thread.c
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
#include "polyphony.h"
|
2
2
|
|
3
3
|
ID ID_deactivate_all_watchers_post_fork;
|
4
|
-
ID ID_empty;
|
5
4
|
ID ID_ivar_agent;
|
6
5
|
ID ID_ivar_join_wait_queue;
|
7
6
|
ID ID_ivar_main_fiber;
|
8
7
|
ID ID_ivar_result;
|
9
8
|
ID ID_ivar_terminated;
|
10
|
-
ID ID_pop;
|
11
|
-
ID ID_push;
|
12
9
|
ID ID_run_queue;
|
13
10
|
ID ID_runnable_next;
|
14
11
|
ID ID_stop;
|
@@ -187,14 +184,11 @@ void Init_Thread() {
|
|
187
184
|
rb_define_method(rb_cThread, "switch_fiber", Thread_switch_fiber, 0);
|
188
185
|
|
189
186
|
ID_deactivate_all_watchers_post_fork = rb_intern("deactivate_all_watchers_post_fork");
|
190
|
-
ID_empty = rb_intern("empty?");
|
191
187
|
ID_ivar_agent = rb_intern("@agent");
|
192
188
|
ID_ivar_join_wait_queue = rb_intern("@join_wait_queue");
|
193
189
|
ID_ivar_main_fiber = rb_intern("@main_fiber");
|
194
190
|
ID_ivar_result = rb_intern("@result");
|
195
191
|
ID_ivar_terminated = rb_intern("@terminated");
|
196
|
-
ID_pop = rb_intern("pop");
|
197
|
-
ID_push = rb_intern("push");
|
198
192
|
ID_run_queue = rb_intern("run_queue");
|
199
193
|
ID_runnable_next = rb_intern("runnable_next");
|
200
194
|
ID_stop = rb_intern("stop");
|
@@ -128,11 +128,11 @@ class ::TCPServer
|
|
128
128
|
|
129
129
|
alias_method :orig_accept, :accept
|
130
130
|
def accept
|
131
|
-
@io
|
131
|
+
@io.accept
|
132
132
|
end
|
133
133
|
|
134
134
|
alias_method :orig_close, :close
|
135
135
|
def close
|
136
|
-
@io
|
136
|
+
@io.close
|
137
137
|
end
|
138
138
|
end
|
data/lib/polyphony/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyphony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.43.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -267,6 +267,7 @@ files:
|
|
267
267
|
- docs/assets/img/echo-fibers.svg
|
268
268
|
- docs/assets/img/sleeping-fiber.svg
|
269
269
|
- docs/faq.md
|
270
|
+
- docs/favicon.ico
|
270
271
|
- docs/getting-started/index.md
|
271
272
|
- docs/getting-started/installing.md
|
272
273
|
- docs/getting-started/overview.md
|
@@ -278,6 +279,7 @@ files:
|
|
278
279
|
- docs/main-concepts/extending.md
|
279
280
|
- docs/main-concepts/fiber-scheduling.md
|
280
281
|
- docs/main-concepts/index.md
|
282
|
+
- docs/polyphony-logo.png
|
281
283
|
- examples/adapters/pg_client.rb
|
282
284
|
- examples/adapters/pg_notify.rb
|
283
285
|
- examples/adapters/pg_pool.rb
|
@@ -386,7 +388,6 @@ files:
|
|
386
388
|
- ext/polyphony/polyphony.c
|
387
389
|
- ext/polyphony/polyphony.h
|
388
390
|
- ext/polyphony/polyphony_ext.c
|
389
|
-
- ext/polyphony/socket.c
|
390
391
|
- ext/polyphony/thread.c
|
391
392
|
- ext/polyphony/tracing.c
|
392
393
|
- lib/polyphony.rb
|
data/ext/polyphony/socket.c
DELETED
@@ -1,213 +0,0 @@
|
|
1
|
-
#include "polyphony.h"
|
2
|
-
#include <sys/socket.h>
|
3
|
-
|
4
|
-
static VALUE cTCPSocket;
|
5
|
-
|
6
|
-
///////////////////////////////////////////////////////////////////////////
|
7
|
-
|
8
|
-
struct rsock_send_arg {
|
9
|
-
int fd, flags;
|
10
|
-
VALUE mesg;
|
11
|
-
struct sockaddr *to;
|
12
|
-
socklen_t tolen;
|
13
|
-
};
|
14
|
-
|
15
|
-
#define StringValue(v) rb_string_value(&(v))
|
16
|
-
#define IS_ADDRINFO(obj) rb_typeddata_is_kind_of((obj), &addrinfo_type)
|
17
|
-
|
18
|
-
VALUE
|
19
|
-
rsock_sockaddr_string_value(volatile VALUE *v)
|
20
|
-
{
|
21
|
-
// VALUE val = *v;
|
22
|
-
// if (IS_ADDRINFO(val)) {
|
23
|
-
// *v = addrinfo_to_sockaddr(val);
|
24
|
-
// }
|
25
|
-
StringValue(*v);
|
26
|
-
return *v;
|
27
|
-
}
|
28
|
-
|
29
|
-
#define SockAddrStringValue(v) rsock_sockaddr_string_value(&(v))
|
30
|
-
#define RSTRING_LENINT(str) rb_long2int(RSTRING_LEN(str))
|
31
|
-
#ifndef RSTRING_SOCKLEN
|
32
|
-
# define RSTRING_SOCKLEN (socklen_t)RSTRING_LENINT
|
33
|
-
#endif
|
34
|
-
|
35
|
-
#if defined __APPLE__
|
36
|
-
# define do_write_retry(code) do {ret = code;} while (ret == -1 && errno == EPROTOTYPE)
|
37
|
-
#else
|
38
|
-
# define do_write_retry(code) ret = code
|
39
|
-
#endif
|
40
|
-
|
41
|
-
VALUE
|
42
|
-
rsock_sendto_blocking(void *data)
|
43
|
-
{
|
44
|
-
struct rsock_send_arg *arg = data;
|
45
|
-
VALUE mesg = arg->mesg;
|
46
|
-
ssize_t ret;
|
47
|
-
do_write_retry(sendto(arg->fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg),
|
48
|
-
arg->flags, arg->to, arg->tolen));
|
49
|
-
return (VALUE)ret;
|
50
|
-
}
|
51
|
-
|
52
|
-
VALUE
|
53
|
-
rsock_send_blocking(void *data)
|
54
|
-
{
|
55
|
-
struct rsock_send_arg *arg = data;
|
56
|
-
VALUE mesg = arg->mesg;
|
57
|
-
ssize_t ret;
|
58
|
-
do_write_retry(send(arg->fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg),
|
59
|
-
arg->flags));
|
60
|
-
return (VALUE)ret;
|
61
|
-
}
|
62
|
-
|
63
|
-
///////////////////////////////////////////////////////////////////////////
|
64
|
-
|
65
|
-
static VALUE BasicSocket_send(int argc, VALUE *argv, VALUE sock) {
|
66
|
-
VALUE underlying_socket = rb_iv_get(sock, "@io");
|
67
|
-
if (!NIL_P(underlying_socket)) sock = underlying_socket;
|
68
|
-
struct rsock_send_arg arg;
|
69
|
-
VALUE flags, to;
|
70
|
-
rb_io_t *fptr;
|
71
|
-
ssize_t n;
|
72
|
-
rb_blocking_function_t *func;
|
73
|
-
const char *funcname;
|
74
|
-
VALUE agent = Qnil;
|
75
|
-
|
76
|
-
rb_scan_args(argc, argv, "21", &arg.mesg, &flags, &to);
|
77
|
-
|
78
|
-
StringValue(arg.mesg);
|
79
|
-
|
80
|
-
if (!NIL_P(to)) {
|
81
|
-
SockAddrStringValue(to);
|
82
|
-
to = rb_str_new4(to);
|
83
|
-
arg.to = (struct sockaddr *)RSTRING_PTR(to);
|
84
|
-
arg.tolen = RSTRING_SOCKLEN(to);
|
85
|
-
func = rsock_sendto_blocking;
|
86
|
-
funcname = "sendto(2)";
|
87
|
-
}
|
88
|
-
else {
|
89
|
-
func = rsock_send_blocking;
|
90
|
-
funcname = "send(2)";
|
91
|
-
}
|
92
|
-
GetOpenFile(sock, fptr);
|
93
|
-
rb_io_set_nonblock(fptr);
|
94
|
-
arg.fd = fptr->fd;
|
95
|
-
arg.flags = NUM2INT(flags);
|
96
|
-
while ((n = (ssize_t)func(&arg)) < 0) {
|
97
|
-
if (NIL_P(agent))
|
98
|
-
agent = rb_ivar_get(rb_thread_current(), ID_ivar_agent);
|
99
|
-
LibevAgent_wait_io(agent, sock, Qtrue);
|
100
|
-
}
|
101
|
-
return SSIZET2NUM(n);
|
102
|
-
}
|
103
|
-
|
104
|
-
static VALUE BasicSocket_recv(int argc, VALUE *argv, VALUE sock) {
|
105
|
-
VALUE underlying_socket = rb_iv_get(sock, "@io");
|
106
|
-
if (!NIL_P(underlying_socket)) sock = underlying_socket;
|
107
|
-
long len = argc >= 1 ? NUM2LONG(argv[0]) : 8192;
|
108
|
-
if (len < 0) {
|
109
|
-
rb_raise(rb_eArgError, "negative length %ld given", len);
|
110
|
-
}
|
111
|
-
|
112
|
-
rb_io_t *fptr;
|
113
|
-
long n;
|
114
|
-
int shrinkable;
|
115
|
-
VALUE agent = Qnil;
|
116
|
-
|
117
|
-
|
118
|
-
VALUE str = argc >= 3 ? argv[2] : Qnil;
|
119
|
-
|
120
|
-
shrinkable = io_setstrbuf(&str, len);
|
121
|
-
OBJ_TAINT(str);
|
122
|
-
GetOpenFile(sock, fptr);
|
123
|
-
// rb_io_set_nonblock(fptr);
|
124
|
-
rb_io_check_byte_readable(fptr);
|
125
|
-
|
126
|
-
if (len == 0)
|
127
|
-
return str;
|
128
|
-
|
129
|
-
while (1) {
|
130
|
-
n = recv(fptr->fd, RSTRING_PTR(str), len, MSG_DONTWAIT);
|
131
|
-
if (n < 0) {
|
132
|
-
int e = errno;
|
133
|
-
if (e == EWOULDBLOCK || e == EAGAIN) {
|
134
|
-
if (NIL_P(agent))
|
135
|
-
agent = rb_ivar_get(rb_thread_current(), ID_ivar_agent);
|
136
|
-
LibevAgent_wait_io(agent, sock, Qnil);
|
137
|
-
}
|
138
|
-
else
|
139
|
-
rb_syserr_fail(e, strerror(e));
|
140
|
-
// rb_syserr_fail_path(e, fptr->pathv);
|
141
|
-
}
|
142
|
-
else
|
143
|
-
break;
|
144
|
-
}
|
145
|
-
|
146
|
-
io_set_read_length(str, n, shrinkable);
|
147
|
-
io_enc_str(str, fptr);
|
148
|
-
|
149
|
-
if (n == 0)
|
150
|
-
return Qnil;
|
151
|
-
|
152
|
-
return str;
|
153
|
-
}
|
154
|
-
|
155
|
-
static VALUE Socket_accept(VALUE sock) {
|
156
|
-
rb_io_t *fptr;
|
157
|
-
int fd;
|
158
|
-
struct sockaddr addr;
|
159
|
-
socklen_t len = (socklen_t)sizeof addr;
|
160
|
-
VALUE agent = Qnil;
|
161
|
-
|
162
|
-
GetOpenFile(sock, fptr);
|
163
|
-
rb_io_set_nonblock(fptr);
|
164
|
-
|
165
|
-
while (1) {
|
166
|
-
fd = accept(fptr->fd, &addr, &len);
|
167
|
-
|
168
|
-
if (fd < 0) {
|
169
|
-
int e = errno;
|
170
|
-
if (e == EWOULDBLOCK || e == EAGAIN) {
|
171
|
-
if (NIL_P(agent))
|
172
|
-
agent = rb_ivar_get(rb_thread_current(), ID_ivar_agent);
|
173
|
-
LibevAgent_wait_io(agent, sock, Qnil);
|
174
|
-
}
|
175
|
-
else
|
176
|
-
rb_syserr_fail(e, strerror(e));
|
177
|
-
// rb_syserr_fail_path(e, fptr->pathv);
|
178
|
-
}
|
179
|
-
else {
|
180
|
-
VALUE connection = rb_obj_alloc(cTCPSocket);
|
181
|
-
rb_io_t *fp;
|
182
|
-
MakeOpenFile(connection, fp);
|
183
|
-
rb_update_max_fd(fd);
|
184
|
-
fp->fd = fd;
|
185
|
-
fp->mode = FMODE_READWRITE | FMODE_DUPLEX;
|
186
|
-
rb_io_ascii8bit_binmode(connection);
|
187
|
-
rb_io_set_nonblock(fp);
|
188
|
-
rb_io_synchronized(fp);
|
189
|
-
// if (rsock_do_not_reverse_lookup) {
|
190
|
-
// fp->mode |= FMODE_NOREVLOOKUP;
|
191
|
-
// }
|
192
|
-
|
193
|
-
return connection;
|
194
|
-
}
|
195
|
-
}
|
196
|
-
}
|
197
|
-
|
198
|
-
void Init_Socket() {
|
199
|
-
VALUE cBasicSocket;
|
200
|
-
VALUE cSocket;
|
201
|
-
|
202
|
-
rb_require("socket");
|
203
|
-
cBasicSocket = rb_const_get(rb_cObject, rb_intern("BasicSocket"));
|
204
|
-
|
205
|
-
rb_define_method(cBasicSocket, "send", BasicSocket_send, -1);
|
206
|
-
rb_define_method(cBasicSocket, "recv", BasicSocket_recv, -1);
|
207
|
-
|
208
|
-
cSocket = rb_const_get(rb_cObject, rb_intern("Socket"));
|
209
|
-
|
210
|
-
// rb_define_method(cSocket, "accept", Socket_accept, 0);
|
211
|
-
|
212
|
-
cTCPSocket = rb_const_get(rb_cObject, rb_intern("TCPSocket"));
|
213
|
-
}
|