class Isomorfeus::Speednode::AttachSocket

Attributes

socket[R]

Public Class Methods

new(socket_path, block) click to toggle source
# File lib/isomorfeus/speednode/attach_socket.rb, line 9
def initialize(socket_path, block)
  @socket_path = socket_path
  @run_block = block
end

Public Instance Methods

run() click to toggle source
# 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
    sleep 0.005
    ret = begin
            IO.select([@socket], nil, nil, 1) || next
          rescue Errno::EBADF
          end
  end
end
stop() click to toggle source
# File lib/isomorfeus/speednode/attach_socket.rb, line 40
def stop
  @running = false
  @socket.close
end