Class: Nodule::UnixSocket
- Defined in:
- lib/nodule/unixsocket.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#connected ⇒ Object
readonly
Returns the value of attribute connected.
-
#family ⇒ Object
readonly
Returns the value of attribute family.
Attributes inherited from Tempfile
Attributes inherited from Base
#prefix, #read_count, #readers, #running, #topology
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ UnixSocket
constructor
A new instance of UnixSocket.
-
#send(data) ⇒ Object
sock1 = Nodule::UnixSocket.new.
- #stop ⇒ Object
Methods inherited from Tempfile
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
#address ⇒ Object (readonly)
Returns the value of attribute address.
6 7 8 |
# File 'lib/nodule/unixsocket.rb', line 6 def address @address end |
#connected ⇒ Object (readonly)
Returns the value of attribute connected.
6 7 8 |
# File 'lib/nodule/unixsocket.rb', line 6 def connected @connected end |
#family ⇒ Object (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 |
#stop ⇒ Object
30 31 32 33 |
# File 'lib/nodule/unixsocket.rb', line 30 def stop @socket.close super end |