polyphony 0.99.4 → 0.99.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -0
  3. data/examples/pipes/gzip_http_server.rb +2 -2
  4. data/examples/pipes/http_server.rb +1 -1
  5. data/examples/pipes/tcp_proxy.rb +1 -1
  6. data/ext/polyphony/backend_common.c +4 -4
  7. data/ext/polyphony/backend_io_uring.c +8 -8
  8. data/ext/polyphony/backend_libev.c +5 -5
  9. data/ext/polyphony/fiber.c +32 -41
  10. data/ext/polyphony/io_extensions.c +50 -37
  11. data/ext/polyphony/pipe.c +6 -18
  12. data/ext/polyphony/polyphony.c +63 -133
  13. data/ext/polyphony/queue.c +25 -63
  14. data/ext/polyphony/thread.c +3 -12
  15. data/lib/polyphony/adapters/process.rb +1 -2
  16. data/lib/polyphony/adapters/sequel.rb +2 -2
  17. data/lib/polyphony/core/debug.rb +1 -1
  18. data/lib/polyphony/core/exceptions.rb +1 -1
  19. data/lib/polyphony/core/global_api.rb +24 -38
  20. data/lib/polyphony/core/resource_pool.rb +7 -8
  21. data/lib/polyphony/core/sync.rb +1 -2
  22. data/lib/polyphony/core/thread_pool.rb +2 -5
  23. data/lib/polyphony/core/throttler.rb +1 -5
  24. data/lib/polyphony/core/timer.rb +24 -25
  25. data/lib/polyphony/extensions/fiber.rb +507 -540
  26. data/lib/polyphony/extensions/io.rb +3 -12
  27. data/lib/polyphony/extensions/openssl.rb +2 -23
  28. data/lib/polyphony/extensions/pipe.rb +4 -15
  29. data/lib/polyphony/extensions/socket.rb +15 -109
  30. data/lib/polyphony/extensions/thread.rb +0 -13
  31. data/lib/polyphony/extensions/timeout.rb +0 -1
  32. data/lib/polyphony/net.rb +5 -8
  33. data/lib/polyphony/version.rb +1 -1
  34. data/lib/polyphony.rb +2 -6
  35. data/test/test_io.rb +221 -221
  36. data/test/test_socket.rb +3 -3
  37. data/test/test_trace.rb +2 -2
  38. metadata +1 -1
@@ -108,7 +108,7 @@ class ::IO
108
108
  def double_splice(src, dest)
109
109
  Polyphony.backend_double_splice(src, dest)
110
110
  end
111
-
111
+
112
112
  # Tees data from the source to the desination.
113
113
  #
114
114
  # @param src [IO, Polyphony::Pipe] source to tee from
@@ -232,7 +232,7 @@ class ::IO
232
232
  Polyphony.backend_write(self, str)
233
233
  self
234
234
  end
235
-
235
+
236
236
  # @!visibility private
237
237
  alias_method :orig_gets, :gets
238
238
 
@@ -350,24 +350,16 @@ class ::IO
350
350
  buf ? readpartial(maxlen, buf) : readpartial(maxlen)
351
351
  end
352
352
 
353
- # call-seq:
354
- # io.read_loop { |data| ... }
355
- # io.read_loop(maxlen) { |data| ... }
356
- #
357
353
  # Reads up to `maxlen` bytes at a time in an infinite loop. Read data
358
354
  # will be passed to the given block.
359
355
  #
360
356
  # @param maxlen [Integer] maximum bytes to receive
361
- # @yield [String] handler block
357
+ # @yield [String] read data
362
358
  # @return [void]
363
359
  def read_loop(maxlen = 8192, &block)
364
360
  Polyphony.backend_read_loop(self, maxlen, &block)
365
361
  end
366
362
 
367
- # call-seq:
368
- # io.feed_loop(receiver, method)
369
- # io.feed_loop(receiver, method) { |result| ... }
370
- #
371
363
  # Receives data from the io in an infinite loop, passing the data to the given
372
364
  # receiver using the given method. If a block is given, the result of the
373
365
  # method call to the receiver is passed to the block.
@@ -384,7 +376,6 @@ class ::IO
384
376
  #
385
377
  # @param receiver [any] receiver object
386
378
  # @param method [Symbol] method to call
387
- # @yield [any] block to handle result of method call to receiver
388
379
  # @return [void]
389
380
  def feed_loop(receiver, method = :call, &block)
390
381
  Polyphony.backend_feed_loop(self, receiver, method, &block)
@@ -89,12 +89,6 @@ class ::OpenSSL::SSL::SSLSocket
89
89
  # @!visibility private
90
90
  alias_method :orig_read, :read
91
91
 
92
- # call-seq:
93
- # socket.read -> string
94
- # socket.read(maxlen) -> string
95
- # socket.read(maxlen, buf) -> buf
96
- # socket.read(maxlen, buf, buf_pos) -> buf
97
- #
98
92
  # Reads from the socket. If `maxlen` is given, reads up to `maxlen` bytes from
99
93
  # the socket, otherwise reads to `EOF`. If `buf` is given, it is used as the
100
94
  # buffer to read into, otherwise a new string is allocated. If `buf_pos` is
@@ -123,12 +117,6 @@ class ::OpenSSL::SSL::SSLSocket
123
117
  buf
124
118
  end
125
119
 
126
- # call-seq:
127
- # socket.readpartial(maxlen) -> string
128
- # socket.readpartial(maxlen, buf) -> buf
129
- # socket.readpartial(maxlen, buf, buf_pos) -> buf
130
- # socket.readpartial(maxlen, buf, buf_pos, raise_on_eof) -> buf
131
- #
132
120
  # Reads up to `maxlen` from the socket. If `buf` is given, it is used as the
133
121
  # buffer to read into, otherwise a new string is allocated. If `buf_pos` is
134
122
  # given, reads into the given offset (in bytes) in the given buffer. If the
@@ -162,17 +150,11 @@ class ::OpenSSL::SSL::SSLSocket
162
150
  result
163
151
  end
164
152
 
165
- # call-seq:
166
- # socket.recv_loop { |data| ... }
167
- # socket.recv_loop(maxlen) { |data| ... }
168
- # socket.read_loop { |data| ... }
169
- # socket.read_loop(maxlen) { |data| ... }
170
- #
171
153
  # Receives up to `maxlen` bytes at a time in an infinite loop. Read buffers
172
154
  # will be passed to the given block.
173
155
  #
174
156
  # @param maxlen [Integer] maximum bytes to receive
175
- # @yield [String] handler block
157
+ # @yield [String] read data
176
158
  # @return [void]
177
159
  def read_loop(maxlen = 8192)
178
160
  while (data = sysread(maxlen))
@@ -279,12 +261,9 @@ class ::OpenSSL::SSL::SSLServer
279
261
  orig_close
280
262
  end
281
263
 
282
- # call-seq:
283
- # socket.accept_loop { |conn| ... }
284
- #
285
264
  # Accepts incoming connections in an infinite loop.
286
265
  #
287
- # @yield [OpenSSL::SSL::SSLSocket] block receiving accepted sockets
266
+ # @yield [OpenSSL::SSL::SSLSocket] accepted socket
288
267
  # @return [void]
289
268
  def accept_loop(ignore_errors = true)
290
269
  loop do
@@ -72,7 +72,7 @@ class Polyphony::Pipe
72
72
  end
73
73
 
74
74
  # Writes to the pipe.
75
-
75
+
76
76
  # @param buf [String] data to write
77
77
  # @param args [any] further arguments to pass to Polyphony.backend_write
78
78
  # @return [Integer] bytes written
@@ -81,7 +81,7 @@ class Polyphony::Pipe
81
81
  end
82
82
 
83
83
  # Writes to the pipe.
84
-
84
+
85
85
  # @param buf [String] data to write
86
86
  # @return [Integer] bytes written
87
87
  def <<(buf)
@@ -89,12 +89,6 @@ class Polyphony::Pipe
89
89
  self
90
90
  end
91
91
 
92
- # call-seq:
93
- # pipe.gets(limit, chomp)
94
- # pipe.gets(separator, limit, chomp)
95
- #
96
- # Reads a single line from the pipe.
97
- #
98
92
  # @param sep [String] line separator
99
93
  # @param _limit [Integer, nil] line length limit
100
94
  # @param _chomp [boolean, nil] whether to chomp the read line
@@ -134,7 +128,7 @@ class Polyphony::Pipe
134
128
  LINEFEED_RE = /\n$/.freeze
135
129
 
136
130
  # Writes a line with line feed to the pipe.
137
- #
131
+ #
138
132
  # @param args [Array] zero or more lines
139
133
  def puts(*args)
140
134
  if args.empty?
@@ -183,16 +177,12 @@ class Polyphony::Pipe
183
177
  # Runs a read loop.
184
178
  #
185
179
  # @param maxlen [Integer] maximum bytes to read
186
- # @yield [String] read block
180
+ # @yield [String] read data
187
181
  # @return [void]
188
182
  def read_loop(maxlen = 8192, &block)
189
183
  Polyphony.backend_read_loop(self, maxlen, &block)
190
184
  end
191
185
 
192
- # call-seq:
193
- # pipe.feed_loop(receiver, method)
194
- # pipe.feed_loop(receiver, method) { |result| ... }
195
- #
196
186
  # Receives data from the pipe in an infinite loop, passing the data to the
197
187
  # given receiver using the given method. If a block is given, the result of
198
188
  # the method call to the receiver is passed to the block.
@@ -209,7 +199,6 @@ class Polyphony::Pipe
209
199
  #
210
200
  # @param receiver [any] receiver object
211
201
  # @param method [Symbol] method to call
212
- # @yield [any] block to handle result of method call to receiver
213
202
  # @return [void]
214
203
  def feed_loop(receiver, method = :call, &block)
215
204
  Polyphony.backend_feed_loop(self, receiver, method, &block)
@@ -28,18 +28,15 @@ 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] block receiving accepted sockets
39
+ # @yield [Socket] accepted socket
43
40
  # @return [void]
44
41
  def accept_loop(&block)
45
42
  Polyphony.backend_accept_loop(self, TCPSocket, &block)
@@ -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] handler block
111
+ # @yield [String] received data
132
112
  # @return [void]
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,7 +131,6 @@ class ::Socket < ::BasicSocket
155
131
  #
156
132
  # @param receiver [any] receiver object
157
133
  # @param method [Symbol] method to call
158
- # @yield [any] block to handle result of method call to receiver
159
134
  # @return [void]
160
135
  def feed_loop(receiver, method = :call, &block)
161
136
  Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
@@ -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] handler block
378
+ # @yield [String] received data
427
379
  # @return [void]
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
- # @yield [any] block to handle result of method call to receiver
454
401
  # @return [void]
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,19 +485,15 @@ 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] handler block
496
+ # @yield [TCPSocket] accepted socket
560
497
  # @return [void]
561
498
  def accept_loop(&block)
562
499
  Polyphony.backend_accept_loop(@io, TCPSocket, &block)
@@ -564,7 +501,7 @@ class ::TCPServer < ::TCPSocket
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,18 +517,15 @@ 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] handler block
528
+ # @yield [UNIXSocket] accepted socket
595
529
  # @return [void]
596
530
  def accept_loop(&block)
597
531
  Polyphony.backend_accept_loop(self, UNIXSocket, &block)
@@ -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] handler block
590
+ # @yield [String] received data
674
591
  # @return [void]
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,7 +610,6 @@ class ::UNIXSocket < ::BasicSocket
697
610
  #
698
611
  # @param receiver [any] receiver object
699
612
  # @param method [Symbol] method to call
700
- # @yield [any] block to handle result of method call to receiver
701
613
  # @return [void]
702
614
  def feed_loop(receiver, method = :call, &block)
703
615
  Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
@@ -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,7 +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
15
  # @return [void]
17
16
  def initialize(*args, &block)
18
17
  @join_wait_queue = []
@@ -34,12 +33,6 @@ class ::Thread
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
@@ -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] connection options
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,7 +54,7 @@ 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
60
  # @return [void]
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Polyphony
4
4
  # @!visibility private
5
- VERSION = '0.99.4'
5
+ VERSION = '0.99.5'
6
6
  end
data/lib/polyphony.rb CHANGED
@@ -43,11 +43,7 @@ module Polyphony
43
43
  end
44
44
  end
45
45
 
46
- # call-seq:
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