Class: Mu::Pcap::IOPair

Inherits:
Object
  • Object
show all
Defined in:
lib/diy/parser/mu/pcap/io_pair.rb

Overview

For emulating of a pair of connected sockets. Bytes written with #write to one side are returned by a subsequent #read on the other side.

Use Pair.stream_pair to get a pair with stream semantics. Use Pair.packet_pair to get a pair with packet semantics.

Direct Known Subclasses

Packet, Stream

Defined Under Namespace

Classes: Packet, Stream

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIOPair

Returns a new instance of IOPair.

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/diy/parser/mu/pcap/io_pair.rb', line 18

def initialize
    raise NotImplementedError
end

Instance Attribute Details

#otherObject

Returns the value of attribute other.



16
17
18
# File 'lib/diy/parser/mu/pcap/io_pair.rb', line 16

def other
  @other
end

#read_queueObject (readonly)

Returns the value of attribute read_queue.



15
16
17
# File 'lib/diy/parser/mu/pcap/io_pair.rb', line 15

def read_queue
  @read_queue
end

Class Method Details

.packet_pairObject



30
31
32
33
34
35
36
# File 'lib/diy/parser/mu/pcap/io_pair.rb', line 30

def self.packet_pair
    io1 = Packet.new
    io2 = Packet.new
    io1.other = io2
    io2.other = io1
    return io1, io2
end

.stream_pairObject



22
23
24
25
26
27
28
# File 'lib/diy/parser/mu/pcap/io_pair.rb', line 22

def self.stream_pair
    io1 = Stream.new
    io2 = Stream.new
    io1.other = io2
    io2.other = io1
    return io1, io2
end

Instance Method Details

#write(bytes) ⇒ Object



38
39
40
41
# File 'lib/diy/parser/mu/pcap/io_pair.rb', line 38

def write bytes
    @other.read_queue << bytes
    bytes.size
end