Class: Isomorfeus::Speednode::AttachSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/isomorfeus/speednode/attach_socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#socketObject (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

#runObject



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

#stopObject



39
40
41
42
# File 'lib/isomorfeus/speednode/attach_socket.rb', line 39

def stop
  @running = false
  @socket.close
end