Class: Isomorfeus::Speednode::AttachSocket
- Inherits:
-
Object
- Object
- Isomorfeus::Speednode::AttachSocket
- Defined in:
- lib/isomorfeus/speednode/attach_socket.rb
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize(socket_path, block) ⇒ AttachSocket
constructor
A new instance of AttachSocket.
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(socket_path, block) ⇒ AttachSocket
Returns a new instance of AttachSocket.
9 10 11 12 |
# File 'lib/isomorfeus/speednode/attach_socket.rb', line 9 def initialize(socket_path, block) @socket_path = socket_path @run_block = block end |
Instance Attribute Details
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
7 8 9 |
# File 'lib/isomorfeus/speednode/attach_socket.rb', line 7 def socket @socket end |
Instance Method Details
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/isomorfeus/speednode/attach_socket.rb', line 14 def run @running = true client = nil ret = nil @socket = UNIXServer.new(@socket_path) while @running do if ret begin client = @socket.accept_nonblock request = client.gets("\x04") result = @run_block.call(request) client.write result client.flush client.close rescue Errno::EAGAIN, Errno::EWOULDBLOCK end end ret = begin IO.select([@socket], nil, nil, nil) || next rescue Errno::EBADF end end end |
#stop ⇒ Object
39 40 41 42 |
# File 'lib/isomorfeus/speednode/attach_socket.rb', line 39 def stop @running = false @socket.close end |