Class: Tochka::UnixSocketChannel
- Defined in:
- lib/tochka/channel.rb
Constant Summary collapse
- SOCKPATH =
"/var/run/captured.sock"
Instance Method Summary collapse
-
#initialize(recv_handler, sock_path = SOCKPATH) ⇒ UnixSocketChannel
constructor
A new instance of UnixSocketChannel.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(recv_handler, sock_path = SOCKPATH) ⇒ UnixSocketChannel
Returns a new instance of UnixSocketChannel.
18 19 20 21 22 |
# File 'lib/tochka/channel.rb', line 18 def initialize recv_handler, sock_path=SOCKPATH @recv_handler = recv_handler @sock_path = sock_path || SOCKPATH @th = nil end |
Instance Method Details
#start ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/tochka/channel.rb', line 24 def start @th = Thread.new do Socket.unix_server_loop(@sock_path) do |sock, addr| data = sock.gets resp = @recv_handler.call(data) sock.write(resp+"\n") end end end |
#stop ⇒ Object
34 35 36 |
# File 'lib/tochka/channel.rb', line 34 def stop @th.kill end |