From 018dd6e9d102c93788d62673f81c710a4bc101a2 Mon Sep 17 00:00:00 2001 From: Jiawei Ou Date: Tue, 30 Jan 2018 12:13:48 -0800 Subject: [PATCH] Refer to the underlying object when reporting the state of SSL basic I/O The reasons behind this change: 1. In OpenSSL 1.1.0. BIO will be an opaque object. We won't have direct access to the `num` field. 2. `num` is only used by OpenSSL provided BIOs and different types of BIOs use num differently. WebRTC is providing its own customized BIO implementation, it probably shouldn't piggyback into this internal field to store the stream/socket state. 4. We can access the stream/socket state directly using the underlying object anyway. Bug: webrtc:8817 Change-Id: I41cdd2920fba378e312e8436a7b9733381555522 Reviewed-on: https://webrtc-review.googlesource.com/46360 Commit-Queue: Jiawei Ou Reviewed-by: Tommi Cr-Commit-Position: refs/heads/master@{#21814} --- rtc_base/openssladapter.cc | 10 +++++----- rtc_base/opensslstreamadapter.cc | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/rtc_base/openssladapter.cc b/rtc_base/openssladapter.cc index a064596881..e3643a54eb 100644 --- a/rtc_base/openssladapter.cc +++ b/rtc_base/openssladapter.cc @@ -94,7 +94,6 @@ static BIO* BIO_new_socket(rtc::AsyncSocket* socket) { static int socket_new(BIO* b) { b->shutdown = 0; b->init = 1; - b->num = 0; // 1 means socket closed b->ptr = 0; return 1; } @@ -113,8 +112,6 @@ static int socket_read(BIO* b, char* out, int outl) { int result = socket->Recv(out, outl, nullptr); if (result > 0) { return result; - } else if (result == 0) { - b->num = 1; } else if (socket->IsBlocking()) { BIO_set_retry_read(b); } @@ -143,8 +140,11 @@ static long socket_ctrl(BIO* b, int cmd, long num, void* ptr) { switch (cmd) { case BIO_CTRL_RESET: return 0; - case BIO_CTRL_EOF: - return b->num; + case BIO_CTRL_EOF: { + rtc::AsyncSocket* socket = static_cast(ptr); + // 1 means socket closed. + return (socket->GetState() == rtc::AsyncSocket::CS_CLOSED) ? 1 : 0; + } case BIO_CTRL_WPENDING: case BIO_CTRL_PENDING: return 0; diff --git a/rtc_base/opensslstreamadapter.cc b/rtc_base/opensslstreamadapter.cc index 52a0b77623..8f66c303a9 100644 --- a/rtc_base/opensslstreamadapter.cc +++ b/rtc_base/opensslstreamadapter.cc @@ -181,7 +181,6 @@ static BIO* BIO_new_stream(StreamInterface* stream) { static int stream_new(BIO* b) { b->shutdown = 0; b->init = 1; - b->num = 0; // 1 means end-of-stream b->ptr = 0; return 1; } @@ -202,8 +201,6 @@ static int stream_read(BIO* b, char* out, int outl) { StreamResult result = stream->Read(out, outl, &read, &error); if (result == SR_SUCCESS) { return checked_cast(read); - } else if (result == SR_EOS) { - b->num = 1; } else if (result == SR_BLOCK) { BIO_set_retry_read(b); } @@ -234,8 +231,11 @@ static long stream_ctrl(BIO* b, int cmd, long num, void* ptr) { switch (cmd) { case BIO_CTRL_RESET: return 0; - case BIO_CTRL_EOF: - return b->num; + case BIO_CTRL_EOF: { + StreamInterface* stream = static_cast(ptr); + // 1 means end-of-stream. + return (stream->GetState() == SS_CLOSED) ? 1 : 0; + } case BIO_CTRL_WPENDING: case BIO_CTRL_PENDING: return 0;