class ServerEngine::SocketManager::Client

Public Class Methods

new(path) click to toggle source
# File lib/serverengine/socket_manager.rb, line 35
def initialize(path)
  @path = path
end

Public Instance Methods

listen(proto, bind, port) click to toggle source
# File lib/serverengine/socket_manager.rb, line 39
def listen(proto, bind, port)
  bind_ip = IPAddr.new(IPSocket.getaddress(bind))
  family = bind_ip.ipv6? ? Socket::AF_INET6 : Socket::AF_INET

  listen_method = case proto
                  when :tcp then :listen_tcp
                  when :udp then :listen_udp
                  else
                    raise ArgumentError, "unknown protocol: #{proto}"
                  end
  peer = connect_peer(@path)
  begin
    SocketManager.send_peer(peer, [Process.pid, listen_method, bind, port])
    res = SocketManager.recv_peer(peer)
    if res.is_a?(Exception)
      raise res
    else
      return send(:recv, family, proto, peer, res)
    end
  ensure
    peer.close
  end
end
listen_tcp(bind, port) click to toggle source
# File lib/serverengine/socket_manager.rb, line 63
def listen_tcp(bind, port)
  listen(:tcp, bind, port)
end
listen_udp(bind, port) click to toggle source
# File lib/serverengine/socket_manager.rb, line 67
def listen_udp(bind, port)
  listen(:udp, bind, port)
end