From ff6d01bc254bbaf359b474f53da9a1534b19b90e Mon Sep 17 00:00:00 2001 From: tpoole Date: Wed, 30 Aug 2017 09:55:56 +0100 Subject: [PATCH] Added a function to the InterprocessConnectionServer class to get the bound port number --- modules/juce_core/network/juce_Socket.h | 3 ++- .../interprocess/juce_InterprocessConnectionServer.cpp | 5 +++++ .../interprocess/juce_InterprocessConnectionServer.h | 10 +++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/juce_core/network/juce_Socket.h b/modules/juce_core/network/juce_Socket.h index 66d259fdbe..8c586f9f38 100644 --- a/modules/juce_core/network/juce_Socket.h +++ b/modules/juce_core/network/juce_Socket.h @@ -74,7 +74,8 @@ public: This is useful if you need to know to which port the OS has actually bound your socket when calling the constructor or bindToPort with zero as the - localPortNumber argument. Returns -1 if the function fails. */ + localPortNumber argument. Returns -1 if the function fails. + */ int getBoundPort() const noexcept; /** Tries to connect the socket to hostname:port. diff --git a/modules/juce_events/interprocess/juce_InterprocessConnectionServer.cpp b/modules/juce_events/interprocess/juce_InterprocessConnectionServer.cpp index d972d9794b..196d90978e 100644 --- a/modules/juce_events/interprocess/juce_InterprocessConnectionServer.cpp +++ b/modules/juce_events/interprocess/juce_InterprocessConnectionServer.cpp @@ -58,6 +58,11 @@ void InterprocessConnectionServer::stop() socket = nullptr; } +int InterprocessConnectionServer::getBoundPort() const noexcept +{ + return (socket == nullptr) ? -1 : socket->getBoundPort(); +} + void InterprocessConnectionServer::run() { while ((! threadShouldExit()) && socket != nullptr) diff --git a/modules/juce_events/interprocess/juce_InterprocessConnectionServer.h b/modules/juce_events/interprocess/juce_InterprocessConnectionServer.h index 8afd71ae34..f731a379a2 100644 --- a/modules/juce_events/interprocess/juce_InterprocessConnectionServer.h +++ b/modules/juce_events/interprocess/juce_InterprocessConnectionServer.h @@ -71,6 +71,15 @@ public: */ void stop(); + /** Returns the local port number to which this server is currently bound. + + This is useful if you need to know to which port the OS has actually bound your + socket when calling beginWaitingForSocket with a port number of zero. + + Returns -1 if the function fails. + */ + int getBoundPort() const noexcept; + protected: /** Creates a suitable connection object for a client process that wants to connect to this one. @@ -83,7 +92,6 @@ protected: */ virtual InterprocessConnection* createConnectionObject() = 0; - private: //============================================================================== ScopedPointer socket;