Skip to content

Commit 0f943b3

Browse files
ocackben-clayton
authored andcommitted
Fix for issue #100 : Let possible to start the server on an address other than localhost
Add a new function for keeping the API stable
1 parent 37c744c commit 0f943b3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

include/dap/network.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,21 @@ class Server {
4444
// create() constructs and returns a new Server.
4545
static std::unique_ptr<Server> create();
4646

47-
// start() begins listening for connections on the given port.
47+
// start() begins listening for connections on localhost and the given port.
4848
// callback will be called for each connection.
4949
// onError will be called for any connection errors.
5050
virtual bool start(int port,
5151
const OnConnect& callback,
5252
const OnError& onError = ignoreErrors) = 0;
5353

54+
// start() begins listening for connections on the given specific address and port.
55+
// callback will be called for each connection.
56+
// onError will be called for any connection errors.
57+
virtual bool start(const char* address,
58+
int port,
59+
const OnConnect& callback,
60+
const OnError& onError = ignoreErrors) = 0;
61+
5462
// stop() stops listening for connections.
5563
// stop() is implicitly called on destruction.
5664
virtual void stop() = 0;

src/network.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@ class Impl : public dap::net::Server {
3232
bool start(int port,
3333
const OnConnect& onConnect,
3434
const OnError& onError) override {
35+
return start("localhost", port, onConnect, onError);
36+
}
37+
38+
bool start(const char* address,
39+
int port,
40+
const OnConnect& onConnect,
41+
const OnError& onError) override {
3542
std::unique_lock<std::mutex> lock(mutex);
3643
stopWithLock();
3744
socket = std::unique_ptr<dap::Socket>(
38-
new dap::Socket("localhost", std::to_string(port).c_str()));
45+
new dap::Socket(address, std::to_string(port).c_str()));
3946

4047
if (!socket->isOpen()) {
4148
onError("Failed to open socket");

0 commit comments

Comments
 (0)