X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FServer.java;h=be847d02884ec3112affd0d730d0d364b158e458;hp=36806d6b61924bd60d5d0d1d2c6afca68d878893;hb=8537d55a7dacf9f528ea9453b03d2391ea348846;hpb=d309f977b2f80988b0275b5ec1d6f95c2d615841 diff --git a/src/be/nikiroo/utils/serial/server/Server.java b/src/be/nikiroo/utils/serial/server/Server.java index 36806d6..be847d0 100644 --- a/src/be/nikiroo/utils/serial/server/Server.java +++ b/src/be/nikiroo/utils/serial/server/Server.java @@ -184,8 +184,17 @@ abstract class Server implements Runnable { while (started && !exiting) { count(1); - Socket s = ss.accept(); - createConnectActionServer(s).connectAsync(); + final Socket s = ss.accept(); + new Thread(new Runnable() { + @Override + public void run() { + try { + createConnectActionServer(s).connect(); + } finally { + count(-1); + } + } + }).start(); } // Will be covered by @link{Server#stop(long)} for timeouts @@ -283,19 +292,6 @@ abstract class Server implements Runnable { } } - /** - * This method will be called on errors. - *

- * By default, it will only call the trace handler (so you may want to call - * super {@link Server#onError} if you override it). - * - * @param e - * the error - */ - protected void onError(Exception e) { - tracer.error(e); - } - /** * Change the number of currently serviced actions. * @@ -304,13 +300,26 @@ abstract class Server implements Runnable { * * @return the current number after this operation */ - int count(int change) { + private int count(int change) { synchronized (counterLock) { counter += change; return counter; } } + /** + * This method will be called on errors. + *

+ * By default, it will only call the trace handler (so you may want to call + * super {@link Server#onError} if you override it). + * + * @param e + * the error + */ + protected void onError(Exception e) { + tracer.error(e); + } + /** * Create a {@link Socket}. *