From c711941e9a0cccbad8a1a74beaa0362a787d7d23 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 23 Nov 2019 18:07:35 +0000 Subject: [PATCH] Problem: wildcard port binding does not work with WS sockets Solution: remove the path from the address when resolving --- src/ws_address.cpp | 4 +++- src/ws_listener.cpp | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ws_address.cpp b/src/ws_address.cpp index f614e122..46831fe2 100644 --- a/src/ws_address.cpp +++ b/src/ws_address.cpp @@ -105,6 +105,8 @@ int zmq::ws_address_t::resolve (const char *name_, bool local_, bool ipv6_) _path = std::string (delim); else _path = std::string ("/"); + // remove the path, otherwise resolving the port will fail with wildcard + std::string host_port = std::string (name_, delim - name_); ip_resolver_options_t resolver_opts; resolver_opts.bindable (local_) @@ -116,7 +118,7 @@ int zmq::ws_address_t::resolve (const char *name_, bool local_, bool ipv6_) ip_resolver_t resolver (resolver_opts); - return resolver.resolve (&_address, name_); + return resolver.resolve (&_address, host_port.c_str ()); } int zmq::ws_address_t::to_string (std::string &addr_) const diff --git a/src/ws_listener.cpp b/src/ws_listener.cpp index f29653d4..dc2b0e0f 100644 --- a/src/ws_listener.cpp +++ b/src/ws_listener.cpp @@ -206,7 +206,10 @@ int zmq::ws_listener_t::set_local_address (const char *addr_) if (rc != 0) return -1; - if (create_socket (addr_) == -1) + // remove the path, otherwise resolving the port will fail with wildcard + const char *delim = strrchr (addr_, '/'); + std::string host_port = std::string (addr_, delim - addr_); + if (create_socket (host_port.c_str ()) == -1) return -1; }