Class: Nodule::UnixSocket

Inherits:
Tempfile show all
Defined in:
lib/nodule/unixsocket.rb

Instance Attribute Summary collapse

Attributes inherited from Tempfile

#file

Attributes inherited from Base

#prefix, #read_count, #readers, #running, #topology

Instance Method Summary collapse

Methods inherited from Tempfile

#to_s, #touch

Methods inherited from Base

#add_reader, #add_readers, #clear!, #done?, #join_topology!, #output, #output!, #output?, #read_until, #require_read_count, #run, #run_readers, #stop!, #verbose, #wait, #wait_with_backoff

Constructor Details

#initialize(opts = {}) ⇒ UnixSocket

Returns a new instance of UnixSocket.



8
9
10
11
12
13
14
# File 'lib/nodule/unixsocket.rb', line 8

def initialize(opts={})
  super(opts)
  @family = opts[:family] || :DGRAM
  @socket = Socket.new(:UNIX, @family, 0)
  @address = Addrinfo.unix(@file)
  @connected = false
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



6
7
8
# File 'lib/nodule/unixsocket.rb', line 6

def address
  @address
end

#connectedObject (readonly)

Returns the value of attribute connected.



6
7
8
# File 'lib/nodule/unixsocket.rb', line 6

def connected
  @connected
end

#familyObject (readonly)

Returns the value of attribute family.



6
7
8
# File 'lib/nodule/unixsocket.rb', line 6

def family
  @family
end

Instance Method Details

#send(data) ⇒ Object

sock1 = Nodule::UnixSocket.new



19
20
21
22
23
24
25
26
27
28
# File 'lib/nodule/unixsocket.rb', line 19

def send(data)
  @socket.connect(@address) unless @connected
  @connected = true

  if @family == :DGRAM
    @socket.sendmsg(data, 0)
  else
    @socket.send(data, 0)
  end
end

#stopObject



30
31
32
33
# File 'lib/nodule/unixsocket.rb', line 30

def stop
  @socket.close
  super
end