Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
feat: use config hostname for Rust websocket binding
Browse files Browse the repository at this point in the history
Closes #1004
  • Loading branch information
bbangert committed Sep 8, 2017
1 parent 2fe4af7 commit 30911ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions autopush_rs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ 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.port = conf.port
cfg.ssl_cert = ffi_from_buffer(conf.ssl.cert)
cfg.ssl_dh_param = ffi_from_buffer(conf.ssl.dh_param)
Expand Down
5 changes: 4 additions & 1 deletion autopush_rs/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct AutopushServerInner {
#[repr(C)]
pub struct AutopushServerOptions {
pub debug: i32,
pub host_ip: *const c_char,
pub port: u16,
pub url: *const c_char,
pub ssl_key: *const c_char,
Expand All @@ -66,6 +67,7 @@ pub struct Server {

pub struct ServerOptions {
pub debug: bool,
pub host_ip: String,
pub port: u16,
pub url: String,
pub ssl_key: Option<PathBuf>,
Expand Down Expand Up @@ -119,6 +121,7 @@ pub extern "C" fn autopush_server_new(opts: *const AutopushServerOptions,

let opts = ServerOptions {
debug: opts.debug != 0,
host_ip: to_s(opts.host_ip).expect("hostname must be specified").to_string(),
port: opts.port,
url: to_s(opts.url).expect("url must be specified").to_string(),
ssl_key: to_s(opts.ssl_key).map(PathBuf::from),
Expand Down Expand Up @@ -265,7 +268,7 @@ impl Server {
handle: core.handle(),
tx: tx,
});
let addr = format!("127.0.0.1:{}", srv.opts.port);
let addr = format!("{}:{}", srv.opts.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");
Expand Down

0 comments on commit 30911ee

Please sign in to comment.