From 7075cf7bc81998b6cf72ccb6748050cd40b006be Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 20 May 2019 11:18:23 +0200 Subject: [PATCH] Make meshlink_set_port() return false if we didn't bind to the requested port. --- src/meshlink++.h | 4 +++- src/meshlink.c | 2 +- src/meshlink.h | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/meshlink++.h b/src/meshlink++.h index 48eabf3f..8287e038 100644 --- a/src/meshlink++.h +++ b/src/meshlink++.h @@ -533,7 +533,9 @@ public: * If the port is set to 0, then MeshLink will listen on a port * that is randomly assigned by the operating system every time open() is called. * - * @return This function returns true if the port was successfully changed, false otherwise. + * @return This function returns true if the port was successfully changed + * to the desired port, false otherwise. If it returns false, there + * is no guarantee that MeshLink is listening on the old port. */ bool set_port(int port) { return meshlink_set_port(handle, port); diff --git a/src/meshlink.c b/src/meshlink.c index 9641173a..496e5d3c 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -2339,7 +2339,7 @@ bool meshlink_set_port(meshlink_handle_t *mesh, int port) { done: pthread_mutex_unlock(&(mesh->mesh_mutex)); - return rval; + return rval && meshlink_get_port(mesh) == port; } void meshlink_set_invitation_timeout(meshlink_handle_t *mesh, int timeout) { diff --git a/src/meshlink.h b/src/meshlink.h index 8ec7b508..c6cb86c6 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -730,7 +730,9 @@ extern int meshlink_get_port(meshlink_handle_t *mesh); * If the port is set to 0, then MeshLink will listen on a port * that is randomly assigned by the operating system every time meshlink_open() is called. * - * @return This function returns true if the port was successfully changed, false otherwise. + * @return This function returns true if the port was successfully changed + * to the desired port, false otherwise. If it returns false, there + * is no guarantee that MeshLink is listening on the old port. */ extern bool meshlink_set_port(meshlink_handle_t *mesh, int port); -- 2.39.2