Class: Net::InternetMessageIO

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

Overview

:nodoc: internal use only

Constant Summary

Instance Attribute Summary

Attributes inherited from BufferedIO

#debug_output, #io, #read_timeout

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from BufferedIO

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

Constructor Details

- (InternetMessageIO) initialize(io)



215
216
217
218
# File 'lib/net/protocol.rb', line 215

def initialize(io)
  super
  @wbuf = nil
end

Class Method Details

+ (Object) old_open(addr, port, open_timeout = nil, read_timeout = nil, debug_output = nil)



205
206
207
208
209
210
211
212
213
# File 'lib/net/protocol.rb', line 205

def InternetMessageIO.old_open(addr, port,
    open_timeout = nil, read_timeout = nil, debug_output = nil)
  debug_output << "opening connection to #{addr}...\n" if debug_output
  s = timeout(open_timeout) { TCPsocket.new(addr, port) }
  io = new(s)
  io.read_timeout = read_timeout
  io.debug_output = debug_output
  io
end

Instance Method Details

- (Object) each_list_item

*library private* (cannot handle 'break')



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

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

- (Object) each_message_chunk

Read



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/net/protocol.rb', line 224

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

- (Object) write_message(src)

Write



255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/net/protocol.rb', line 255

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

- (Object) write_message_0(src)



243
244
245
246
247
248
249
# File 'lib/net/protocol.rb', line 243

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

- (Object) write_message_by_block(&block)



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/net/protocol.rb', line 268

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