Class: SurroGate::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/surro-gate/proxy.rb

Instance Method Summary collapse

Constructor Details

#initializeProxy

Returns a new instance of Proxy.


6
7
8
9
# File 'lib/surro-gate/proxy.rb', line 6

def initialize
  @mutex = Mutex.new
  @selector = NIO::Selector.new
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/surro-gate/proxy.rb', line 26

def alive?
  !@thread.nil? && @thread.alive?
end

#push(left, right) ⇒ Object

Add new socket pair to the proxy

Raises:


12
13
14
15
16
17
18
19
20
# File 'lib/surro-gate/proxy.rb', line 12

def push(left, right)
  raise ProxyError, 'Socket already handled by the proxy' if includes?(left, right)

  @mutex.synchronize do
    proxy(left, right)
  end

  [left, right]
end

#waitObject


22
23
24
# File 'lib/surro-gate/proxy.rb', line 22

def wait
  @thread.join if alive?
end