polyphony 0.47.4 → 0.47.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f32962c9f1004bc9c63afcaddaad91dc8878da5e8290b8e9d42d591433311c0b
4
- data.tar.gz: 3b43ad185ccb0778d88d9c8ac1043bbff291ac0a55d5bee80da8b6e08a1f6493
3
+ metadata.gz: 4343a37f26793e76528ea8e87287e2f3fbc4c8182064e820eedfc131d4308729
4
+ data.tar.gz: 89273660342f647e3e016290ef48ac10f33b040a3ca6538b1fdd29aab13519da
5
5
  SHA512:
6
- metadata.gz: b4ba80ea441862f22398e624996144e9ed7f8297b56e2f14035c537671282f4338b3843ff192959a7031134e761d273c5050043b08b5051c1653ecc3f986cddb
7
- data.tar.gz: '04850a036f5278d221b6610259e70fbb7e44e8afd04237d9a6906fa826a836c786734123894a0b7197c5c98502a9b5304896b09a1e7b6d16433e363dbd1803e6'
6
+ metadata.gz: 7aa6b9f5e9ea61b682a112b30286b1e66f71088da67f96827d6415a6be12de4874de79ccd2236f36ba4da1bf5e9c078735bd07ac32520268c12cadfe60cd8565
7
+ data.tar.gz: e564dfed776907921bdceafcdb47e78fe5655d345812f3484d7493df74f3485d09bf32e756c766cc45efe45591524c6a24d55c19530fa14ededbb4f481e80977
@@ -1,497 +1,502 @@
1
+ ## 0.47.5
2
+
3
+ - Add `socket_class` argument to `Backend#accept`, `Backend#accept_loop`
4
+ - Fix `#supervise` to stop when all children fibers are done
5
+
1
6
  ## 0.47.4
2
7
 
3
- * Add support for Unix sockets
8
+ - Add support for Unix sockets
4
9
 
5
10
  ## 0.47.3
6
11
 
7
- * Enable I/O in signal handlers (#45)
8
- * Accept `:interval` argument in `#spin_loop`
12
+ - Enable I/O in signal handlers (#45)
13
+ - Accept `:interval` argument in `#spin_loop`
9
14
 
10
15
  ## 0.47.2
11
16
 
12
- * Fix API compatibility between TCPSocket and IO
17
+ - Fix API compatibility between TCPSocket and IO
13
18
 
14
19
  ## 0.47.0
15
20
 
16
- * Implement `#spin_scope` used for creating blocking fiber scopes
17
- * Reimplement `move_on_after`, `cancel_after`, `Timeout.timeout` using
21
+ - Implement `#spin_scope` used for creating blocking fiber scopes
22
+ - Reimplement `move_on_after`, `cancel_after`, `Timeout.timeout` using
18
23
  `Backend#timeout` (avoids creating canceller fiber for most common use case)
19
- * Implement `Backend#timeout` API
20
- * Implemented capped queues
24
+ - Implement `Backend#timeout` API
25
+ - Implemented capped queues
21
26
 
22
27
  ## 0.46.1
23
28
 
24
- * Add `TCPServer#accept_loop`, `OpenSSL::SSL::SSLSocket#accept_loop` method
25
- * Fix compilation error on MacOS (#43)
26
- * Fix backtrace for `Timeout.timeout`
27
- * Add `Backend#timer_loop`
29
+ - Add `TCPServer#accept_loop`, `OpenSSL::SSL::SSLSocket#accept_loop` method
30
+ - Fix compilation error on MacOS (#43)
31
+ - Fix backtrace for `Timeout.timeout`
32
+ - Add `Backend#timer_loop`
28
33
 
29
34
  ## 0.46.0
30
35
 
31
- * Implement [io_uring backend](https://github.com/digital-fabric/polyphony/pull/44)
36
+ - Implement [io_uring backend](https://github.com/digital-fabric/polyphony/pull/44)
32
37
 
33
38
  ## 0.45.5
34
39
 
35
- * Fix compilation error (#43)
36
- * Add support for resetting move_on_after, cancel_after timeouts
37
- * Optimize anti-event starvation polling
38
- * Implement optimized runqueue for better performance
39
- * Schedule parent with priority on uncaught exception
40
- * Fix race condition in `Mutex#synchronize` (#41)
40
+ - Fix compilation error (#43)
41
+ - Add support for resetting move_on_after, cancel_after timeouts
42
+ - Optimize anti-event starvation polling
43
+ - Implement optimized runqueue for better performance
44
+ - Schedule parent with priority on uncaught exception
45
+ - Fix race condition in `Mutex#synchronize` (#41)
41
46
 
42
47
  ## 0.45.4
43
48
 
44
- * Improve signal trapping mechanism
49
+ - Improve signal trapping mechanism
45
50
 
46
51
  ## 0.45.3
47
52
 
48
- * Don't swallow error in `Process#kill_and_await`
49
- * Add `Fiber#mailbox` attribute reader
50
- * Fix bug in `Fiber.await`
51
- * Implement `IO#getc`, `IO#getbyte`
53
+ - Don't swallow error in `Process#kill_and_await`
54
+ - Add `Fiber#mailbox` attribute reader
55
+ - Fix bug in `Fiber.await`
56
+ - Implement `IO#getc`, `IO#getbyte`
52
57
 
53
58
  ## 0.45.2
54
59
 
55
- * Rewrite `Fiber#<<`, `Fiber#await`, `Fiber#receive` in C
60
+ - Rewrite `Fiber#<<`, `Fiber#await`, `Fiber#receive` in C
56
61
 
57
62
  ## 0.45.1
58
63
 
59
- * Fix Net::HTTP compatibility
60
- * Fix fs adapter
61
- * Improve performance of IO#puts
62
- * Mutex#synchronize
63
- * Fix Socket#connect
64
- * Cleanup code
65
- * Improve support for Ruby 3 keyword args
64
+ - Fix Net::HTTP compatibility
65
+ - Fix fs adapter
66
+ - Improve performance of IO#puts
67
+ - Mutex#synchronize
68
+ - Fix Socket#connect
69
+ - Cleanup code
70
+ - Improve support for Ruby 3 keyword args
66
71
 
67
72
  ## 0.45.0
68
73
 
69
- * Cleanup code
70
- * Rename `Agent` to `Backend`
71
- * Implement `Polyphony::ConditionVariable`
72
- * Fix Kernel.system
74
+ - Cleanup code
75
+ - Rename `Agent` to `Backend`
76
+ - Implement `Polyphony::ConditionVariable`
77
+ - Fix Kernel.system
73
78
 
74
79
  ## 0.44.0 2020-07-25
75
80
 
76
- * Fix reentrant `ResourcePool` (#38)
77
- * Add `ResourcePool#discard!` (#35)
78
- * Add `Mysql2::Client` and `Sequel::ConnectionPool` adapters (#35)
79
- * Reimplement `Kernel.trap` using `Fiber#interject`
80
- * Add `Fiber#interject` for running arbitrary code on arbitrary fibers (#39)
81
+ - Fix reentrant `ResourcePool` (#38)
82
+ - Add `ResourcePool#discard!` (#35)
83
+ - Add `Mysql2::Client` and `Sequel::ConnectionPool` adapters (#35)
84
+ - Reimplement `Kernel.trap` using `Fiber#interject`
85
+ - Add `Fiber#interject` for running arbitrary code on arbitrary fibers (#39)
81
86
 
82
87
  ## 0.43.11 2020-07-24
83
88
 
84
- * Dump uncaught exception info for forked process (#36)
85
- * Add additional socket config options (#37)
89
+ - Dump uncaught exception info for forked process (#36)
90
+ - Add additional socket config options (#37)
86
91
  - :reuse_port (`SO_REUSEPORT`)
87
92
  - :backlog (listen backlog, default `SOMAXCONN`)
88
- * Fix possible race condition in Queue#shift (#34)
93
+ - Fix possible race condition in Queue#shift (#34)
89
94
 
90
95
  ## 0.43.10 2020-07-23
91
96
 
92
- * Fix race condition when terminating fibers (#33)
93
- * Fix lock release in `Mutex` (#32)
94
- * Virtualize agent interface
95
- * Implement `LibevAgent_connect`
97
+ - Fix race condition when terminating fibers (#33)
98
+ - Fix lock release in `Mutex` (#32)
99
+ - Virtualize agent interface
100
+ - Implement `LibevAgent_connect`
96
101
 
97
102
  ## 0.43.9 2020-07-22
98
103
 
99
- * Rewrite `Channel` using `Queue`
100
- * Rewrite `Mutex` using `Queue`
101
- * Reimplement `Event` in C to prevent cross-thread race condition
102
- * Reimplement `ResourcePool` using `Queue`
103
- * Implement `Queue#size`
104
+ - Rewrite `Channel` using `Queue`
105
+ - Rewrite `Mutex` using `Queue`
106
+ - Reimplement `Event` in C to prevent cross-thread race condition
107
+ - Reimplement `ResourcePool` using `Queue`
108
+ - Implement `Queue#size`
104
109
 
105
110
  ## 0.43.8 2020-07-21
106
111
 
107
- * Rename `LibevQueue` to `Queue`
108
- * Reimplement Event using `Agent#wait_event`
109
- * Improve Queue shift queue performance
110
- * Introduce `Agent#wait_event` API for waiting on asynchronous events
111
- * Minimize `fcntl` syscalls in IO operations
112
+ - Rename `LibevQueue` to `Queue`
113
+ - Reimplement Event using `Agent#wait_event`
114
+ - Improve Queue shift queue performance
115
+ - Introduce `Agent#wait_event` API for waiting on asynchronous events
116
+ - Minimize `fcntl` syscalls in IO operations
112
117
 
113
118
  ## 0.43.7 2020-07-20
114
119
 
115
- * Fix memory leak in ResourcePool (#31)
116
- * Check and adjust file position before reading (#30)
117
- * Minor documentation fixes
120
+ - Fix memory leak in ResourcePool (#31)
121
+ - Check and adjust file position before reading (#30)
122
+ - Minor documentation fixes
118
123
 
119
124
  ## 0.43.6 2020-07-18
120
125
 
121
- * Allow brute-force interrupting with second Ctrl-C
122
- * Fix outgoing SSL connections (#28)
123
- * Improve Fiber#await_all_children with many children
124
- * Use `writev` for writing multiple strings
125
- * Add logo (thanks [Gerald](https://webocube.com/)!)
126
+ - Allow brute-force interrupting with second Ctrl-C
127
+ - Fix outgoing SSL connections (#28)
128
+ - Improve Fiber#await_all_children with many children
129
+ - Use `writev` for writing multiple strings
130
+ - Add logo (thanks [Gerald](https://webocube.com/)!)
126
131
 
127
132
  ## 0.43.5 2020-07-13
128
133
 
129
- * Fix `#read_nonblock`, `#write_nonblock` for `IO` and `Socket` (#27)
130
- * Patch `Kernel#p`, `IO#puts` to issue single write call
131
- * Add support for multiple arguments in `IO#write` and `LibevAgent#write`
132
- * Use LibevQueue for fiber run queue
133
- * Reimplement LibevQueue as ring buffer
134
+ - Fix `#read_nonblock`, `#write_nonblock` for `IO` and `Socket` (#27)
135
+ - Patch `Kernel#p`, `IO#puts` to issue single write call
136
+ - Add support for multiple arguments in `IO#write` and `LibevAgent#write`
137
+ - Use LibevQueue for fiber run queue
138
+ - Reimplement LibevQueue as ring buffer
134
139
 
135
140
  ## 0.43.4 2020-07-09
136
141
 
137
- * Reimplement Kernel#trap
138
- * Dynamically allocate read buffer if length not given (#23)
139
- * Prevent CPU saturation on infinite sleep (#24)
142
+ - Reimplement Kernel#trap
143
+ - Dynamically allocate read buffer if length not given (#23)
144
+ - Prevent CPU saturation on infinite sleep (#24)
140
145
 
141
146
  ## 0.43.3 2020-07-08
142
147
 
143
- * Fix behaviour after call to `Process.daemon` (#8)
144
- * Replace core `Queue` class with `Polyphony::Queue` (#22)
145
- * Make `ResourcePool` reentrant (#1)
146
- * Accept `:with_exception` argument in `cancel_after` (#16)
148
+ - Fix behaviour after call to `Process.daemon` (#8)
149
+ - Replace core `Queue` class with `Polyphony::Queue` (#22)
150
+ - Make `ResourcePool` reentrant (#1)
151
+ - Accept `:with_exception` argument in `cancel_after` (#16)
147
152
 
148
153
  ## 0.43.2 2020-07-07
149
154
 
150
- * Fix sending Redis commands with array arguments (#21)
155
+ - Fix sending Redis commands with array arguments (#21)
151
156
 
152
157
  ## 0.43.1 2020-06
153
158
 
154
- * Fix compiling C-extension on MacOS (#20)
159
+ - Fix compiling C-extension on MacOS (#20)
155
160
 
156
161
  ## 0.43 2020-07-05
157
162
 
158
- * Add IO#read_loop
159
- * Fix OpenSSL extension
160
- * More work on docs
163
+ - Add IO#read_loop
164
+ - Fix OpenSSL extension
165
+ - More work on docs
161
166
 
162
167
  ## 0.42 2020-07-03
163
168
 
164
- * Improve documentation
165
- * Fix backtrace on SIGINT
166
- * Implement LibevAgent#accept_loop, #read_loop
167
- * Move ref counting from thread to agent
168
- * Short circuit switchpoint if continuing with the same fiber
169
- * Always do a switchpoint in #read, #write, #accept
169
+ - Improve documentation
170
+ - Fix backtrace on SIGINT
171
+ - Implement LibevAgent#accept_loop, #read_loop
172
+ - Move ref counting from thread to agent
173
+ - Short circuit switchpoint if continuing with the same fiber
174
+ - Always do a switchpoint in #read, #write, #accept
170
175
 
171
176
  ## 0.41 2020-06-27
172
177
 
173
- * Introduce System Agent design, remove all `Gyro` classes
178
+ - Introduce System Agent design, remove all `Gyro` classes
174
179
 
175
180
  ## 0.40 2020-05-04
176
181
 
177
- * More improvements to stability after fork
182
+ - More improvements to stability after fork
178
183
 
179
184
  ## 0.38 2020-04-13
180
185
 
181
- * Fix post-fork segfault if parent process has multiple threads with active watchers
186
+ - Fix post-fork segfault if parent process has multiple threads with active watchers
182
187
 
183
188
  ## 0.37 2020-04-07
184
189
 
185
- * Explicitly kill threads on exit to prevent possible segfault
186
- * Remove Modulation dependency
190
+ - Explicitly kill threads on exit to prevent possible segfault
191
+ - Remove Modulation dependency
187
192
 
188
193
  ## 0.36 2020-03-31
189
194
 
190
- * More docs
191
- * More C code refactoring
192
- * Fix freeing for active child, signal watchers
195
+ - More docs
196
+ - More C code refactoring
197
+ - Fix freeing for active child, signal watchers
193
198
 
194
199
  ## 0.35 2020-03-29
195
200
 
196
- * Rename `Fiber#cancel!` to `Fiber#cancel`
197
- * Rename `Gyro::Async#signal!` to `Gyro::Async#signal`
198
- * Use `Fiber#auto_watcher` in thread pool, thread extension
199
- * Implement `Fiber#auto_io` for reusing IO watcher instances
200
- * Refactor C code
201
+ - Rename `Fiber#cancel!` to `Fiber#cancel`
202
+ - Rename `Gyro::Async#signal!` to `Gyro::Async#signal`
203
+ - Use `Fiber#auto_watcher` in thread pool, thread extension
204
+ - Implement `Fiber#auto_io` for reusing IO watcher instances
205
+ - Refactor C code
201
206
 
202
207
  ## 0.34 2020-03-25
203
208
 
204
- * Add `Fiber#auto_watcher` mainly for use in places like `Gyro::Queue#shift`
205
- * Refactor C extension
206
- * Improved GC'ing for watchers
207
- * Implement process supervisor (`Polyphony::ProcessSupervisor`)
208
- * Improve fiber supervision
209
- * Fix forking behaviour
210
- * Use correct backtrace for fiber control exceptions
211
- * Allow calling `move_on_after` and `cancel_after` without block
209
+ - Add `Fiber#auto_watcher` mainly for use in places like `Gyro::Queue#shift`
210
+ - Refactor C extension
211
+ - Improved GC'ing for watchers
212
+ - Implement process supervisor (`Polyphony::ProcessSupervisor`)
213
+ - Improve fiber supervision
214
+ - Fix forking behaviour
215
+ - Use correct backtrace for fiber control exceptions
216
+ - Allow calling `move_on_after` and `cancel_after` without block
212
217
 
213
218
  ## 0.33 2020-03-08
214
219
 
215
- * Implement `Fiber#supervise` (WIP)
216
- * Add `Fiber#restart` API
217
- * Fix race condition in `Thread#join`, `Thread#raise` (#14)
218
- * Add `Exception#source_fiber` - references the fiber in which an uncaught
220
+ - Implement `Fiber#supervise` (WIP)
221
+ - Add `Fiber#restart` API
222
+ - Fix race condition in `Thread#join`, `Thread#raise` (#14)
223
+ - Add `Exception#source_fiber` - references the fiber in which an uncaught
219
224
  exception occurred
220
225
 
221
226
  ## 0.32 2020-02-29
222
227
 
223
- * Accept optional throttling rate in `#spin_loop`
224
- * Remove CancelScope
225
- * Allow spinning fibers from a parent fiber other than the current
226
- * Add `#receive_pending` global API.
227
- * Prevent race condition in `Gyro::Queue`.
228
- * Improve signal handling - `INT`, `TERM` signals are now always handled in the
228
+ - Accept optional throttling rate in `#spin_loop`
229
+ - Remove CancelScope
230
+ - Allow spinning fibers from a parent fiber other than the current
231
+ - Add `#receive_pending` global API.
232
+ - Prevent race condition in `Gyro::Queue`.
233
+ - Improve signal handling - `INT`, `TERM` signals are now always handled in the
229
234
  main fiber
230
- * Fix adapter requires (redis and postgres)
235
+ - Fix adapter requires (redis and postgres)
231
236
 
232
237
  ## 0.31 2020-02-20
233
238
 
234
- * Fix signal handling race condition (#13)
235
- * Move adapter code into polyphony/adapters
236
- * Fix spin_loop caller, add tag parameter
239
+ - Fix signal handling race condition (#13)
240
+ - Move adapter code into polyphony/adapters
241
+ - Fix spin_loop caller, add tag parameter
237
242
 
238
243
  ## 0.30 2020-02-04
239
244
 
240
- * Add support for awaiting a fiber from multiple monitor fibers at once
241
- * Implemented child fibers
242
- * Fix TERM and INT signal handling (#11)
243
- * Fix compiling on Linux
244
- * Do not reset runnable value in Gyro_suspend (prevents interrupting timers)
245
- * Don't snooze when stopping a fiber
246
- * Fix IO#read for files larger than 8KB (#10)
247
- * Fix fiber messaging in main fiber
248
- * Prevent signalling of inactive async watcher
249
- * Better fiber messaging
245
+ - Add support for awaiting a fiber from multiple monitor fibers at once
246
+ - Implemented child fibers
247
+ - Fix TERM and INT signal handling (#11)
248
+ - Fix compiling on Linux
249
+ - Do not reset runnable value in Gyro_suspend (prevents interrupting timers)
250
+ - Don't snooze when stopping a fiber
251
+ - Fix IO#read for files larger than 8KB (#10)
252
+ - Fix fiber messaging in main fiber
253
+ - Prevent signalling of inactive async watcher
254
+ - Better fiber messaging
250
255
 
251
256
  ## 0.29 2020-02-02
252
257
 
253
- * Pass SignalException to main fiber
254
- * Add (restore) default thread pool
255
- * Prevent race condition in Thread#join
256
- * Add support for cross-thread fiber scheduling
257
- * Remove `#defer` global method
258
- * Prevent starvation of waiting fibers when using snooze (#7)
259
- * Improve tracing
260
- * Fix IRB adapter
258
+ - Pass SignalException to main fiber
259
+ - Add (restore) default thread pool
260
+ - Prevent race condition in Thread#join
261
+ - Add support for cross-thread fiber scheduling
262
+ - Remove `#defer` global method
263
+ - Prevent starvation of waiting fibers when using snooze (#7)
264
+ - Improve tracing
265
+ - Fix IRB adapter
261
266
 
262
267
  ## 0.28 2020-01-27
263
268
 
264
- * Accept block in Supervisor#initialize
265
- * Refactor `ThreadPool`
266
- * Implement fiber switch events for `TracePoint`
267
- * Add optional tag parameter to #spin
268
- * Correctly increment ref count for indefinite sleep
269
- * Add `irb` adapter
270
- * Add support for listen/notify to postgres adapter
271
- * Use `:waiting`, `:runnable`, `:running`, `:dead` for fiber states
272
- * Move docs to https://digital-fabric.github.io/polyphony/
269
+ - Accept block in Supervisor#initialize
270
+ - Refactor `ThreadPool`
271
+ - Implement fiber switch events for `TracePoint`
272
+ - Add optional tag parameter to #spin
273
+ - Correctly increment ref count for indefinite sleep
274
+ - Add `irb` adapter
275
+ - Add support for listen/notify to postgres adapter
276
+ - Use `:waiting`, `:runnable`, `:running`, `:dead` for fiber states
277
+ - Move docs to https://digital-fabric.github.io/polyphony/
273
278
 
274
279
  ## 0.27 2020-01-19
275
280
 
276
- * Reimplement `Throttler` using recurring timer
277
- * Add `Gyro::Selector` for wrapping libev
278
- * Add `Gyro::Queue`, a fiber-aware thread-safe queue
279
- * Implement multithreaded fiber scheduling
281
+ - Reimplement `Throttler` using recurring timer
282
+ - Add `Gyro::Selector` for wrapping libev
283
+ - Add `Gyro::Queue`, a fiber-aware thread-safe queue
284
+ - Implement multithreaded fiber scheduling
280
285
 
281
286
  ## 0.26 2020-01-12
282
287
 
283
- * Optimize `IO#read_watcher`, `IO#write_watcher`
284
- * Implement `Fiber#raise`
285
- * Fix `Kernel#gets` with `ARGV`
286
- * Return `[pid, exit_status]` from `Gyro::Child#await`
288
+ - Optimize `IO#read_watcher`, `IO#write_watcher`
289
+ - Implement `Fiber#raise`
290
+ - Fix `Kernel#gets` with `ARGV`
291
+ - Return `[pid, exit_status]` from `Gyro::Child#await`
287
292
 
288
293
  ## 0.25 2020-01-10
289
294
 
290
- * Fold `Coprocess` functionality into `Fiber`
291
- * Add support for indefinite `#sleep`
295
+ - Fold `Coprocess` functionality into `Fiber`
296
+ - Add support for indefinite `#sleep`
292
297
 
293
298
  ## 0.24 2020-01-08
294
299
 
295
- * Extract HTTP code into separate polyphony-http gem
296
- * Cull core, io examples
297
- * Remove `SIGINT` handler
300
+ - Extract HTTP code into separate polyphony-http gem
301
+ - Cull core, io examples
302
+ - Remove `SIGINT` handler
298
303
 
299
304
  ## 0.23 2020-01-07
300
305
 
301
- * Remove `API#pulse`
302
- * Better repeat timer, reimplement `API#every`
303
- * Move global API methods to separate module, include in `Object` instead of
306
+ - Remove `API#pulse`
307
+ - Better repeat timer, reimplement `API#every`
308
+ - Move global API methods to separate module, include in `Object` instead of
304
309
  `Kernel`
305
- * Improve setting root fiber and corresponding coprocess
306
- * Fix `ResourcePool#preheat!`
307
- * Rename `$Coprocess#list` to `Coprocess#map`
308
- * Fix `CancelScope#on_cancel`, remove `CancelScope#protect`
309
- * Remove `auto_run` mechanism. Just use `suspend`!
310
- * Optional coverage report for tests
311
- * More tests
312
- * Add `Coprocess.select` and `Supervisor#select` methods
313
- * Add `Coprocess.join` alias to `Coprocess.await` method
314
- * Add support for cancelling multiple coprocesses with a single cancel scope
315
- * Fix stopping a coprocess before it being scheduled for the first time
316
- * Rewrite `thread`, `thread_pool` modules
317
- * Add `Kernel#orig_sleep` alias to sync `#sleep` method
318
- * Add optional resume value to `Gyro::Async#signal!`
319
- * Patch Fiber#inspect to show correct block location
320
- * Add Gyro.run
321
- * Move away from callback-based API for `Gyro::Timer`, `Gyro::Signal`
310
+ - Improve setting root fiber and corresponding coprocess
311
+ - Fix `ResourcePool#preheat!`
312
+ - Rename `$Coprocess#list` to `Coprocess#map`
313
+ - Fix `CancelScope#on_cancel`, remove `CancelScope#protect`
314
+ - Remove `auto_run` mechanism. Just use `suspend`!
315
+ - Optional coverage report for tests
316
+ - More tests
317
+ - Add `Coprocess.select` and `Supervisor#select` methods
318
+ - Add `Coprocess.join` alias to `Coprocess.await` method
319
+ - Add support for cancelling multiple coprocesses with a single cancel scope
320
+ - Fix stopping a coprocess before it being scheduled for the first time
321
+ - Rewrite `thread`, `thread_pool` modules
322
+ - Add `Kernel#orig_sleep` alias to sync `#sleep` method
323
+ - Add optional resume value to `Gyro::Async#signal!`
324
+ - Patch Fiber#inspect to show correct block location
325
+ - Add Gyro.run
326
+ - Move away from callback-based API for `Gyro::Timer`, `Gyro::Signal`
322
327
 
323
328
  ## 0.22 2020-01-02
324
329
 
325
- * Redesign Gyro scheduling subsystem, go scheduler-less
326
- * More docs
327
- * Rewrite HTTP client agent c1b63787
328
- * Increment Gyro refcount in ResourcePool#acquire
329
- * Rewrite ResourcePool
330
- * Fix socket extensions
331
- * Fix ALPN setup in Net.secure_socket
330
+ - Redesign Gyro scheduling subsystem, go scheduler-less
331
+ - More docs
332
+ - Rewrite HTTP client agent c1b63787
333
+ - Increment Gyro refcount in ResourcePool#acquire
334
+ - Rewrite ResourcePool
335
+ - Fix socket extensions
336
+ - Fix ALPN setup in Net.secure_socket
332
337
 
333
338
  ## 0.21 2019-12-12
334
339
 
335
- * Add Coprocess.await (for waiting for multiple coprocesses)
336
- * Add Coprocess#caller, Coprocess#location methods
337
- * Remove callback-oriented Gyro APIs
338
- * Revise signal handling API
339
- * Improve error handling in HTTP/2 adapter
340
- * More documentation
340
+ - Add Coprocess.await (for waiting for multiple coprocesses)
341
+ - Add Coprocess#caller, Coprocess#location methods
342
+ - Remove callback-oriented Gyro APIs
343
+ - Revise signal handling API
344
+ - Improve error handling in HTTP/2 adapter
345
+ - More documentation
341
346
 
342
347
  ## 0.20 2019-11-27
343
348
 
344
- * Refactor and improve CancelScope, ResourcePool
345
- * Reimplement cancel_after, move_on_after using plain timers
346
- * Use Timer#await instead of Timer#start in Pulser
347
- * Rename Fiber.main to Fiber.root
348
- * Replace use of defer with proper fiber scheduling
349
- * Improve Coprocess resume, interrupt, cancel methods
350
- * Cleanup code using Rubocop
351
- * Update and cleanup examples
352
- * Remove fiber pool
353
- * Rename `CoprocessInterrupt` to `Interrupt`
354
- * Fix ResourcePool, Mutex, Thread, ThreadPool
355
- * Fix coprocess message passing behaviour
356
- * Add HTTP::Request#consume API
357
- * Use bundler 2.x
358
- * Remove separate parse loop fiber in HTTP 1, HTTP 2 adapters
359
- * Fix handling of exceptions in coprocesses
360
- * Implement synthetic, sanitized exception backtrace showing control flow across
349
+ - Refactor and improve CancelScope, ResourcePool
350
+ - Reimplement cancel_after, move_on_after using plain timers
351
+ - Use Timer#await instead of Timer#start in Pulser
352
+ - Rename Fiber.main to Fiber.root
353
+ - Replace use of defer with proper fiber scheduling
354
+ - Improve Coprocess resume, interrupt, cancel methods
355
+ - Cleanup code using Rubocop
356
+ - Update and cleanup examples
357
+ - Remove fiber pool
358
+ - Rename `CoprocessInterrupt` to `Interrupt`
359
+ - Fix ResourcePool, Mutex, Thread, ThreadPool
360
+ - Fix coprocess message passing behaviour
361
+ - Add HTTP::Request#consume API
362
+ - Use bundler 2.x
363
+ - Remove separate parse loop fiber in HTTP 1, HTTP 2 adapters
364
+ - Fix handling of exceptions in coprocesses
365
+ - Implement synthetic, sanitized exception backtrace showing control flow across
361
366
  fibers
362
- * Fix channels
363
- * Fix HTTP1 connection shutdown and error states
364
- * Workaround for IO#read without length
365
- * Rename `next_tick` to `defer`
366
- * Fix race condition in firing of deferred items, use linked list instead of
367
+ - Fix channels
368
+ - Fix HTTP1 connection shutdown and error states
369
+ - Workaround for IO#read without length
370
+ - Rename `next_tick` to `defer`
371
+ - Fix race condition in firing of deferred items, use linked list instead of
367
372
  array for deferred items
368
- * Rename `EV` module to `Gyro`
369
- * Keep track of main fiber when forking
370
- * Add `<<` alias for `send_chunk` in HTTP::Request
371
- * Implement Socket#accept in C
372
- * Better conformance of rack adapter to rack spec (WIP)
373
- * Fix HTTP1 adapter
374
- * Better support for debugging with ruby-debug-ide (WIP)
373
+ - Rename `EV` module to `Gyro`
374
+ - Keep track of main fiber when forking
375
+ - Add `<<` alias for `send_chunk` in HTTP::Request
376
+ - Implement Socket#accept in C
377
+ - Better conformance of rack adapter to rack spec (WIP)
378
+ - Fix HTTP1 adapter
379
+ - Better support for debugging with ruby-debug-ide (WIP)
375
380
 
376
381
  ## 0.19 2019-06-12
377
382
 
378
- * Rewrite HTTP server for better concurrency, sequential API
379
- * Support 204 no-content response in HTTP 1
380
- * Add optional count parameter to Kernel#throttled_loop for finite looping
381
- * Implement Fiber#safe_transfer in C
382
- * Optimize Kernel#next_tick implementation using ev_idle instead of ev_timer
383
+ - Rewrite HTTP server for better concurrency, sequential API
384
+ - Support 204 no-content response in HTTP 1
385
+ - Add optional count parameter to Kernel#throttled_loop for finite looping
386
+ - Implement Fiber#safe_transfer in C
387
+ - Optimize Kernel#next_tick implementation using ev_idle instead of ev_timer
383
388
 
384
389
  ## 0.18 2019-06-08
385
390
 
386
- * Rename Kernel#coproc to Kernel#spin
387
- * Rewrite Supervisor#spin
391
+ - Rename Kernel#coproc to Kernel#spin
392
+ - Rewrite Supervisor#spin
388
393
 
389
394
  ## 0.17 2019-05-24
390
395
 
391
- * Implement IO#read_watcher, IO#write_watcher in C for better performance
392
- * Implement nonblocking (yielding) versions of Kernel#system, IO.popen,
396
+ - Implement IO#read_watcher, IO#write_watcher in C for better performance
397
+ - Implement nonblocking (yielding) versions of Kernel#system, IO.popen,
393
398
  Process.detach, IO#gets IO#puts, other IO singleton methods
394
- * Add Coprocess#join as alias to Coprocess#await
395
- * Rename Kernel#spawn to Kernel#coproc
396
- * Fix encoding of strings read with IO#read, IO#readpartial
397
- * Fix non-blocking behaviour of IO#read, IO#readpartial, IO#write
399
+ - Add Coprocess#join as alias to Coprocess#await
400
+ - Rename Kernel#spawn to Kernel#coproc
401
+ - Fix encoding of strings read with IO#read, IO#readpartial
402
+ - Fix non-blocking behaviour of IO#read, IO#readpartial, IO#write
398
403
 
399
404
  ## 0.16 2019-05-22
400
405
 
401
- * Reorganize and refactor code
402
- * Allow opening secure socket without OpenSSL context
406
+ - Reorganize and refactor code
407
+ - Allow opening secure socket without OpenSSL context
403
408
 
404
409
  ## 0.15 2019-05-20
405
410
 
406
- * Optimize `#next_tick` callback (about 6% faster than before)
407
- * Fix IO#<< to return self
408
- * Refactor HTTP code and examples
409
- * Fix race condition in `Supervisor#stop!`
410
- * Add `Kernel#snooze` method (`EV.snooze` will be deprecated eventually)
411
+ - Optimize `#next_tick` callback (about 6% faster than before)
412
+ - Fix IO#<< to return self
413
+ - Refactor HTTP code and examples
414
+ - Fix race condition in `Supervisor#stop!`
415
+ - Add `Kernel#snooze` method (`EV.snooze` will be deprecated eventually)
411
416
 
412
417
  ## 0.14 2019-05-17
413
418
 
414
- * Use chunked encoding in HTTP 1 response
415
- * Rewrite `IO#read`, `#readpartial`, `#write` in C (about 30% performance improvement)
416
- * Add method delegation to `ResourcePool`
417
- * Optimize PG::Connection#async_exec
418
- * Fix `Coprocess#cancel!`
419
- * Preliminary support for websocket (see `examples/io/http_ws_server.rb`)
420
- * Rename `Coroutine` to `Coprocess`
419
+ - Use chunked encoding in HTTP 1 response
420
+ - Rewrite `IO#read`, `#readpartial`, `#write` in C (about 30% performance improvement)
421
+ - Add method delegation to `ResourcePool`
422
+ - Optimize PG::Connection#async_exec
423
+ - Fix `Coprocess#cancel!`
424
+ - Preliminary support for websocket (see `examples/io/http_ws_server.rb`)
425
+ - Rename `Coroutine` to `Coprocess`
421
426
 
422
427
  ## 0.13 2019-01-05
423
428
 
424
- * Rename Rubato to Polyphony (I know, this is getting silly...)
429
+ - Rename Rubato to Polyphony (I know, this is getting silly...)
425
430
 
426
431
  ## 0.12 2019-01-01
427
432
 
428
- * Add Coroutine#resume
429
- * Improve startup time
430
- * Accept rate: or interval: arguments for throttle
431
- * Set correct backtrace for errors
432
- * Improve handling of uncaught raised errors
433
- * Implement HTTP 1.1/2 client agent with connection management
433
+ - Add Coroutine#resume
434
+ - Improve startup time
435
+ - Accept rate: or interval: arguments for throttle
436
+ - Set correct backtrace for errors
437
+ - Improve handling of uncaught raised errors
438
+ - Implement HTTP 1.1/2 client agent with connection management
434
439
 
435
440
  ## 0.11 2018-12-27
436
441
 
437
- * Move reactor loop to secondary fiber, allow blocking operations on main
442
+ - Move reactor loop to secondary fiber, allow blocking operations on main
438
443
  fiber.
439
- * Example implementation of erlang-style generic server pattern (implement async
444
+ - Example implementation of erlang-style generic server pattern (implement async
440
445
  API to a coroutine)
441
- * Implement coroutine mailboxes, Coroutine#<<, Coroutine#receive, Kernel.receive
446
+ - Implement coroutine mailboxes, Coroutine#<<, Coroutine#receive, Kernel.receive
442
447
  for message passing
443
- * Add Coroutine.current for getting current coroutine
448
+ - Add Coroutine.current for getting current coroutine
444
449
 
445
450
  ## 0.10 2018-11-20
446
451
 
447
- * Rewrite Rubato core for simpler code and better performance
448
- * Implement EV.snooze (sleep until next tick)
449
- * Coroutine encapsulates a task spawned on a separate fiber
450
- * Supervisor supervises multiple coroutines
451
- * CancelScope used to cancel an ongoing task (usually with a timeout)
452
- * Rate throttling
453
- * Implement async SSL server
452
+ - Rewrite Rubato core for simpler code and better performance
453
+ - Implement EV.snooze (sleep until next tick)
454
+ - Coroutine encapsulates a task spawned on a separate fiber
455
+ - Supervisor supervises multiple coroutines
456
+ - CancelScope used to cancel an ongoing task (usually with a timeout)
457
+ - Rate throttling
458
+ - Implement async SSL server
454
459
 
455
460
  ## 0.9 2018-11-14
456
461
 
457
- * Rename Nuclear to Rubato
462
+ - Rename Nuclear to Rubato
458
463
 
459
464
  ## 0.8 2018-10-04
460
465
 
461
- * Replace nio4r with in-house extension based on libev, with better API,
466
+ - Replace nio4r with in-house extension based on libev, with better API,
462
467
  better performance, support for IO, timer, signal and async watchers
463
- * Fix mem leak coming from nio4r (probably related to code in Selector#select)
468
+ - Fix mem leak coming from nio4r (probably related to code in Selector#select)
464
469
 
465
470
  ## 0.7 2018-09-13
466
471
 
467
- * Implement resource pool
468
- * transaction method for pg cient
469
- * Async connect for pg client
470
- * Add testing module for testing async code
471
- * Improve HTTP server performance
472
- * Proper promise chaining
472
+ - Implement resource pool
473
+ - transaction method for pg cient
474
+ - Async connect for pg client
475
+ - Add testing module for testing async code
476
+ - Improve HTTP server performance
477
+ - Proper promise chaining
473
478
 
474
479
  ## 0.6 2018-09-11
475
480
 
476
- * Add http, redis, pg dependencies
477
- * Move ALPN code inside net module
481
+ - Add http, redis, pg dependencies
482
+ - Move ALPN code inside net module
478
483
 
479
484
  ## 0.4 2018-09-10
480
485
 
481
- * Code refactored and reogranized
482
- * Fix recursion in next_tick
483
- * HTTP 2 server with support for ALPN protocol negotiation and HTTP upgrade
484
- * OpenSSL server
486
+ - Code refactored and reogranized
487
+ - Fix recursion in next_tick
488
+ - HTTP 2 server with support for ALPN protocol negotiation and HTTP upgrade
489
+ - OpenSSL server
485
490
 
486
491
  ## 0.3 2018-09-06
487
492
 
488
- * Event reactor
489
- * Timers
490
- * Promises
491
- * async/await syntax for promises
492
- * IO and read/write stream
493
- * TCP server/client
494
- * Promised threads
495
- * HTTP server
496
- * Redis interface
497
- * PostgreSQL interface
493
+ - Event reactor
494
+ - Timers
495
+ - Promises
496
+ - async/await syntax for promises
497
+ - IO and read/write stream
498
+ - TCP server/client
499
+ - Promised threads
500
+ - HTTP server
501
+ - Redis interface
502
+ - PostgreSQL interface
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polyphony (0.47.4)
4
+ polyphony (0.47.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/TODO.md CHANGED
@@ -1,17 +1,13 @@
1
1
  - Graceful shutdown again:
2
2
 
3
- - Add `Polyphony::GracefulShutdown` exception
4
- - Two exceptions for stopping fibers:
5
- - `Polyphony::GracefulShutdown` - graceful shutdown
6
- - `Polyphony::Terminate` - ungraceful shutdown
7
3
  - Fiber API:
8
- - `Fiber#shutdown_children` - graceful shutdown of all children
9
- - `Fiber#terminate_children` - ungraceful shutdown of all children
4
+ - `Fiber#terminate(graceul)` - with a graceful flag
5
+ - `Fiber#terminate_all_children(graceful)` - with a graceful flag
6
+ - `Fiber#shutdown_all_children(graceful)` - with a graceful flag
10
7
 
8
+ - Set graceful termination in `@graceful_shutdown`
11
9
  - Add `Fiber#graceful_shutdown?` method
12
- - Returns false unless a `Polyphony::GracefulShutdown` was raised
13
- - Override `Polyphony::Terminate#invoke` to reset the `@graceful_shutdown` fiber
14
- flag
10
+ - Returns `@graceful_shutdown`
15
11
 
16
12
  And then we have:
17
13
 
@@ -19,15 +15,11 @@
19
15
  spin do
20
16
  loop { do_some_stuff }
21
17
  ensure
22
- return unless Fiber.current.graceful_shutdown?
23
-
24
- shutdown_gracefully
18
+ shutdown_gracefully if Fiber.current.graceful_shutdown?
25
19
  end
26
20
  ```
27
21
 
28
- - When a fiber is stopped it should use `Polyphony::Terminate` to stop child
29
- fibers, *unless* it was stopped with a `Polyphony::GracefulShutdown` (which it
30
- can check with `@graceful_shutdown`).
22
+ - `Fiber#finalize_children` should pass graceful shutdown flag to children
31
23
 
32
24
  - More tight loops
33
25
  - IO#gets_loop, Socket#gets_loop, OpenSSL::Socket#gets_loop (medium effort)
@@ -37,13 +29,13 @@
37
29
 
38
30
  - check integration with rb-inotify
39
31
 
40
- - Check why worker-thread example doesn't work.
32
+ - Improve `#supervise`. It does not work as advertised, and seems to exhibit an
33
+ inconsistent behaviour (see supervisor example).
34
+
41
35
  - Add test that mimics the original design for Monocrono:
42
36
  - 256 fibers each waiting for a message
43
37
  - When message received do some blocking work using a `ThreadPool`
44
38
  - Send messages, collect responses, check for correctness
45
- - Improve `#supervise`. It does not work as advertised, and seems to exhibit an
46
- inconsistent behaviour (see supervisor example).
47
39
 
48
40
  - io_uring
49
41
  - Use playground.c to find out why we when submitting and waiting for
@@ -9,9 +9,9 @@ def my_sleep(t)
9
9
  puts "#{t} done"
10
10
  end
11
11
 
12
- spin { my_sleep(1) }
13
- spin { my_sleep(2) }
14
- spin { my_sleep(3) }
12
+ spin { my_sleep(0.1) }
13
+ spin { my_sleep(0.2) }
14
+ spin { my_sleep(0.3) }
15
15
  spin { puts "fiber count: #{Fiber.current.children.count}" }
16
16
  snooze
17
17
 
@@ -13,11 +13,9 @@ end
13
13
  $worker = Thread.new do
14
14
  Fiber.current.tag = :worker
15
15
  loop do
16
- client, block = receive
16
+ (client, block) = receive
17
17
  do_work(client, &block)
18
18
  end
19
- rescue Exception => e
20
- p e
21
19
  end
22
20
 
23
21
  def process(&block)
@@ -27,4 +25,5 @@ end
27
25
 
28
26
  sleep 0.1
29
27
 
30
- p process { 1 + 1 }
28
+ p process { 1 + 1 }
29
+ p process { 42 ** 2 }
@@ -3,26 +3,6 @@
3
3
  #include "ruby.h"
4
4
  #include "ruby/io.h"
5
5
 
6
- VALUE cTCPSocket;
7
- VALUE cTCPServer;
8
- VALUE cUNIXSocket;
9
- VALUE cUNIXServer;
10
-
11
- void Init_SocketClasses() {
12
- rb_require("socket");
13
- cTCPSocket = rb_const_get(rb_cObject, rb_intern("TCPSocket"));
14
- cTCPServer = rb_const_get(rb_cObject, rb_intern("TCPServer"));
15
- cUNIXSocket = rb_const_get(rb_cObject, rb_intern("UNIXSocket"));
16
- cUNIXServer = rb_const_get(rb_cObject, rb_intern("UNIXServer"));
17
- }
18
-
19
- VALUE ConnectionSocketClass(VALUE server) {
20
- if (RTEST(rb_obj_is_kind_of(server, cTCPServer))) return cTCPSocket;
21
- if (RTEST(rb_obj_is_kind_of(server, cUNIXServer))) return cUNIXSocket;
22
-
23
- rb_raise(rb_eRuntimeError, "Invalid server class");
24
- }
25
-
26
6
  //////////////////////////////////////////////////////////////////////
27
7
  //////////////////////////////////////////////////////////////////////
28
8
  // the following is copied verbatim from the Ruby source code (io.c)
@@ -668,12 +668,11 @@ VALUE Backend_send(VALUE self, VALUE io, VALUE str) {
668
668
  return INT2NUM(len);
669
669
  }
670
670
 
671
- VALUE io_uring_backend_accept(Backend_t *backend, VALUE server_socket, int loop) {
671
+ VALUE io_uring_backend_accept(Backend_t *backend, VALUE server_socket, VALUE socket_class, int loop) {
672
672
  rb_io_t *fptr;
673
673
  struct sockaddr addr;
674
674
  socklen_t len = (socklen_t)sizeof addr;
675
675
  VALUE socket = Qnil;
676
- VALUE socket_class = ConnectionSocketClass(server_socket);
677
676
  VALUE underlying_sock = rb_ivar_get(server_socket, ID_ivar_io);
678
677
  if (underlying_sock != Qnil) server_socket = underlying_sock;
679
678
 
@@ -718,16 +717,16 @@ VALUE io_uring_backend_accept(Backend_t *backend, VALUE server_socket, int loop)
718
717
  return Qnil;
719
718
  }
720
719
 
721
- VALUE Backend_accept(VALUE self, VALUE sock) {
720
+ VALUE Backend_accept(VALUE self, VALUE server_socket, VALUE socket_class) {
722
721
  Backend_t *backend;
723
722
  GetBackend(self, backend);
724
- return io_uring_backend_accept(backend, sock, 0);
723
+ return io_uring_backend_accept(backend, server_socket, socket_class, 0);
725
724
  }
726
725
 
727
- VALUE Backend_accept_loop(VALUE self, VALUE sock) {
726
+ VALUE Backend_accept_loop(VALUE self, VALUE server_socket, VALUE socket_class) {
728
727
  Backend_t *backend;
729
728
  GetBackend(self, backend);
730
- io_uring_backend_accept(backend, sock, 1);
729
+ io_uring_backend_accept(backend, server_socket, socket_class, 1);
731
730
  return self;
732
731
  }
733
732
 
@@ -945,8 +944,6 @@ VALUE Backend_kind(VALUE self) {
945
944
  }
946
945
 
947
946
  void Init_Backend() {
948
- Init_SocketClasses();
949
-
950
947
  VALUE cBackend = rb_define_class_under(mPolyphony, "Backend", rb_cData);
951
948
  rb_define_alloc_func(cBackend, Backend_allocate);
952
949
 
@@ -967,8 +964,8 @@ void Init_Backend() {
967
964
  rb_define_method(cBackend, "recv", Backend_recv, 3);
968
965
  rb_define_method(cBackend, "recv_loop", Backend_recv_loop, 1);
969
966
  rb_define_method(cBackend, "send", Backend_send, 2);
970
- rb_define_method(cBackend, "accept", Backend_accept, 1);
971
- rb_define_method(cBackend, "accept_loop", Backend_accept_loop, 1);
967
+ rb_define_method(cBackend, "accept", Backend_accept, 2);
968
+ rb_define_method(cBackend, "accept_loop", Backend_accept_loop, 2);
972
969
  rb_define_method(cBackend, "connect", Backend_connect, 3);
973
970
  rb_define_method(cBackend, "wait_io", Backend_wait_io, 2);
974
971
  rb_define_method(cBackend, "sleep", Backend_sleep, 1);
@@ -493,7 +493,7 @@ VALUE Backend_write_m(int argc, VALUE *argv, VALUE self) {
493
493
  Backend_writev(self, argv[0], argc - 1, argv + 1);
494
494
  }
495
495
 
496
- VALUE Backend_accept(VALUE self, VALUE server_socket) {
496
+ VALUE Backend_accept(VALUE self, VALUE server_socket, VALUE socket_class) {
497
497
  Backend_t *backend;
498
498
  struct libev_io watcher;
499
499
  rb_io_t *fptr;
@@ -501,7 +501,6 @@ VALUE Backend_accept(VALUE self, VALUE server_socket) {
501
501
  struct sockaddr addr;
502
502
  socklen_t len = (socklen_t)sizeof addr;
503
503
  VALUE switchpoint_result = Qnil;
504
- VALUE socket_class = ConnectionSocketClass(server_socket);
505
504
  VALUE underlying_sock = rb_ivar_get(server_socket, ID_ivar_io);
506
505
  if (underlying_sock != Qnil) server_socket = underlying_sock;
507
506
 
@@ -550,7 +549,7 @@ error:
550
549
  return RAISE_EXCEPTION(switchpoint_result);
551
550
  }
552
551
 
553
- VALUE Backend_accept_loop(VALUE self, VALUE server_socket) {
552
+ VALUE Backend_accept_loop(VALUE self, VALUE server_socket, VALUE socket_class) {
554
553
  Backend_t *backend;
555
554
  struct libev_io watcher;
556
555
  rb_io_t *fptr;
@@ -559,7 +558,6 @@ VALUE Backend_accept_loop(VALUE self, VALUE server_socket) {
559
558
  socklen_t len = (socklen_t)sizeof addr;
560
559
  VALUE switchpoint_result = Qnil;
561
560
  VALUE socket = Qnil;
562
- VALUE socket_class = ConnectionSocketClass(server_socket);
563
561
  VALUE underlying_sock = rb_ivar_get(server_socket, ID_ivar_io);
564
562
  if (underlying_sock != Qnil) server_socket = underlying_sock;
565
563
 
@@ -850,8 +848,6 @@ VALUE Backend_kind(VALUE self) {
850
848
  void Init_Backend() {
851
849
  ev_set_allocator(xrealloc);
852
850
 
853
- Init_SocketClasses();
854
-
855
851
  VALUE cBackend = rb_define_class_under(mPolyphony, "Backend", rb_cData);
856
852
  rb_define_alloc_func(cBackend, Backend_allocate);
857
853
 
@@ -869,8 +865,8 @@ void Init_Backend() {
869
865
  rb_define_method(cBackend, "read", Backend_read, 4);
870
866
  rb_define_method(cBackend, "read_loop", Backend_read_loop, 1);
871
867
  rb_define_method(cBackend, "write", Backend_write_m, -1);
872
- rb_define_method(cBackend, "accept", Backend_accept, 1);
873
- rb_define_method(cBackend, "accept_loop", Backend_accept_loop, 1);
868
+ rb_define_method(cBackend, "accept", Backend_accept, 2);
869
+ rb_define_method(cBackend, "accept_loop", Backend_accept_loop, 2);
874
870
  rb_define_method(cBackend, "connect", Backend_connect, 3);
875
871
  rb_define_method(cBackend, "recv", Backend_recv, 3);
876
872
  rb_define_method(cBackend, "recv_loop", Backend_read_loop, 1);
@@ -67,19 +67,29 @@ module Polyphony
67
67
  self << fiber unless result.is_a?(Exception)
68
68
  end
69
69
  loop { supervise_perform(opts) }
70
+ rescue Polyphony::MoveOn
71
+ # generated in #supervise_perform to stop supervisor
70
72
  ensure
71
73
  @on_child_done = nil
72
74
  end
73
75
 
74
76
  def supervise_perform(opts)
75
77
  fiber = receive
76
- restart_fiber(fiber, opts) if fiber
78
+ if fiber && opts[:restart]
79
+ restart_fiber(fiber, opts)
80
+ elsif Fiber.current.children.empty?
81
+ Fiber.current.stop
82
+ end
77
83
  rescue Polyphony::Restart
78
84
  restart_all_children
79
85
  rescue Exception => e
80
86
  Kernel.raise e if e.source_fiber.nil? || e.source_fiber == self
81
87
 
82
- restart_fiber(e.source_fiber, opts)
88
+ if opts[:restart]
89
+ restart_fiber(e.source_fiber, opts)
90
+ elsif Fiber.current.children.empty?
91
+ Fiber.current.stop
92
+ end
83
93
  end
84
94
 
85
95
  def restart_fiber(fiber, opts)
@@ -8,7 +8,7 @@ require_relative '../core/thread_pool'
8
8
  # Socket overrides (eventually rewritten in C)
9
9
  class ::Socket
10
10
  def accept
11
- Thread.current.backend.accept(self)
11
+ Thread.current.backend.accept(self, TCPSocket)
12
12
  end
13
13
 
14
14
  NO_EXCEPTION = { exception: false }.freeze
@@ -134,7 +134,7 @@ class ::TCPSocket
134
134
  end
135
135
 
136
136
  def recv(maxlen, flags = 0, outbuf = nil)
137
- Thread.current.backend.recv(self, buf || +'', maxlen)
137
+ Thread.current.backend.recv(self, outbuf || +'', maxlen)
138
138
  end
139
139
 
140
140
  def recv_loop(&block)
@@ -188,11 +188,12 @@ class ::TCPServer
188
188
 
189
189
  alias_method :orig_accept, :accept
190
190
  def accept
191
- @io.accept
191
+ Thread.current.backend.accept(@io, TCPSocket)
192
+ # @io.accept
192
193
  end
193
194
 
194
195
  def accept_loop(&block)
195
- Thread.current.backend.accept_loop(@io, &block)
196
+ Thread.current.backend.accept_loop(@io, TCPSocket, &block)
196
197
  end
197
198
 
198
199
  alias_method :orig_close, :close
@@ -204,19 +205,17 @@ end
204
205
  class ::UNIXServer
205
206
  alias_method :orig_accept, :accept
206
207
  def accept
207
- Thread.current.backend.accept(self)
208
+ Thread.current.backend.accept(self, UNIXSocket)
208
209
  end
209
210
 
210
211
  def accept_loop(&block)
211
- Thread.current.backend.accept_loop(self, &block)
212
+ Thread.current.backend.accept_loop(self, UNIXSocket, &block)
212
213
  end
213
-
214
-
215
214
  end
216
215
 
217
216
  class ::UNIXSocket
218
217
  def recv(maxlen, flags = 0, outbuf = nil)
219
- Thread.current.backend.recv(self, buf || +'', maxlen)
218
+ Thread.current.backend.recv(self, outbuf || +'', maxlen)
220
219
  end
221
220
 
222
221
  def recv_loop(&block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polyphony
4
- VERSION = '0.47.4'
4
+ VERSION = '0.47.5'
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'helper'
4
+ require 'fileutils'
4
5
 
5
6
  class SocketTest < MiniTest::Test
6
7
  def setup
@@ -24,7 +25,32 @@ class SocketTest < MiniTest::Test
24
25
  snooze
25
26
  client = TCPSocket.new('127.0.0.1', port)
26
27
  client.write("1234\n")
27
- assert_equal "1234\n", client.readpartial(8192)
28
+ assert_equal "1234\n", client.recv(8192)
29
+ client.close
30
+ ensure
31
+ server_fiber&.stop
32
+ server_fiber&.await
33
+ server&.close
34
+ end
35
+
36
+ def test_unix_socket
37
+ path = '/tmp/test_unix_socket'
38
+ FileUtils.rm(path) rescue nil
39
+ server = UNIXServer.new(path)
40
+ server_fiber = spin do
41
+ server.accept_loop do |socket|
42
+ spin do
43
+ while (data = socket.gets(8192))
44
+ socket << data
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ snooze
51
+ client = UNIXSocket.new(path)
52
+ client.write("1234\n")
53
+ assert_equal "1234\n", client.recv(8192)
28
54
  client.close
29
55
  ensure
30
56
  server_fiber&.stop
@@ -20,9 +20,10 @@ class SuperviseTest < MiniTest::Test
20
20
 
21
21
  f2 << 'bar'
22
22
  f2.await
23
+ assert_equal :waiting, p.state
23
24
  snooze
24
25
 
25
- assert_equal :waiting, p.state
26
+ assert_equal :dead, p.state
26
27
  end
27
28
 
28
29
  def test_supervise_with_restart
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: 0.47.4
4
+ version: 0.47.5
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-11-14 00:00:00.000000000 Z
11
+ date: 2020-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler