polyphony 0.99.4 → 0.99.6
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 +4 -4
- data/.rubocop.yml +11 -0
- data/.yardopts +0 -2
- data/README.md +1 -1
- data/docs/readme.md +1 -1
- data/docs/tutorial.md +2 -2
- data/examples/pipes/gzip_http_server.rb +2 -2
- data/examples/pipes/http_server.rb +1 -1
- data/examples/pipes/tcp_proxy.rb +1 -1
- data/ext/polyphony/backend_common.c +4 -4
- data/ext/polyphony/backend_io_uring.c +8 -8
- data/ext/polyphony/backend_libev.c +5 -5
- data/ext/polyphony/fiber.c +33 -42
- data/ext/polyphony/io_extensions.c +50 -37
- data/ext/polyphony/pipe.c +6 -20
- data/ext/polyphony/polyphony.c +72 -144
- data/ext/polyphony/queue.c +23 -63
- data/ext/polyphony/thread.c +4 -13
- data/lib/polyphony/adapters/process.rb +2 -5
- data/lib/polyphony/adapters/sequel.rb +2 -2
- data/lib/polyphony/core/debug.rb +1 -4
- data/lib/polyphony/core/exceptions.rb +1 -5
- data/lib/polyphony/core/resource_pool.rb +7 -8
- data/lib/polyphony/core/sync.rb +5 -8
- data/lib/polyphony/core/thread_pool.rb +3 -10
- data/lib/polyphony/core/throttler.rb +1 -5
- data/lib/polyphony/core/timer.rb +23 -30
- data/lib/polyphony/extensions/fiber.rb +513 -543
- data/lib/polyphony/extensions/io.rb +5 -14
- data/lib/polyphony/extensions/object.rb +283 -2
- data/lib/polyphony/extensions/openssl.rb +5 -26
- data/lib/polyphony/extensions/pipe.rb +6 -17
- data/lib/polyphony/extensions/socket.rb +24 -118
- data/lib/polyphony/extensions/thread.rb +3 -18
- data/lib/polyphony/extensions/timeout.rb +0 -1
- data/lib/polyphony/net.rb +5 -9
- data/lib/polyphony/version.rb +1 -1
- data/lib/polyphony.rb +2 -6
- data/test/test_io.rb +221 -221
- data/test/test_socket.rb +3 -3
- data/test/test_trace.rb +2 -2
- metadata +5 -9
- data/docs/index.md +0 -94
- data/docs/link_rewriter.rb +0 -17
- data/docs/main-concepts/index.md +0 -9
- data/lib/polyphony/core/global_api.rb +0 -309
- /data/{assets → docs/assets}/echo-fibers.svg +0 -0
- /data/{assets → docs/assets}/polyphony-logo.png +0 -0
- /data/{assets → docs/assets}/sleeping-fiber.svg +0 -0
@@ -28,19 +28,16 @@ end
|
|
28
28
|
class ::Socket < ::BasicSocket
|
29
29
|
|
30
30
|
# Accepts an incoming connection.
|
31
|
-
|
31
|
+
|
32
32
|
# @return [TCPSocket] new connection
|
33
33
|
def accept
|
34
34
|
Polyphony.backend_accept(self, TCPSocket)
|
35
35
|
end
|
36
36
|
|
37
|
-
# call-seq:
|
38
|
-
# socket.accept_loop { |conn| ... }
|
39
|
-
#
|
40
37
|
# Accepts incoming connections in an infinite loop.
|
41
38
|
#
|
42
|
-
# @yield [Socket]
|
43
|
-
# @return [
|
39
|
+
# @yield [Socket] accepted socket
|
40
|
+
# @return [nil]
|
44
41
|
def accept_loop(&block)
|
45
42
|
Polyphony.backend_accept_loop(self, TCPSocket, &block)
|
46
43
|
end
|
@@ -61,12 +58,6 @@ class ::Socket < ::BasicSocket
|
|
61
58
|
# @!visibility private
|
62
59
|
alias_method :orig_read, :read
|
63
60
|
|
64
|
-
# call-seq:
|
65
|
-
# socket.read -> string
|
66
|
-
# socket.read(maxlen) -> string
|
67
|
-
# socket.read(maxlen, buf) -> buf
|
68
|
-
# socket.read(maxlen, buf, buf_pos) -> buf
|
69
|
-
#
|
70
61
|
# Reads from the socket. If `maxlen` is given, reads up to `maxlen` bytes from
|
71
62
|
# the socket, otherwise reads to `EOF`. If `buf` is given, it is used as the
|
72
63
|
# buffer to read into, otherwise a new string is allocated. If `buf_pos` is
|
@@ -98,11 +89,6 @@ class ::Socket < ::BasicSocket
|
|
98
89
|
buf
|
99
90
|
end
|
100
91
|
|
101
|
-
# call-seq:
|
102
|
-
# socket.recv(maxlen) -> string
|
103
|
-
# socket.recv(maxlen, flags) -> string
|
104
|
-
# socket.recv(maxlen, flags, buf) -> buf
|
105
|
-
#
|
106
92
|
# Receives up to `maxlen` bytes from the socket. If `outbuf` is given, it is
|
107
93
|
# used as the buffer to receive into, otherwise a new string is allocated and
|
108
94
|
# used as buffer.
|
@@ -118,27 +104,17 @@ class ::Socket < ::BasicSocket
|
|
118
104
|
Polyphony.backend_recv(self, outbuf || +'', maxlen, 0)
|
119
105
|
end
|
120
106
|
|
121
|
-
# call-seq:
|
122
|
-
# socket.recv_loop { |data| ... }
|
123
|
-
# socket.recv_loop(maxlen) { |data| ... }
|
124
|
-
# socket.read_loop { |data| ... }
|
125
|
-
# socket.read_loop(maxlen) { |data| ... }
|
126
|
-
#
|
127
107
|
# Receives up to `maxlen` bytes at a time in an infinite loop. Read buffers
|
128
108
|
# will be passed to the given block.
|
129
109
|
#
|
130
110
|
# @param maxlen [Integer] maximum bytes to receive
|
131
|
-
# @yield [String]
|
132
|
-
# @return [
|
111
|
+
# @yield [String] received data
|
112
|
+
# @return [Socket] self
|
133
113
|
def recv_loop(maxlen = 8192, &block)
|
134
114
|
Polyphony.backend_recv_loop(self, maxlen, &block)
|
135
115
|
end
|
136
116
|
alias_method :read_loop, :recv_loop
|
137
117
|
|
138
|
-
# call-seq:
|
139
|
-
# socket.feed_loop(receiver, method)
|
140
|
-
# socket.feed_loop(receiver, method) { |result| ... }
|
141
|
-
#
|
142
118
|
# Receives data from the socket in an infinite loop, passing the data to the
|
143
119
|
# given receiver using the given method. If a block is given, the result of
|
144
120
|
# the method call to the receiver is passed to the block.
|
@@ -155,8 +131,7 @@ class ::Socket < ::BasicSocket
|
|
155
131
|
#
|
156
132
|
# @param receiver [any] receiver object
|
157
133
|
# @param method [Symbol] method to call
|
158
|
-
# @
|
159
|
-
# @return [void]
|
134
|
+
# @return [Socket] self
|
160
135
|
def feed_loop(receiver, method = :call, &block)
|
161
136
|
Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
|
162
137
|
end
|
@@ -179,12 +154,6 @@ class ::Socket < ::BasicSocket
|
|
179
154
|
end
|
180
155
|
end
|
181
156
|
|
182
|
-
# call-seq:
|
183
|
-
# socket.readpartial(maxlen) -> string
|
184
|
-
# socket.readpartial(maxlen, buf) -> buf
|
185
|
-
# socket.readpartial(maxlen, buf, buf_pos) -> buf
|
186
|
-
# socket.readpartial(maxlen, buf, buf_pos, raise_on_eof) -> buf
|
187
|
-
#
|
188
157
|
# Reads up to `maxlen` from the socket. If `buf` is given, it is used as the
|
189
158
|
# buffer to read into, otherwise a new string is allocated. If `buf_pos` is
|
190
159
|
# given, reads into the given offset (in bytes) in the given buffer. If the
|
@@ -246,7 +215,7 @@ class ::Socket < ::BasicSocket
|
|
246
215
|
class << self
|
247
216
|
# @!visibility private
|
248
217
|
alias_method :orig_getaddrinfo, :getaddrinfo
|
249
|
-
|
218
|
+
|
250
219
|
# Resolves the given addr using a worker thread from the default thread
|
251
220
|
# pool.
|
252
221
|
#
|
@@ -291,7 +260,7 @@ class ::TCPSocket < ::IPSocket
|
|
291
260
|
|
292
261
|
# @!visibility private
|
293
262
|
alias_method :orig_close, :close
|
294
|
-
|
263
|
+
|
295
264
|
# Closes the socket.
|
296
265
|
#
|
297
266
|
# @return [TCPSocket] self
|
@@ -302,7 +271,7 @@ class ::TCPSocket < ::IPSocket
|
|
302
271
|
|
303
272
|
# @!visibility private
|
304
273
|
alias_method :orig_setsockopt, :setsockopt
|
305
|
-
|
274
|
+
|
306
275
|
# Calls `setsockopt` with the given arguments.
|
307
276
|
#
|
308
277
|
# @return [TCPSocket] self
|
@@ -313,7 +282,7 @@ class ::TCPSocket < ::IPSocket
|
|
313
282
|
|
314
283
|
# @!visibility private
|
315
284
|
alias_method :orig_closed?, :closed?
|
316
|
-
|
285
|
+
|
317
286
|
# Returns true if the socket is closed.
|
318
287
|
#
|
319
288
|
# @return [bool] is socket closed
|
@@ -356,12 +325,6 @@ class ::TCPSocket < ::IPSocket
|
|
356
325
|
# @!visibility private
|
357
326
|
alias_method :orig_read, :read
|
358
327
|
|
359
|
-
# call-seq:
|
360
|
-
# socket.read -> string
|
361
|
-
# socket.read(maxlen) -> string
|
362
|
-
# socket.read(maxlen, buf) -> buf
|
363
|
-
# socket.read(maxlen, buf, buf_pos) -> buf
|
364
|
-
#
|
365
328
|
# Reads from the socket. If `maxlen` is given, reads up to `maxlen` bytes from
|
366
329
|
# the socket, otherwise reads to `EOF`. If `buf` is given, it is used as the
|
367
330
|
# buffer to read into, otherwise a new string is allocated. If `buf_pos` is
|
@@ -393,11 +356,6 @@ class ::TCPSocket < ::IPSocket
|
|
393
356
|
buf
|
394
357
|
end
|
395
358
|
|
396
|
-
# call-seq:
|
397
|
-
# socket.recv(maxlen) -> string
|
398
|
-
# socket.recv(maxlen, flags) -> string
|
399
|
-
# socket.recv(maxlen, flags, buf) -> buf
|
400
|
-
#
|
401
359
|
# Receives up to `maxlen` bytes from the socket. If `outbuf` is given, it is
|
402
360
|
# used as the buffer to receive into, otherwise a new string is allocated and
|
403
361
|
# used as buffer.
|
@@ -413,27 +371,17 @@ class ::TCPSocket < ::IPSocket
|
|
413
371
|
Polyphony.backend_recv(self, outbuf || +'', maxlen, 0)
|
414
372
|
end
|
415
373
|
|
416
|
-
# call-seq:
|
417
|
-
# socket.recv_loop { |data| ... }
|
418
|
-
# socket.recv_loop(maxlen) { |data| ... }
|
419
|
-
# socket.read_loop { |data| ... }
|
420
|
-
# socket.read_loop(maxlen) { |data| ... }
|
421
|
-
#
|
422
374
|
# Receives up to `maxlen` bytes at a time in an infinite loop. Read buffers
|
423
375
|
# will be passed to the given block.
|
424
376
|
#
|
425
377
|
# @param maxlen [Integer] maximum bytes to receive
|
426
|
-
# @yield [String]
|
427
|
-
# @return [
|
378
|
+
# @yield [String] received data
|
379
|
+
# @return [Socket] self
|
428
380
|
def recv_loop(maxlen = 8192, &block)
|
429
381
|
Polyphony.backend_recv_loop(self, maxlen, &block)
|
430
382
|
end
|
431
383
|
alias_method :read_loop, :recv_loop
|
432
384
|
|
433
|
-
# call-seq:
|
434
|
-
# socket.feed_loop(receiver, method)
|
435
|
-
# socket.feed_loop(receiver, method) { |result| ... }
|
436
|
-
#
|
437
385
|
# Receives data from the socket in an infinite loop, passing the data to the
|
438
386
|
# given receiver using the given method. If a block is given, the result of
|
439
387
|
# the method call to the receiver is passed to the block.
|
@@ -450,18 +398,11 @@ class ::TCPSocket < ::IPSocket
|
|
450
398
|
#
|
451
399
|
# @param receiver [any] receiver object
|
452
400
|
# @param method [Symbol] method to call
|
453
|
-
# @
|
454
|
-
# @return [void]
|
401
|
+
# @return [Socket] self
|
455
402
|
def feed_loop(receiver, method = :call, &block)
|
456
403
|
Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
|
457
404
|
end
|
458
405
|
|
459
|
-
# call-seq:
|
460
|
-
# socket.readpartial(maxlen) -> string
|
461
|
-
# socket.readpartial(maxlen, buf) -> buf
|
462
|
-
# socket.readpartial(maxlen, buf, buf_pos) -> buf
|
463
|
-
# socket.readpartial(maxlen, buf, buf_pos, raise_on_eof) -> buf
|
464
|
-
#
|
465
406
|
# Reads up to `maxlen` from the socket. If `buf` is given, it is used as the
|
466
407
|
# buffer to read into, otherwise a new string is allocated. If `buf_pos` is
|
467
408
|
# given, reads into the given offset (in bytes) in the given buffer. If the
|
@@ -530,7 +471,7 @@ class ::TCPServer < ::TCPSocket
|
|
530
471
|
alias_method :orig_accept, :accept
|
531
472
|
|
532
473
|
# Accepts an incoming connection.
|
533
|
-
|
474
|
+
|
534
475
|
# @return [TCPSocket] new connection
|
535
476
|
def accept
|
536
477
|
Polyphony.backend_accept(@io, TCPSocket)
|
@@ -544,27 +485,23 @@ class ::TCPServer < ::TCPSocket
|
|
544
485
|
# server.accept_loop { |c| handle_connection(c) }
|
545
486
|
# end
|
546
487
|
#
|
547
|
-
# @yield [TCPSocket] code block
|
548
488
|
# @return [any] return value of code block
|
549
489
|
def multishot_accept(&block)
|
550
490
|
Polyphony.backend_multishot_accept(@io, &block)
|
551
491
|
end
|
552
492
|
end
|
553
493
|
|
554
|
-
# call-seq:
|
555
|
-
# socket.accept_loop { |conn| ... }
|
556
|
-
#
|
557
494
|
# Accepts incoming connections in an infinite loop.
|
558
495
|
#
|
559
|
-
# @yield [TCPSocket]
|
560
|
-
# @return [
|
496
|
+
# @yield [TCPSocket] accepted socket
|
497
|
+
# @return [nil]
|
561
498
|
def accept_loop(&block)
|
562
499
|
Polyphony.backend_accept_loop(@io, TCPSocket, &block)
|
563
500
|
end
|
564
501
|
|
565
502
|
# @!visibility private
|
566
503
|
alias_method :orig_close, :close
|
567
|
-
|
504
|
+
|
568
505
|
# Closes the server socket.
|
569
506
|
#
|
570
507
|
# @return [TCPServer] self
|
@@ -580,19 +517,16 @@ class ::UNIXServer < ::UNIXSocket
|
|
580
517
|
alias_method :orig_accept, :accept
|
581
518
|
|
582
519
|
# Accepts an incoming connection.
|
583
|
-
|
520
|
+
|
584
521
|
# @return [UNIXSocket] new connection
|
585
522
|
def accept
|
586
523
|
Polyphony.backend_accept(self, UNIXSocket)
|
587
524
|
end
|
588
525
|
|
589
|
-
# call-seq:
|
590
|
-
# socket.accept_loop { |conn| ... }
|
591
|
-
#
|
592
526
|
# Accepts incoming connections in an infinite loop.
|
593
527
|
#
|
594
|
-
# @yield [UNIXSocket]
|
595
|
-
# @return [
|
528
|
+
# @yield [UNIXSocket] accepted socket
|
529
|
+
# @return [nil]
|
596
530
|
def accept_loop(&block)
|
597
531
|
Polyphony.backend_accept_loop(self, UNIXSocket, &block)
|
598
532
|
end
|
@@ -602,13 +536,7 @@ end
|
|
602
536
|
class ::UNIXSocket < ::BasicSocket
|
603
537
|
# @!visibility private
|
604
538
|
alias_method :orig_read, :read
|
605
|
-
|
606
|
-
# call-seq:
|
607
|
-
# socket.read -> string
|
608
|
-
# socket.read(maxlen) -> string
|
609
|
-
# socket.read(maxlen, buf) -> buf
|
610
|
-
# socket.read(maxlen, buf, buf_pos) -> buf
|
611
|
-
#
|
539
|
+
|
612
540
|
# Reads from the socket. If `maxlen` is given, reads up to `maxlen` bytes from
|
613
541
|
# the socket, otherwise reads to `EOF`. If `buf` is given, it is used as the
|
614
542
|
# buffer to read into, otherwise a new string is allocated. If `buf_pos` is
|
@@ -640,11 +568,6 @@ class ::UNIXSocket < ::BasicSocket
|
|
640
568
|
buf
|
641
569
|
end
|
642
570
|
|
643
|
-
# call-seq:
|
644
|
-
# socket.recv(maxlen) -> string
|
645
|
-
# socket.recv(maxlen, flags) -> string
|
646
|
-
# socket.recv(maxlen, flags, buf) -> buf
|
647
|
-
#
|
648
571
|
# Receives up to `maxlen` bytes from the socket. If `outbuf` is given, it is
|
649
572
|
# used as the buffer to receive into, otherwise a new string is allocated and
|
650
573
|
# used as buffer.
|
@@ -660,27 +583,17 @@ class ::UNIXSocket < ::BasicSocket
|
|
660
583
|
Polyphony.backend_recv(self, outbuf || +'', maxlen, 0)
|
661
584
|
end
|
662
585
|
|
663
|
-
# call-seq:
|
664
|
-
# socket.recv_loop { |data| ... }
|
665
|
-
# socket.recv_loop(maxlen) { |data| ... }
|
666
|
-
# socket.read_loop { |data| ... }
|
667
|
-
# socket.read_loop(maxlen) { |data| ... }
|
668
|
-
#
|
669
586
|
# Receives up to `maxlen` bytes at a time in an infinite loop. Read buffers
|
670
587
|
# will be passed to the given block.
|
671
588
|
#
|
672
589
|
# @param maxlen [Integer] maximum bytes to receive
|
673
|
-
# @yield [String]
|
674
|
-
# @return [
|
590
|
+
# @yield [String] received data
|
591
|
+
# @return [Socket] self
|
675
592
|
def recv_loop(maxlen = 8192, &block)
|
676
593
|
Polyphony.backend_recv_loop(self, maxlen, &block)
|
677
594
|
end
|
678
595
|
alias_method :read_loop, :recv_loop
|
679
596
|
|
680
|
-
# call-seq:
|
681
|
-
# socket.feed_loop(receiver, method)
|
682
|
-
# socket.feed_loop(receiver, method) { |result| ... }
|
683
|
-
#
|
684
597
|
# Receives data from the socket in an infinite loop, passing the data to the
|
685
598
|
# given receiver using the given method. If a block is given, the result of
|
686
599
|
# the method call to the receiver is passed to the block.
|
@@ -697,8 +610,7 @@ class ::UNIXSocket < ::BasicSocket
|
|
697
610
|
#
|
698
611
|
# @param receiver [any] receiver object
|
699
612
|
# @param method [Symbol] method to call
|
700
|
-
# @
|
701
|
-
# @return [void]
|
613
|
+
# @return [Socket] self
|
702
614
|
def feed_loop(receiver, method = :call, &block)
|
703
615
|
Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
|
704
616
|
end
|
@@ -729,12 +641,6 @@ class ::UNIXSocket < ::BasicSocket
|
|
729
641
|
Polyphony.backend_send(self, mesg, 0)
|
730
642
|
end
|
731
643
|
|
732
|
-
# call-seq:
|
733
|
-
# socket.readpartial(maxlen) -> string
|
734
|
-
# socket.readpartial(maxlen, buf) -> buf
|
735
|
-
# socket.readpartial(maxlen, buf, buf_pos) -> buf
|
736
|
-
# socket.readpartial(maxlen, buf, buf_pos, raise_on_eof) -> buf
|
737
|
-
#
|
738
644
|
# Reads up to `maxlen` from the socket. If `buf` is given, it is used as the
|
739
645
|
# buffer to read into, otherwise a new string is allocated. If `buf_pos` is
|
740
646
|
# given, reads into the given offset (in bytes) in the given buffer. If the
|
@@ -12,8 +12,6 @@ class ::Thread
|
|
12
12
|
|
13
13
|
# Initializes the thread.
|
14
14
|
# @param args [Array] arguments to pass to thread block
|
15
|
-
# @yield [any] thread block
|
16
|
-
# @return [void]
|
17
15
|
def initialize(*args, &block)
|
18
16
|
@join_wait_queue = []
|
19
17
|
@finalization_mutex = Mutex.new
|
@@ -24,22 +22,17 @@ class ::Thread
|
|
24
22
|
|
25
23
|
# Sets up the thread and its main fiber.
|
26
24
|
#
|
27
|
-
# @return [
|
25
|
+
# @return [Thread] self
|
28
26
|
def setup
|
29
27
|
@main_fiber = Fiber.current
|
30
28
|
@main_fiber.setup_main_fiber
|
31
29
|
setup_fiber_scheduling
|
30
|
+
self
|
32
31
|
end
|
33
32
|
|
34
33
|
# @!visibility private
|
35
34
|
alias_method :orig_join, :join
|
36
35
|
|
37
|
-
# call-seq:
|
38
|
-
# thread.join -> result
|
39
|
-
# thread.join(timeout) -> result
|
40
|
-
# thread.await -> result
|
41
|
-
# thread.await(timeout) -> result
|
42
|
-
#
|
43
36
|
# Waits for the thread to terminate and returns its return value. If the
|
44
37
|
# thread terminated with an uncaught exception, it is propagated to the
|
45
38
|
# waiting fiber. If a timeout interval is specified, the thread will be
|
@@ -64,11 +57,6 @@ class ::Thread
|
|
64
57
|
# @!visibility private
|
65
58
|
alias_method :orig_raise, :raise
|
66
59
|
|
67
|
-
# call-seq:
|
68
|
-
# thread.raise
|
69
|
-
# thread.raise(exception_class)
|
70
|
-
# thread.raise(exception_instance)
|
71
|
-
#
|
72
60
|
# Raises an exception in the context of the thread. If no exception is given,
|
73
61
|
# a `RuntimeError` is raised.
|
74
62
|
#
|
@@ -136,7 +124,6 @@ class ::Thread
|
|
136
124
|
|
137
125
|
# Sets the idle handler for the thread's backend.
|
138
126
|
#
|
139
|
-
# @yield [] idle handler
|
140
127
|
# @return [Proc] idle handler
|
141
128
|
def on_idle(&block)
|
142
129
|
backend.idle_proc = block
|
@@ -146,7 +133,7 @@ class ::Thread
|
|
146
133
|
|
147
134
|
# Runs the thread's block, handling any uncaught exceptions.
|
148
135
|
#
|
149
|
-
# @return [
|
136
|
+
# @return [any] thread result value
|
150
137
|
def execute
|
151
138
|
# backend must be created in the context of the new thread, therefore it
|
152
139
|
# cannot be created in Thread#initialize
|
@@ -172,7 +159,6 @@ class ::Thread
|
|
172
159
|
# Finalizes the thread.
|
173
160
|
#
|
174
161
|
# @param result [any] thread's return value
|
175
|
-
# @return [void]
|
176
162
|
def finalize(result)
|
177
163
|
unless Fiber.current.children.empty?
|
178
164
|
Fiber.current.shutdown_all_children
|
@@ -188,7 +174,6 @@ class ::Thread
|
|
188
174
|
# Signals all fibers waiting for the thread to terminate.
|
189
175
|
#
|
190
176
|
# @param result [any] thread's return value
|
191
|
-
# @return [void]
|
192
177
|
def signal_waiters(result)
|
193
178
|
@join_wait_queue.each { |w| w.signal(result) }
|
194
179
|
end
|
@@ -13,7 +13,6 @@ module ::Timeout
|
|
13
13
|
# @param sec [Number] timeout period in seconds
|
14
14
|
# @param klass [Class] exception class
|
15
15
|
# @param message [String] exception message
|
16
|
-
# @yield [] code to run
|
17
16
|
# @return [any] block's return value
|
18
17
|
def self.timeout(sec, klass = Timeout::Error, message = 'execution expired', &block)
|
19
18
|
cancel_after(sec, with_exception: [klass, message], &block)
|
data/lib/polyphony/net.rb
CHANGED
@@ -4,16 +4,11 @@ require_relative './extensions/socket'
|
|
4
4
|
require_relative './extensions/openssl'
|
5
5
|
|
6
6
|
module Polyphony
|
7
|
-
|
7
|
+
|
8
8
|
# A more elegant networking API
|
9
9
|
module Net
|
10
10
|
class << self
|
11
11
|
|
12
|
-
# call-seq:
|
13
|
-
# Polyphony::Net.tcp_connect(host, port) -> TCPSocket
|
14
|
-
# Polyphony::Net.tcp_connect(host, port, secure: true) -> SSLSocket
|
15
|
-
# Polyphony::Net.tcp_connect(host, port, secure_context: ctx) -> SSLSocket
|
16
|
-
#
|
17
12
|
# Create a TCP connection to the given host and port, returning the new
|
18
13
|
# socket. If `opts[:secure]` is true, or if an SSL context is given in
|
19
14
|
# `opts[:secure_context]`, a TLS handshake is performed, and an SSLSocket
|
@@ -21,7 +16,9 @@ module Polyphony
|
|
21
16
|
#
|
22
17
|
# @param host [String] hostname
|
23
18
|
# @param port [Integer] port number
|
24
|
-
# @param opts [Hash]
|
19
|
+
# @param opts [Hash] options to use
|
20
|
+
# @option opts [boolean] :secure use a default context as SSL context, return `SSLSocket` instance
|
21
|
+
# @option opts [OpenSSL::SSL::SSLContext] :secure_context SSL context to use, return `SSLSocket` instance
|
25
22
|
# @return [TCPSocket, SSLSocket] connected socket
|
26
23
|
def tcp_connect(host, port, opts = {})
|
27
24
|
socket = TCPSocket.new(host, port)
|
@@ -57,10 +54,9 @@ module Polyphony
|
|
57
54
|
# context will select the first protocol from the list given by the client
|
58
55
|
# that appears in the list of given protocols, according to the specified
|
59
56
|
# order.
|
60
|
-
#
|
57
|
+
#
|
61
58
|
# @param context [SSLContext] SSL context
|
62
59
|
# @param protocols [Array] array of supported protocols
|
63
|
-
# @return [void]
|
64
60
|
def setup_alpn(context, protocols)
|
65
61
|
context.alpn_protocols = protocols
|
66
62
|
context.alpn_select_cb = lambda do |peer_protocols|
|
data/lib/polyphony/version.rb
CHANGED
data/lib/polyphony.rb
CHANGED
@@ -43,11 +43,7 @@ module Polyphony
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
#
|
47
|
-
# Polyphony.watch_process(cmd)
|
48
|
-
# Polyphony.watch_process { sleep 1 }
|
49
|
-
#
|
50
|
-
# Lubnches a process using either a command or a block for a forked process,
|
46
|
+
# Launches a process using either a command or a block for a forked process,
|
51
47
|
# waiting for the child process to terminate.
|
52
48
|
def watch_process(cmd = nil, &block)
|
53
49
|
Polyphony::Process.watch(cmd, &block)
|
@@ -136,7 +132,7 @@ module Polyphony
|
|
136
132
|
$VERBOSE = nil
|
137
133
|
Object.const_set(:Queue, Polyphony::Queue)
|
138
134
|
Object.const_set(:Mutex, Polyphony::Mutex)
|
139
|
-
|
135
|
+
|
140
136
|
require 'monitor'
|
141
137
|
Object.const_set(:Monitor, Polyphony::Mutex)
|
142
138
|
|