Drop buffers in idle SSLClientSockets (and SSLServerSockets).
As part of this, significantly refactor how both classes handle the
transport. BoringSSL's SSL stack expects the transport as a BIO. BIOs
follow the UNIX-style non-blocking I/O. Our net stack, however, is based
on asynchronous callbacks. Both socket had some complex code to bridge
the two I/O models.
Factor all this code into a SocketBIOAdapter. This takes a StreamSocket
and returns a BIO which acts on the socket. The UNIX model assumes
external knowledge of when to retry operations (usually a select loop),
so the SocketBIOAdapter has a delegate interface which signals
OnReadReady and OnWriteReady. By being factored out, it can also be
independently unit-tested, which is handy.
It also implements the weird hack we have where write errors route into
read errors. In doing so, it fixes a case where whether that error was
routed correctly depended on whether transport Writes failed
synchronously (if BufferSend synchronously succeeded in DoWriteLoop,
DoPayloadRead wasn't run, but it was run if asynchronous). This requires
tweaking a test expectation.
This removes uses of the bizarre "zero-copy" BIO pair stuff which can
now be removed from BoringSSL. It also unifies client and server I/O
handling which fixes transport error mapping on the
server. (Accordingly, some server test expectations also needed fixes.)
Oh, and on top of all this, actually drop the buffers when not needed as this
was sort of the point of this exercise. Having the code factored out makes this
a lot simpler to reason about and avoids adding even more complexity to BIO
pairs.
BUG=652456,399455
Review-Url: https://codereview.chromium.org/2411033003
Cr-Commit-Position: refs/heads/master@{#426097}
diff --git a/net/socket/ssl_server_socket_unittest.cc b/net/socket/ssl_server_socket_unittest.cc
index 8f22947..e6a71a1 100644
--- a/net/socket/ssl_server_socket_unittest.cc
+++ b/net/socket/ssl_server_socket_unittest.cc
@@ -787,7 +787,8 @@
client_socket_->Disconnect();
- EXPECT_THAT(handshake_callback.GetResult(server_ret), IsError(ERR_FAILED));
+ EXPECT_THAT(handshake_callback.GetResult(server_ret),
+ IsError(ERR_CONNECTION_CLOSED));
}
TEST_F(SSLServerSocketTest, HandshakeWithClientCertRequiredNotSuppliedCached) {
@@ -820,7 +821,8 @@
client_socket_->Disconnect();
- EXPECT_THAT(handshake_callback.GetResult(server_ret), IsError(ERR_FAILED));
+ EXPECT_THAT(handshake_callback.GetResult(server_ret),
+ IsError(ERR_CONNECTION_CLOSED));
server_socket_->Disconnect();
// Below, check that the cache didn't store the result of a failed handshake.
@@ -842,7 +844,8 @@
client_socket_->Disconnect();
- EXPECT_THAT(handshake_callback2.GetResult(server_ret2), IsError(ERR_FAILED));
+ EXPECT_THAT(handshake_callback2.GetResult(server_ret2),
+ IsError(ERR_CONNECTION_CLOSED));
}
TEST_F(SSLServerSocketTest, HandshakeWithWrongClientCertSupplied) {