From 9ae9ccff1618e37a93e56072a3422e83fa82deb4 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Thu, 3 Sep 2020 19:21:54 +0530 Subject: [PATCH] Modified the logic to check Port is in use for runtime. Fixes #5751. --- runtime/Runtime.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/runtime/Runtime.cpp b/runtime/Runtime.cpp index 8967811e5..432ee0904 100644 --- a/runtime/Runtime.cpp +++ b/runtime/Runtime.cpp @@ -346,11 +346,15 @@ bool Runtime::isPortInUse(const quint16 port) const { QTcpSocket socket; - // Bind the socket on the specified port. It it fails then - // port is in use. - bool bindSuccessful = socket.bind(port, QTcpSocket::ShareAddress); + // Bind the socket on the specified port. + socket.bind(port, QTcpSocket::DontShareAddress); - return !bindSuccessful; + // Returns the host port number of the local socket if available; otherwise returns 0 + quint16 tmpPort = socket.localPort(); + if (tmpPort == 0) + return true; + + return false; } void Runtime::openConfigureWindow(const QString errorMsg)