Class: XenStore::Connection::PacketConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/xsrb/connection.rb

Overview

Generic class which implements a connection which send Packets to a XenStore daemon.

Direct Known Subclasses

UnixSocketConnection, XenBusConnection

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ PacketConnection

Returns a new instance of PacketConnection.



9
10
11
# File 'lib/xsrb/connection.rb', line 9

def initialize(transport)
  @transport = transport
end

Instance Method Details

#recvPacket

Receive a Packet from XenStored

Returns:

  • (Packet)

    The latest packet received from XenStore. Will block until either a packet is received or an error occurs.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/xsrb/connection.rb', line 26

def recv
  header = @transport.recv Packet.header_size

  op, rq_id, tx_id, len = header.unpack('IIII')
  if len > 4096
    raise XenStore::Exceptions::InvalidPayload,
          "Payload too large (#{l})"
  end

  body = @transport.recv len
  Packet.new(op, body, rq_id, tx_id)
end

#send(pkt) ⇒ Object

Serialize a Packet and send over the wire to XenStored

Parameters:

  • pkt (Packet)

    The Packet of data to send to xenstored.



16
17
18
19
# File 'lib/xsrb/connection.rb', line 16

def send(pkt)
  data = pkt.pack
  @transport.send data
end