Class: XenStore::Transport::UnixSocketTransport

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

Overview

A Transport implementation which communicates with XenStore over a UNIX socket.

Instance Method Summary collapse

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

#closeObject



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