diff --git a/include/dap/network.h b/include/dap/network.h index 9d14f6b..3832873 100644 --- a/include/dap/network.h +++ b/include/dap/network.h @@ -44,13 +44,21 @@ class Server { // create() constructs and returns a new Server. static std::unique_ptr create(); - // start() begins listening for connections on the given port. + // start() begins listening for connections on localhost and the given port. // callback will be called for each connection. // onError will be called for any connection errors. virtual bool start(int port, const OnConnect& callback, const OnError& onError = ignoreErrors) = 0; + // start() begins listening for connections on the given specific address and port. + // callback will be called for each connection. + // onError will be called for any connection errors. + virtual bool start(const char* address, + int port, + const OnConnect& callback, + const OnError& onError = ignoreErrors) = 0; + // stop() stops listening for connections. // stop() is implicitly called on destruction. virtual void stop() = 0; diff --git a/src/network.cpp b/src/network.cpp index 613c234..7d1da7a 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -32,10 +32,17 @@ class Impl : public dap::net::Server { bool start(int port, const OnConnect& onConnect, const OnError& onError) override { + return start("localhost", port, onConnect, onError); + } + + bool start(const char* address, + int port, + const OnConnect& onConnect, + const OnError& onError) override { std::unique_lock lock(mutex); stopWithLock(); socket = std::unique_ptr( - new dap::Socket("localhost", std::to_string(port).c_str())); + new dap::Socket(address, std::to_string(port).c_str())); if (!socket->isOpen()) { onError("Failed to open socket");