From b08aa70e2045404d935895fafac6d2fb69f9b92f Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Mon, 27 Nov 2017 23:24:20 +0100 Subject: [PATCH] Change Server behaviour for start(): - start() is now synchronous, a new start(boolean wait) is there --- src/be/nikiroo/utils/serial/Server.java | 23 +++++++++++++++++++++-- src/be/nikiroo/utils/test/SerialTest.java | 8 ++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/be/nikiroo/utils/serial/Server.java b/src/be/nikiroo/utils/serial/Server.java index f2a01c5d..b2771863 100644 --- a/src/be/nikiroo/utils/serial/Server.java +++ b/src/be/nikiroo/utils/serial/Server.java @@ -125,19 +125,38 @@ abstract public class Server implements Runnable { * Start the server (listen on the network for new connections). *

* Can only be called once. + *

+ * This call is synchronous. */ public void start() { + start(true); + } + + /** + * Start the server (listen on the network for new connections). + *

+ * Can only be called once. + * + * @param wait + * TRUE for synchronous, FALSE for asynchronous + */ + public void start(boolean wait) { boolean ok = false; synchronized (lock) { if (!started && ss != null) { - started = true; - new Thread(this).start(); ok = true; + started = true; + if (!wait) { + new Thread(this).start(); + } } } if (ok) { tracer.trace(name + ": server started on port " + port); + if (wait) { + run(); + } } else if (ss == null) { tracer.error(name + ": cannot start server on port " + port + ", it has already been used"); diff --git a/src/be/nikiroo/utils/test/SerialTest.java b/src/be/nikiroo/utils/test/SerialTest.java index e66bda8d..e5bafa9c 100644 --- a/src/be/nikiroo/utils/test/SerialTest.java +++ b/src/be/nikiroo/utils/test/SerialTest.java @@ -38,7 +38,7 @@ class SerialTest extends TestLauncher { // TODO: remove server.setTraceHandler(new TraceHandler(true, true, true)); - server.start(); + server.start(false); try { new ConnectActionClient(null, server.getPort(), ssl) { @@ -80,7 +80,7 @@ class SerialTest extends TestLauncher { } }; - server.start(); + server.start(false); try { new ConnectActionClient(null, server.getPort(), ssl) { @@ -128,7 +128,7 @@ class SerialTest extends TestLauncher { } }; - server.start(); + server.start(false); try { new ConnectActionClient(null, server.getPort(), ssl) { @@ -177,7 +177,7 @@ class SerialTest extends TestLauncher { } }; - server.start(); + server.start(false); try { new ConnectActionClient(null, server.getPort(), ssl) { -- 2.27.0