Sha256: 49c651f5ac12afb5048a1a765f9bdc123662bf2279a2a5b7b143801ea700ffad

Contents?: true

Size: 1.63 KB

Versions: 17

Compression:

Stored size: 1.63 KB

Contents

# http://www.mudynamics.com
# http://labs.mudynamics.com
# http://www.pcapr.net

require 'mu/pcap/io_pair'
require 'mu/pcap/io_wrapper'

module Mu
class Pcap
class StreamPacketizer
    attr_reader :io_pair, :parser
    def initialize parser
        @parser = parser
        @key_to_idx = Hash.new do |hash,key|
            if hash.size >= 2
                raise ArgumentError, "Only two endpoints are allowed in a transaction"
            end
            hash[key] = hash.size
        end
        @sent_messages = [[], []].freeze
        @inner_pair = IOPair.stream_pair
        @io_pair = @inner_pair.map{|io| IOWrapper.new io, parser}.freeze
    end

    def msg_count key
        key = key.inspect
        widx       = @key_to_idx[key]
        messages = @sent_messages[widx]
        messages.size
    end

    def extra_bytes w_key
        w_key = w_key.inspect

        ridx       = @key_to_idx[w_key] ^ 1
        reader = @io_pair[ridx]
        incomplete =  reader.unread
        incomplete.empty? ? nil : incomplete.dup
    end

    def push key, bytes
        key = key.inspect
        widx       = @key_to_idx[key]
        writer     = @io_pair[widx]
        raw_writer = @inner_pair[widx]
        raw_writer.write bytes

        messages = @sent_messages[widx]

        ridx = widx ^ 1
        reader = @io_pair[ridx]
        while msg = reader.read
            messages << msg
            writer.record_write bytes
        end

        nil
    end

    def next_msg key
        key = key.inspect
        idx = @key_to_idx[key] 
        if m = @sent_messages[idx].shift
            return m.dup
        else
            nil
        end
    end
end
end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
DIY-pcap-0.4.1 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.3.8 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.3.6 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.3.5 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.3.4 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.3.3 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.3.2 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.3.1 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.3.0 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.2.8 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.2.7 lib/diy/parser/mu/pcap/stream_packetizer.rb
DIY-pcap-0.2.6 lib/diy/parser/mu/pcap/stream_packetizer.rb
pcapr-local-0.2.0 lib/mu/pcap/stream_packetizer.rb
pcapr-local-0.1.13 lib/mu/pcap/stream_packetizer.rb
pcapr-local-0.1.12 lib/mu/pcap/stream_packetizer.rb
pcapr-local-0.1.11 lib/mu/pcap/stream_packetizer.rb
pcapr-local-0.1.10 lib/mu/pcap/stream_packetizer.rb