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 <ouj@fb.com>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21814}
This commit is contained in:
Jiawei Ou 2018-01-30 12:13:48 -08:00 committed by Commit Bot
parent 76d295231a
commit 018dd6e9d1
2 changed files with 10 additions and 10 deletions

View File

@ -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<rtc::AsyncSocket*>(ptr);
// 1 means socket closed.
return (socket->GetState() == rtc::AsyncSocket::CS_CLOSED) ? 1 : 0;
}
case BIO_CTRL_WPENDING:
case BIO_CTRL_PENDING:
return 0;

View File

@ -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<int>(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<StreamInterface*>(ptr);
// 1 means end-of-stream.
return (stream->GetState() == SS_CLOSED) ? 1 : 0;
}
case BIO_CTRL_WPENDING:
case BIO_CTRL_PENDING:
return 0;