< prev index next >

test/javax/net/ssl/templates/SSLTest.java

Print this page

        

*** 92,107 **** private SSLContext context; /* * Is the server ready to serve? */ ! private final CountDownLatch serverCondition = new CountDownLatch(1); /* * Is the client ready to handshake? */ ! private final CountDownLatch clientCondition = new CountDownLatch(1); /* * Public API. */ --- 92,117 ---- private SSLContext context; /* * Is the server ready to serve? */ ! private final CountDownLatch serverReadyCondition = new CountDownLatch(1); /* * Is the client ready to handshake? */ ! private final CountDownLatch clientReadyCondition = new CountDownLatch(1); ! ! /* ! * Is the server done? ! */ ! private final CountDownLatch serverDoneCondition = new CountDownLatch(1); ! ! /* ! * Is the client done? ! */ ! private final CountDownLatch clientDoneCondition = new CountDownLatch(1); /* * Public API. */
*** 160,169 **** --- 170,198 ---- keystore.load(fis, password.toCharArray()); } return keystore; } + // Try to accept a connection in 30 seconds. + public static SSLSocket accept(SSLServerSocket sslServerSocket) + throws IOException { + + return accept(sslServerSocket, SERVER_TIMEOUT); + } + + public static SSLSocket accept(SSLServerSocket sslServerSocket, int timeout) + throws IOException { + + try { + sslServerSocket.setSoTimeout(timeout); + return (SSLSocket) sslServerSocket.accept(); + } catch (SocketTimeoutException ste) { + sslServerSocket.close(); + return null; + } + } + public SSLTest setSeparateServerThread(boolean separateServerThread) { this.separateServerThread = separateServerThread; return this; }
*** 200,236 **** return (SSLSocketFactory) SSLSocketFactory.getDefault(); } public void signalServerReady() { ! serverCondition.countDown(); } public boolean waitForClientSignal(long timeout, TimeUnit unit) throws InterruptedException { ! return clientCondition.await(timeout, unit); } public boolean waitForClientSignal() throws InterruptedException { return waitForClientSignal(CLIENT_SIGNAL_TIMEOUT, TimeUnit.SECONDS); } public void signalClientReady() { ! clientCondition.countDown(); } public boolean waitForServerSignal(long timeout, TimeUnit unit) throws InterruptedException { ! return serverCondition.await(timeout, unit); } public boolean waitForServerSignal() throws InterruptedException { return waitForServerSignal(SERVER_SIGNAL_TIMEOUT, TimeUnit.SECONDS); } public SSLTest setServerPeer(Peer serverPeer) { this.serverPeer = serverPeer; return this; } --- 229,293 ---- return (SSLSocketFactory) SSLSocketFactory.getDefault(); } public void signalServerReady() { ! serverReadyCondition.countDown(); ! } ! ! public void signalServerDone() { ! serverDoneCondition.countDown(); } public boolean waitForClientSignal(long timeout, TimeUnit unit) throws InterruptedException { ! return clientReadyCondition.await(timeout, unit); } public boolean waitForClientSignal() throws InterruptedException { return waitForClientSignal(CLIENT_SIGNAL_TIMEOUT, TimeUnit.SECONDS); } + public boolean waitForClientDone(long timeout, TimeUnit unit) + throws InterruptedException { + + return clientDoneCondition.await(timeout, unit); + } + + public boolean waitForClientDone() throws InterruptedException { + return waitForClientDone(CLIENT_SIGNAL_TIMEOUT, TimeUnit.SECONDS); + } + public void signalClientReady() { ! clientReadyCondition.countDown(); ! } ! ! public void signalClientDone() { ! clientDoneCondition.countDown(); } public boolean waitForServerSignal(long timeout, TimeUnit unit) throws InterruptedException { ! return serverReadyCondition.await(timeout, unit); } public boolean waitForServerSignal() throws InterruptedException { return waitForServerSignal(SERVER_SIGNAL_TIMEOUT, TimeUnit.SECONDS); } + public boolean waitForServerDone(long timeout, TimeUnit unit) + throws InterruptedException { + + return serverDoneCondition.await(timeout, unit); + } + + public boolean waitForServerDone() throws InterruptedException { + return waitForServerDone(SERVER_SIGNAL_TIMEOUT, TimeUnit.SECONDS); + } + public SSLTest setServerPeer(Peer serverPeer) { this.serverPeer = serverPeer; return this; }
*** 308,330 **** // Signal the client, the server is ready to accept connection. test.signalServerReady(); // Try to accept a connection in 30 seconds. ! SSLSocket sslSocket; ! try { ! sslServerSocket.setSoTimeout(SERVER_TIMEOUT); ! sslSocket = (SSLSocket) sslServerSocket.accept(); ! print("Server accepted connection"); ! } catch (SocketTimeoutException ste) { ! sslServerSocket.close(); ! // Ignore the test case if no connection within 30 seconds. print("No incoming client connection in 30 seconds. " ! + "Ignore in server side.", ste); return; } // handle the connection try { // Is it the expected client connection? // --- 365,382 ---- // Signal the client, the server is ready to accept connection. test.signalServerReady(); // Try to accept a connection in 30 seconds. ! SSLSocket sslSocket = accept(sslServerSocket); ! if (sslSocket == null) { // Ignore the test case if no connection within 30 seconds. print("No incoming client connection in 30 seconds. " ! + "Ignore in server side."); return; } + print("Server accepted connection"); // handle the connection try { // Is it the expected client connection? //
*** 351,360 **** --- 403,414 ---- } } finally { sslSocket.close(); sslServerSocket.close(); } + + test.signalServerDone(); } /* * Define the server side application of the test for the specified socket. */
*** 417,426 **** --- 471,482 ---- // Run the application in client side. print("Run client application"); test.getClientApplication().run(sslSocket, test); } + + test.signalClientDone(); } /* * Define the client side application of the test for the specified socket. */
< prev index next >