diff --git a/autopush_rs/__init__.py b/autopush_rs/__init__.py index a4224de8..5f59fbd9 100644 --- a/autopush_rs/__init__.py +++ b/autopush_rs/__init__.py @@ -27,8 +27,6 @@ def __init__(self, conf, queue): cfg.close_handshake_timeout = conf.close_handshake_timeout cfg.max_connections = conf.max_connections cfg.open_handshake_timeout = 5 - if not conf._resolve_hostname: - raise Exception("Must set resolve_hostname to True") cfg.host_ip = ffi_from_buffer(conf.hostname) cfg.router_ip = ffi_from_buffer(conf.router_hostname) cfg.router_port = conf.router_port diff --git a/autopush_rs/src/server/mod.rs b/autopush_rs/src/server/mod.rs index 4e097c44..09ee633c 100644 --- a/autopush_rs/src/server/mod.rs +++ b/autopush_rs/src/server/mod.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use std::ffi::CStr; use std::io; use std::mem; +use std::net::{IpAddr, ToSocketAddrs}; use std::panic; use std::path::PathBuf; use std::rc::Rc; @@ -91,6 +92,10 @@ pub struct ServerOptions { pub close_handshake_timeout: Option, } +fn resolve(host: &str) -> IpAddr { + (host, 0).to_socket_addrs().unwrap().next().unwrap().ip() +} + #[no_mangle] pub extern "C" fn autopush_server_new(opts: *const AutopushServerOptions, err: &mut AutopushError) @@ -246,7 +251,8 @@ impl Server { use hyper::server::Http; let handle = core.handle(); - let addr = format!("{}:{}", srv.opts.router_ip, srv.opts.router_port).parse().unwrap(); + let router_ip = resolve(&srv.opts.router_ip); + let addr = format!("{}:{}", router_ip, srv.opts.router_port).parse().unwrap(); let push_listener = TcpListener::bind(&addr, &handle).unwrap(); let proto = Http::new(); let push_srv = push_listener.incoming().for_each(move |(socket, addr)| { @@ -281,7 +287,8 @@ impl Server { handle: core.handle(), tx: tx, }); - let addr = format!("{}:{}", srv.opts.host_ip, srv.opts.port); + let host_ip = resolve(&srv.opts.host_ip); + let addr = format!("{}:{}", host_ip, srv.opts.port); let ws_listener = TcpListener::bind(&addr.parse().unwrap(), &srv.handle)?; assert!(srv.opts.ssl_key.is_none(), "ssl not supported yet"); @@ -497,6 +504,9 @@ impl Future for PingManager { } } + // Ensure the scheduled ping is actually flushed out + self.socket.borrow_mut().poll_complete()?; + // At this point looks our state of ping management A-OK, so try to // make progress on our client, and when done with that execute the // closing handshake. @@ -590,7 +600,6 @@ impl Stream for WebpushSocket Pong::None => {} Pong::Received => {} Pong::Waiting(task) => { - self.pong = Pong::None; task.notify(); } }