X-Git-Url: https://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FServer.java;h=2f23c288388bbc82315672dc3e375c39ec3622cc;hb=d6ab0dab9051de0ee408dda63db8fdf8e01d221d;hp=2022469a0296387f90bc5aca40005d4b2981849c;hpb=f4053377fa15da2f11e82955bfab86e673fa371c;p=fanfix.git diff --git a/src/be/nikiroo/utils/serial/server/Server.java b/src/be/nikiroo/utils/serial/server/Server.java index 2022469..2f23c28 100644 --- a/src/be/nikiroo/utils/serial/server/Server.java +++ b/src/be/nikiroo/utils/serial/server/Server.java @@ -38,6 +38,9 @@ abstract class Server implements Runnable { private boolean exiting = false; private int counter; + private long bytesReceived; + private long bytesSent; + private TraceHandler tracer = new TraceHandler(); /** @@ -146,6 +149,24 @@ abstract class Server implements Runnable { return port; } + /** + * The total amount of bytes received. + * + * @return the amount of bytes received + */ + public long getBytesReceived() { + return bytesReceived; + } + + /** + * The total amount of bytes sent. + * + * @return the amount of bytes sent + */ + public long getBytesSent() { + return bytesSent; + } + /** * Start the server (listen on the network for new connections). *

@@ -200,10 +221,16 @@ abstract class Server implements Runnable { new Thread(new Runnable() { @Override public void run() { + ConnectActionServer action = null; try { - createConnectActionServer(s).connect(); + action = createConnectActionServer(s); + action.connect(); } finally { count(-1); + if (action != null) { + bytesReceived += action.getBytesReceived(); + bytesSent += action.getBytesSent(); + } } } }).start(); @@ -293,13 +320,13 @@ abstract class Server implements Runnable { } } } + } - // only return when stopped - while (started || exiting) { - try { - Thread.sleep(10); - } catch (InterruptedException e) { - } + // return only when stopped + while (started || exiting) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { } } } @@ -357,7 +384,10 @@ abstract class Server implements Runnable { Socket s; if (ssl) { s = SSLSocketFactory.getDefault().createSocket(host, port); - ((SSLSocket) s).setEnabledCipherSuites(ANON_CIPHERS); + if (s instanceof SSLSocket) { + // Should always be the case + ((SSLSocket) s).setEnabledCipherSuites(ANON_CIPHERS); + } } else { s = new Socket(host, port); } @@ -388,7 +418,10 @@ abstract class Server implements Runnable { ServerSocket ss; if (ssl) { ss = SSLServerSocketFactory.getDefault().createServerSocket(port); - ((SSLServerSocket) ss).setEnabledCipherSuites(ANON_CIPHERS); + if (ss instanceof SSLServerSocket) { + // Should always be the case + ((SSLServerSocket) ss).setEnabledCipherSuites(ANON_CIPHERS); + } } else { ss = new ServerSocket(port); } @@ -401,7 +434,7 @@ abstract class Server implements Runnable { * * @return the list of such supported ciphers */ - private static String[] getAnonCiphers() { + public static String[] getAnonCiphers() { List anonCiphers = new ArrayList(); for (String cipher : ((SSLSocketFactory) SSLSocketFactory.getDefault()) .getSupportedCipherSuites()) {