Class: XenStore::Transport::UnixSocketTransport
- Inherits:
-
Object
- Object
- XenStore::Transport::UnixSocketTransport
- Defined in:
- lib/xsrb/transport.rb
Overview
A Transport implementation which communicates with XenStore over a UNIX socket.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path = nil) ⇒ UnixSocketTransport
constructor
A new instance of UnixSocketTransport.
- #recv(size) ⇒ Object
- #send(data) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ UnixSocketTransport
Returns a new instance of UnixSocketTransport.
44 45 46 47 48 49 50 |
# File 'lib/xsrb/transport.rb', line 44 def initialize(path = nil) path ||= XenStore::Utils.unix_socket_path @sock = UNIXSocket.new path # Ensure the socket is closed when this object is garbage collected ObjectSpace.define_finalizer(self, proc { @sock.close }) end |
Instance Method Details
#close ⇒ Object
65 66 67 |
# File 'lib/xsrb/transport.rb', line 65 def close @sock.close end |
#recv(size) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/xsrb/transport.rb', line 56 def recv(size) chunks = [] while size chunks << @sock.read(size) size -= chunks[-1].length end chunks.join '' end |
#send(data) ⇒ Object
52 53 54 |
# File 'lib/xsrb/transport.rb', line 52 def send(data) @sock.write(data) end |