[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp
Tor Lillqvist
tml at collabora.com
Fri Oct 7 10:51:10 UTC 2016
loolwsd/LOOLWSD.cpp | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
New commits:
commit 3576b17ac95db792d77e41b7a5106f70e3acdf5f
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Oct 7 13:46:53 2016 +0300
Refuse to start a second loolwsd listening on the same socket
Poco's ServerSocket by default uses SO_REUSEPORT when one creates it
using the constructor that takes a port number. If one uses the
default constructor and calls bind() and listen() separately, one can
tell it not to reuse the port.
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index e24505e..7bb6522 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1366,8 +1366,21 @@ namespace {
static inline
ServerSocket* getServerSocket(int nClientPortNumber)
{
- return (LOOLWSD::isSSLEnabled()) ? new SecureServerSocket(nClientPortNumber)
- : new ServerSocket(nClientPortNumber);
+ try
+ {
+ ServerSocket *socket = LOOLWSD::isSSLEnabled() ? new SecureServerSocket()
+ : new ServerSocket();
+ socket->bind(nClientPortNumber, false);
+ // 64 is the default value for the backlog parameter in Poco when creating a ServerSocket,
+ // so use it here, too.
+ socket->listen(64);
+ return socket;
+ }
+ catch (const Exception& exc)
+ {
+ Log::error() << "Could not create server socket: " << exc.displayText() << Log::end;
+ return nullptr;
+ }
}
static inline
@@ -1906,6 +1919,8 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
// Start a server listening on the port for clients
std::unique_ptr<ServerSocket> psvs(getServerSocket(ClientPortNumber));
+ if (!psvs)
+ return Application::EXIT_SOFTWARE;
ThreadPool threadPool(NumPreSpawnedChildren*6, MAX_SESSIONS * 2);
HTTPServer srv(new ClientRequestHandlerFactory(), threadPool, *psvs, params1);
More information about the Libreoffice-commits
mailing list