Class: ServerEngine::SocketManager::Client
- Inherits:
-
Object
- Object
- ServerEngine::SocketManager::Client
- Includes:
- ServerEngine::SocketManagerUnix::ClientModule, ServerEngine::SocketManagerWin::ClientModule
- Defined in:
- lib/serverengine/socket_manager.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ Client
constructor
A new instance of Client.
- #listen(proto, bind, port) ⇒ Object
- #listen_tcp(bind, port) ⇒ Object
- #listen_udp(bind, port) ⇒ Object
Constructor Details
#initialize(path) ⇒ Client
Returns a new instance of Client.
37 38 39 |
# File 'lib/serverengine/socket_manager.rb', line 37 def initialize(path) @path = path end |
Instance Method Details
#listen(proto, bind, port) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/serverengine/socket_manager.rb', line 41 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) ⇒ Object
65 66 67 |
# File 'lib/serverengine/socket_manager.rb', line 65 def listen_tcp(bind, port) listen(:tcp, bind, port) end |
#listen_udp(bind, port) ⇒ Object
69 70 71 |
# File 'lib/serverengine/socket_manager.rb', line 69 def listen_udp(bind, port) listen(:udp, bind, port) end |