diff options
author | Brian Carlstrom <bdc@google.com> | 2010-09-21 02:09:29 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2010-09-21 12:13:43 -0700 |
commit | 84f161268b8ae93a9046c40ca8381aa92148f2f6 (patch) | |
tree | 5e65c94cac2b8b12cd9f2fbb44707504ce098d8e /luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java | |
parent | 03a4818d5b95c77585be7df437b6fe28507529a9 (diff) | |
download | libcore-84f161268b8ae93a9046c40ca8381aa92148f2f6.tar.gz libcore-84f161268b8ae93a9046c40ca8381aa92148f2f6.tar.bz2 libcore-84f161268b8ae93a9046c40ca8381aa92148f2f6.zip |
Make SSL network I/O interruptible
- Changed NativeCrypto code to hold onto java.io.FileDescriptor so it
can see observe when another thread calls Socket.close and sets the
FileDescriptor's fd to -1. Changed AppData::setEnv to check
NetFd::isClosed, it was already being used before each SSL I/O
operation.
- Changed sslSelect to no longer take an int fd, it now uses the
AppData to get access the FileDescriptor. Within sslSelect, the
select call is now protected with AsynchronousSocketCloseMonitor.
The select call is now retried on EINTR, checking for socket close
similar to NET_FAILURE_RETRY. sslSelect now returns
THROWN_SOCKETEXCEPTION to indicate that NetFd::isClosed has already
thrown.
- sslRead and sslWrite now similarly returns THROWN_SOCKETEXCEPTION to
indicate that Net::isClosed detected a closed FileDescriptor.
luni/src/main/native/NativeCrypto.cpp
Moved NetFd from OSNetworkSystem.cpp to new NetFd.h for reuse by NativeCrypto
luni/src/main/native/NetFd.h
luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
Added test of 4 Socket/SSLSocket interrupt cases
1.) read Socket / close Socket (redundant with AsynchronousCloseExceptionTest)
2.) read Socket / close SSLSocket
3.) read SSLSocket / close Socket
4.) read SSLSocket / close SSLSocket
luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
Bug: 2973020
Change-Id: I9037738dd1d1c09c03c99e3403e086366aa25109
Diffstat (limited to 'luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java')
-rw-r--r-- | luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java index dbd9a2a51..5e9567a96 100644 --- a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java +++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java @@ -816,6 +816,62 @@ public class SSLSocketTest extends TestCase { listening.close(); } + public void test_SSLSocket_interrupt() throws Exception { + ServerSocket listening = new ServerSocket(0); + + for (int i = 0; i < 3; i++) { + Socket underlying = new Socket(listening.getInetAddress(), listening.getLocalPort()); + Socket server = listening.accept(); + + SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault(); + Socket clientWrapping = sf.createSocket(underlying, null, -1, true); + + switch (i) { + case 0: + test_SSLSocket_interrupt_case(underlying, underlying); + break; + case 1: + test_SSLSocket_interrupt_case(underlying, clientWrapping); + break; + case 2: + test_SSLSocket_interrupt_case(clientWrapping, underlying); + break; + case 3: + test_SSLSocket_interrupt_case(clientWrapping, clientWrapping); + break; + default: + fail(); + } + + server.close(); + underlying.close(); + } + listening.close(); + } + + private void test_SSLSocket_interrupt_case(Socket toRead, final Socket toClose) + throws Exception { + new Thread() { + @Override + public void run() { + try { + Thread.sleep(1 * 1000); + toClose.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }.start(); + try { + toRead.setSoTimeout(5 * 1000); + toRead.getInputStream().read(); + fail(); + } catch (SocketTimeoutException e) { + throw e; + } catch (SocketException expected) { + } + } + public void test_TestSSLSocketPair_create() { TestSSLSocketPair test = TestSSLSocketPair.create(); assertNotNull(test.c); |