Class: Net::InternetMessageIO
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
BufferedIO
|
|
Instance Chain:
self,
BufferedIO
|
|
Inherits: |
Net::BufferedIO
|
Defined in: | lib/net/protocol.rb |
Overview
internal use only
Constant Summary
BufferedIO
- Inherited
Class Method Summary
Instance Attribute Summary
BufferedIO
- Inherited
Instance Method Summary
-
#each_list_item
*library private* (cannot handle ‘break’).
-
#each_message_chunk
Read.
-
#write_message(src)
Write.
- #write_message_0(src)
- #write_message_by_block(&block)
- #buffer_filling(buf, src) private
- #dot_stuff(s) private
- #each_crlf_line(src) private
- #using_each_crlf_line private
BufferedIO
- Inherited
#<< | Alias for BufferedIO#write. |
#close, #inspect, #read, #read_all, #readline, #readuntil, #write, #writeline, #LOG, #LOG_off, #LOG_on, #rbuf_consume, #rbuf_fill, #write0, #writing |
Constructor Details
.new ⇒ InternetMessageIO
# File 'lib/net/protocol.rb', line 325
def initialize(*, **) super @wbuf = nil end
Instance Method Details
#buffer_filling(buf, src) (private)
[ GitHub ]# File 'lib/net/protocol.rb', line 421
def buffer_filling(buf, src) case src when String # for speeding up. 0.step(src.size - 1, 1024) do |i| buf << src[i, 1024] yield end when File # for speeding up. while s = src.read(1024) buf << s yield end else # generic reader src.each do |str| buf << str yield if buf.size > 1024 end yield unless buf.empty? end end
#dot_stuff(s) (private)
[ GitHub ]# File 'lib/net/protocol.rb', line 397
def dot_stuff(s) s.sub(/\A\./, '..') end
#each_crlf_line(src) (private)
[ GitHub ]# File 'lib/net/protocol.rb', line 413
def each_crlf_line(src) buffer_filling(@wbuf, src) do while line = @wbuf.slice!(/\A[^\r\n]*(?:\n|\r(?:\n|(?!\z)))/) yield line.chomp("\n") + "\r\n" end end end
#each_list_item
*library private* (cannot handle ‘break’)
# File 'lib/net/protocol.rb', line 347
def each_list_item while (str = readuntil("\r\n")) != ".\r\n" yield str.chop end end
#each_message_chunk
Read
#using_each_crlf_line (private)
[ GitHub ]# File 'lib/net/protocol.rb', line 401
def using_each_crlf_line @wbuf = ''.b yield if not @wbuf.empty? # unterminated last line write0 dot_stuff(@wbuf.chomp) + "\r\n" elsif @written_bytes == 0 # empty src write0 "\r\n" end write0 ".\r\n" @wbuf = nil end
#write_message(src)
Write
# File 'lib/net/protocol.rb', line 365
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)
[ GitHub ]# File 'lib/net/protocol.rb', line 353
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)
[ GitHub ]# File 'lib/net/protocol.rb', line 378
def (&block) LOG 'writing message from block' LOG_off() len = writing { using_each_crlf_line { begin block.call(WriteAdapter.new(self, : )) rescue LocalJumpError # allow `break' from writer block end } } LOG_on() LOG "wrote #{len} bytes" len end