net-protocol 0.3.0 → 0.4.0
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/lib/net/protocol.rb +38 -23
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f819b1703cd2631eb0c7d41fff4ca6a74dff9e88d740c5bfd93980ba2e8b3873
|
|
4
|
+
data.tar.gz: c4ac03ea98b451e2ddc9f38b0ff6b73d4341a6b09d01c923683ae354d9adcbb2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f9f88f0b96250c90ced8c159a4941efb190bb1de64b9bbed3cb393b295aaf9a60dc607038fcfcf7a2d39d983aa27a2ca9b61f07e04c8d7f8750c700dcb76ceda
|
|
7
|
+
data.tar.gz: 395718803914996cc958d50d30a56d1cb3856be7c940961059e19316476f5ae476366b42e38cd348508bc1850e13f51965e5a4631524683c63e252ff1088d571
|
data/lib/net/protocol.rb
CHANGED
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
|
|
22
22
|
require 'socket'
|
|
23
23
|
require 'timeout'
|
|
24
|
-
require 'io/wait'
|
|
24
|
+
require 'io/wait' if RUBY_VERSION < '3.2'
|
|
25
25
|
|
|
26
26
|
module Net # :nodoc:
|
|
27
27
|
|
|
28
28
|
class Protocol #:nodoc: internal use only
|
|
29
|
-
VERSION = "0.
|
|
29
|
+
VERSION = "0.4.0"
|
|
30
30
|
|
|
31
31
|
private
|
|
32
32
|
def Protocol.protocol_param(name, val)
|
|
@@ -189,6 +189,7 @@ module Net # :nodoc:
|
|
|
189
189
|
public
|
|
190
190
|
|
|
191
191
|
def read(len, dest = ''.b, ignore_eof = false)
|
|
192
|
+
raise ArgumentError, "negative length #{len} given" if len < 0
|
|
192
193
|
LOG "reading #{len} bytes..."
|
|
193
194
|
read_bytes = 0
|
|
194
195
|
begin
|
|
@@ -356,9 +357,9 @@ module Net # :nodoc:
|
|
|
356
357
|
@debug_output << '<- ' if @debug_output
|
|
357
358
|
yield
|
|
358
359
|
@debug_output << "\n" if @debug_output
|
|
359
|
-
|
|
360
|
+
@written_bytes
|
|
361
|
+
ensure
|
|
360
362
|
@written_bytes = nil
|
|
361
|
-
bytes
|
|
362
363
|
end
|
|
363
364
|
|
|
364
365
|
def write0(*strs)
|
|
@@ -384,6 +385,9 @@ module Net # :nodoc:
|
|
|
384
385
|
# next string
|
|
385
386
|
end
|
|
386
387
|
# continue looping
|
|
388
|
+
when :wait_readable
|
|
389
|
+
(io = @io.to_io).wait_readable(@write_timeout) or raise Net::WriteTimeout.new(io)
|
|
390
|
+
# continue looping
|
|
387
391
|
when :wait_writable
|
|
388
392
|
(io = @io.to_io).wait_writable(@write_timeout) or raise Net::WriteTimeout.new(io)
|
|
389
393
|
# continue looping
|
|
@@ -426,12 +430,15 @@ module Net # :nodoc:
|
|
|
426
430
|
def each_message_chunk
|
|
427
431
|
LOG 'reading message...'
|
|
428
432
|
LOG_off()
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
+
begin
|
|
434
|
+
read_bytes = 0
|
|
435
|
+
while (line = readuntil("\r\n")) != ".\r\n"
|
|
436
|
+
read_bytes += line.size
|
|
437
|
+
yield line.delete_prefix('.')
|
|
438
|
+
end
|
|
439
|
+
ensure
|
|
440
|
+
LOG_on()
|
|
433
441
|
end
|
|
434
|
-
LOG_on()
|
|
435
442
|
LOG "read message (#{read_bytes} bytes)"
|
|
436
443
|
end
|
|
437
444
|
|
|
@@ -457,12 +464,15 @@ module Net # :nodoc:
|
|
|
457
464
|
def write_message(src)
|
|
458
465
|
LOG "writing message from #{src.class}"
|
|
459
466
|
LOG_off()
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
467
|
+
begin
|
|
468
|
+
len = writing {
|
|
469
|
+
using_each_crlf_line {
|
|
470
|
+
write_message_0 src
|
|
471
|
+
}
|
|
463
472
|
}
|
|
464
|
-
|
|
465
|
-
|
|
473
|
+
ensure
|
|
474
|
+
LOG_on()
|
|
475
|
+
end
|
|
466
476
|
LOG "wrote #{len} bytes"
|
|
467
477
|
len
|
|
468
478
|
end
|
|
@@ -470,16 +480,19 @@ module Net # :nodoc:
|
|
|
470
480
|
def write_message_by_block(&block)
|
|
471
481
|
LOG 'writing message from block'
|
|
472
482
|
LOG_off()
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
483
|
+
begin
|
|
484
|
+
len = writing {
|
|
485
|
+
using_each_crlf_line {
|
|
486
|
+
begin
|
|
487
|
+
block.call(WriteAdapter.new(self.method(:write_message_0)))
|
|
488
|
+
rescue LocalJumpError
|
|
489
|
+
# allow `break' from writer block
|
|
490
|
+
end
|
|
491
|
+
}
|
|
480
492
|
}
|
|
481
|
-
|
|
482
|
-
|
|
493
|
+
ensure
|
|
494
|
+
LOG_on()
|
|
495
|
+
end
|
|
483
496
|
LOG "wrote #{len} bytes"
|
|
484
497
|
len
|
|
485
498
|
end
|
|
@@ -499,6 +512,8 @@ module Net # :nodoc:
|
|
|
499
512
|
write0 "\r\n"
|
|
500
513
|
end
|
|
501
514
|
write0 ".\r\n"
|
|
515
|
+
nil
|
|
516
|
+
ensure
|
|
502
517
|
@wbuf = nil
|
|
503
518
|
end
|
|
504
519
|
|