Class: Speednode::AttachSocket
- Inherits:
-
Object
- Object
- Speednode::AttachSocket
- Defined in:
- lib/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.
8 9 10 11 |
# File 'lib/speednode/attach_socket.rb', line 8 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.
6 7 8 |
# File 'lib/speednode/attach_socket.rb', line 6 def socket @socket end |
Instance Method Details
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/speednode/attach_socket.rb', line 13 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
38 39 40 41 |
# File 'lib/speednode/attach_socket.rb', line 38 def stop @running = false @socket.close end |