Class: Gem::Net::InternetMessageIO

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

Overview

:nodoc: internal use only

Instance Attribute Summary

Attributes inherited from BufferedIO

#continue_timeout, #debug_output, #io, #read_timeout, #write_timeout

Instance Method Summary collapse

Methods inherited from BufferedIO

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

Constructor Details

#initializeInternetMessageIO

Returns a new instance of InternetMessageIO.



364
365
366
367
# File 'lib/rubygems/vendor/net-protocol/lib/net/protocol.rb', line 364

def initialize(*, **)
  super
  @wbuf = nil
end

Instance Method Details

#each_list_itemObject

*library private* (cannot handle ‘break’)



386
387
388
389
390
# File 'lib/rubygems/vendor/net-protocol/lib/net/protocol.rb', line 386

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

#each_message_chunkObject

Read



373
374
375
376
377
378
379
380
381
382
383
# File 'lib/rubygems/vendor/net-protocol/lib/net/protocol.rb', line 373

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.delete_prefix('.')
  end
  LOG_on()
  LOG "read message (#{read_bytes} bytes)"
end

#write_message(src) ⇒ Object

Write



404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/rubygems/vendor/net-protocol/lib/net/protocol.rb', line 404

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



392
393
394
395
396
397
398
# File 'lib/rubygems/vendor/net-protocol/lib/net/protocol.rb', line 392

def write_message_0(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



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/rubygems/vendor/net-protocol/lib/net/protocol.rb', line 417

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.method(:write_message_0)))
      rescue LocalJumpError
        # allow `break' from writer block
      end
    }
  }
  LOG_on()
  LOG "wrote #{len} bytes"
  len
end