Class: Net::InternetMessageIO
- Inherits:
-
BufferedIO
- Object
- BufferedIO
- Net::InternetMessageIO
- Defined in:
- lib/net/protocol.rb
Overview
Instance Attribute Summary
Attributes inherited from BufferedIO
#continue_timeout, #debug_output, #io, #read_timeout, #write_timeout
Instance Method Summary collapse
-
#each_list_item ⇒ Object
library private (cannot handle 'break').
-
#each_message_chunk ⇒ Object
Read.
-
#initialize ⇒ InternetMessageIO
constructor
A new instance of InternetMessageIO.
-
#write_message(src) ⇒ Object
Write.
- #write_message_0(src) ⇒ Object
- #write_message_by_block(&block) ⇒ Object
Methods inherited from BufferedIO
#close, #closed?, #eof?, #inspect, #read, #read_all, #readline, #readuntil, #write, #writeline
Constructor Details
#initialize ⇒ InternetMessageIO
Returns a new instance of InternetMessageIO.
417 418 419 420 |
# File 'lib/net/protocol.rb', line 417 def initialize(*, **) super @wbuf = nil end |
Instance Method Details
#each_list_item ⇒ Object
library private (cannot handle 'break')
439 440 441 442 443 |
# File 'lib/net/protocol.rb', line 439 def each_list_item while (str = readuntil("\r\n")) != ".\r\n" yield str.chop end end |
#each_message_chunk ⇒ Object
Read
426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/net/protocol.rb', line 426 def LOG 'reading message...' LOG_off() read_bytes = 0 while (line = readuntil("\r\n")) != ".\r\n" read_bytes += line.size yield line.delete_prefix('.') end LOG_on() LOG "read message (#{read_bytes} bytes)" end |
#write_message(src) ⇒ Object
Write
457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/net/protocol.rb', line 457 def (src) LOG "writing message from #{src.class}" LOG_off() len = writing { using_each_crlf_line { src } } LOG_on() LOG "wrote #{len} bytes" len end |
#write_message_0(src) ⇒ Object
445 446 447 448 449 450 451 |
# File 'lib/net/protocol.rb', line 445 def (src) prev = @written_bytes each_crlf_line(src) do |line| write0 dot_stuff(line) end @written_bytes - prev end |
#write_message_by_block(&block) ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/net/protocol.rb', line 470 def (&block) LOG 'writing message from block' LOG_off() len = writing { using_each_crlf_line { begin block.call(WriteAdapter.new(self.method(:write_message_0))) rescue LocalJumpError # allow `break' from writer block end } } LOG_on() LOG "wrote #{len} bytes" len end |