Class: Net::InternetMessageIO

Inherits:
BufferedIO show all
Defined in:
lib/net/protocol.rb

Overview

:nodoc: internal use only

Instance Attribute Summary

Attributes inherited from BufferedIO

#continue_timeout, #debug_output, #io, #read_timeout

Instance Method Summary collapse

Methods inherited from BufferedIO

#close, #closed?, #eof?, #inspect, #read, #read_all, #readline, #readuntil, #write, #writeline

Constructor Details

#initialize(io) ⇒ InternetMessageIO

Returns a new instance of InternetMessageIO.



239
240
241
242
# File 'lib/net/protocol.rb', line 239

def initialize(io)
  super
  @wbuf = nil
end

Instance Method Details

#each_list_itemObject

*library private* (cannot handle ‘break’)



261
262
263
264
265
# File 'lib/net/protocol.rb', line 261

def each_list_item
  while (str = readuntil("\r\n")) != ".\r\n"
    yield str.chop
  end
end

#each_message_chunkObject

Read



248
249
250
251
252
253
254
255
256
257
258
# File 'lib/net/protocol.rb', line 248

def each_message_chunk
  LOG 'reading message...'
  LOG_off()
  read_bytes = 0
  while (line = readuntil("\r\n")) != ".\r\n"
    read_bytes += line.size
    yield line.sub(/\A\./, '')
  end
  LOG_on()
  LOG "read message (#{read_bytes} bytes)"
end

#write_message(src) ⇒ Object

Write



279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/net/protocol.rb', line 279

def write_message(src)
  LOG "writing message from #{src.class}"
  LOG_off()
  len = writing {
    using_each_crlf_line {
      write_message_0 src
    }
  }
  LOG_on()
  LOG "wrote #{len} bytes"
  len
end

#write_message_0(src) ⇒ Object



267
268
269
270
271
272
273
# File 'lib/net/protocol.rb', line 267

def write_message_0(src)
  prev = @written_bytes
  each_crlf_line(src) do |line|
    write0 line.sub(/\A\./, '..')
  end
  @written_bytes - prev
end

#write_message_by_block(&block) ⇒ Object



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/net/protocol.rb', line 292

def write_message_by_block(&block)
  LOG 'writing message from block'
  LOG_off()
  len = writing {
    using_each_crlf_line {
      begin
        block.call(WriteAdapter.new(self, :write_message_0))
      rescue LocalJumpError
        # allow `break' from writer block
      end
    }
  }
  LOG_on()
  LOG "wrote #{len} bytes"
  len
end