class Mu::Pcap::IOWrapper

Constants

MAX_RECEIVE_SIZE

Impose upper limit to protect against memory exhaustion.

Attributes

ios[R]
state[R]
unread[R]

Public Class Methods

new(ios, reader) click to toggle source
# File lib/woolen_common/pcap/mu/pcap/io_wrapper.rb, line 12
def initialize ios, reader
    @ios = ios
    @reader = reader
    # parse state for reader
    @state = {}
    # read off of underlying io but not yet processed by @reader
    @unread = ""
end

Public Instance Methods

close() click to toggle source
# File lib/woolen_common/pcap/mu/pcap/io_wrapper.rb, line 70
def close
    @ios.close
end
open() { || ... } click to toggle source
# File lib/woolen_common/pcap/mu/pcap/io_wrapper.rb, line 58
def open
    if block_given?
        @ios.open { yield }
    else
        @ios.open
    end
end
open?() click to toggle source
# File lib/woolen_common/pcap/mu/pcap/io_wrapper.rb, line 66
def open?
    @ios.open?
end
read() click to toggle source

Returns next higher level protocol message.

# File lib/woolen_common/pcap/mu/pcap/io_wrapper.rb, line 25
def read
    until message = @reader.read_message!(@unread, @state)
        bytes = @ios.read
        if bytes and not bytes.empty?
            @unread << bytes
        else
            return nil
        end
        if @unread.size > MAX_RECEIVE_SIZE
            raise "Maximum message size (#{MAX_RECEIVE_SIZE}) exceeded"
        end
    end

    return message
end
record_write(bytes) click to toggle source

Parser may need to see requests to understand responses.

# File lib/woolen_common/pcap/mu/pcap/io_wrapper.rb, line 42
def record_write bytes
    @reader.record_write bytes, @state
end
write(bytes, *args) click to toggle source
# File lib/woolen_common/pcap/mu/pcap/io_wrapper.rb, line 46
def write bytes, *args
    w = @ios.write bytes, *args
    record_write bytes
    w
end
write_to(bytes, *args) click to toggle source
# File lib/woolen_common/pcap/mu/pcap/io_wrapper.rb, line 52
def write_to bytes, *args
    w = @ios.write_to bytes, *args
    record_write bytes
    w
end