Class: XenStore::Connection::PacketConnection
- Inherits:
-
Object
- Object
- XenStore::Connection::PacketConnection
- Defined in:
- lib/xsrb/connection.rb
Overview
Generic class which implements a connection which send Packets to a XenStore daemon.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(transport) ⇒ PacketConnection
constructor
A new instance of PacketConnection.
-
#recv ⇒ Packet
Receive a
Packetfrom XenStored. -
#send(pkt) ⇒ Object
Serialize a
Packetand send over the wire to XenStored.
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
#recv ⇒ Packet
Receive a Packet from XenStored
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
16 17 18 19 |
# File 'lib/xsrb/connection.rb', line 16 def send(pkt) data = pkt.pack @transport.send data end |