Formatting openssladapter to be more consistent.
This CL just updates some of the vertical spaces, if conditional scoping rusles etc fro openssladapter.cc. This is part of an ongoing effort to clean up this code base. Bug: webrtc:9860 Change-Id: I628edaa663cb977fefdff186fa015e4b0a794db1 Reviewed-on: https://webrtc-review.googlesource.com/c/106240 Reviewed-by: Steve Anton <steveanton@webrtc.org> Reviewed-by: Qingsi Wang <qingsi@webrtc.org> Commit-Queue: Benjamin Wright <benwright@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25218}
This commit is contained in:

committed by
Commit Bot

parent
4e5074e0d2
commit
243cabe502
@ -393,15 +393,17 @@ int OpenSSLAdapter::BeginSSL() {
|
||||
|
||||
// Do the connect.
|
||||
err = ContinueSSL();
|
||||
if (err != 0)
|
||||
if (err != 0) {
|
||||
goto ssl_error;
|
||||
}
|
||||
|
||||
return err;
|
||||
|
||||
ssl_error:
|
||||
Cleanup();
|
||||
if (bio)
|
||||
if (bio) {
|
||||
BIO_free(bio);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
@ -425,14 +427,13 @@ int OpenSSLAdapter::ContinueSSL() {
|
||||
|
||||
state_ = SSL_CONNECTED;
|
||||
AsyncSocketAdapter::OnConnectEvent(this);
|
||||
#if 0 // TODO(benwright): worry about this
|
||||
// Don't let ourselves go away during the callbacks
|
||||
PRefPtr<OpenSSLAdapter> lock(this);
|
||||
RTC_LOG(LS_INFO) << " -- onStreamReadable";
|
||||
AsyncSocketAdapter::OnReadEvent(this);
|
||||
RTC_LOG(LS_INFO) << " -- onStreamWriteable";
|
||||
AsyncSocketAdapter::OnWriteEvent(this);
|
||||
#endif
|
||||
// TODO(benwright): Refactor this code path.
|
||||
// Don't let ourselves go away during the callbacks
|
||||
// PRefPtr<OpenSSLAdapter> lock(this);
|
||||
// RTC_LOG(LS_INFO) << " -- onStreamReadable";
|
||||
// AsyncSocketAdapter::OnReadEvent(this);
|
||||
// RTC_LOG(LS_INFO) << " -- onStreamWriteable";
|
||||
// AsyncSocketAdapter::OnWriteEvent(this);
|
||||
break;
|
||||
|
||||
case SSL_ERROR_WANT_READ:
|
||||
@ -463,8 +464,9 @@ void OpenSSLAdapter::Error(const char* context, int err, bool signal) {
|
||||
<< ")";
|
||||
state_ = SSL_ERROR;
|
||||
SetError(err);
|
||||
if (signal)
|
||||
if (signal) {
|
||||
AsyncSocketAdapter::OnCloseEvent(this, err);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSSLAdapter::Cleanup() {
|
||||
@ -529,23 +531,20 @@ int OpenSSLAdapter::DoSslWrite(const void* pv, size_t cb, int* error) {
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// AsyncSocket Implementation
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int OpenSSLAdapter::Send(const void* pv, size_t cb) {
|
||||
switch (state_) {
|
||||
case SSL_NONE:
|
||||
return AsyncSocketAdapter::Send(pv, cb);
|
||||
|
||||
case SSL_WAIT:
|
||||
case SSL_CONNECTING:
|
||||
SetError(ENOTCONN);
|
||||
return SOCKET_ERROR;
|
||||
|
||||
case SSL_CONNECTED:
|
||||
break;
|
||||
|
||||
case SSL_ERROR:
|
||||
default:
|
||||
return SOCKET_ERROR;
|
||||
@ -568,8 +567,9 @@ int OpenSSLAdapter::Send(const void* pv, size_t cb) {
|
||||
}
|
||||
|
||||
// OpenSSL will return an error if we try to write zero bytes
|
||||
if (cb == 0)
|
||||
if (cb == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = DoSslWrite(pv, cb, &error);
|
||||
|
||||
@ -596,7 +596,6 @@ int OpenSSLAdapter::Send(const void* pv, size_t cb) {
|
||||
// size. The user of this class can consider it sent.
|
||||
return rtc::dchecked_cast<int>(cb);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -609,7 +608,6 @@ int OpenSSLAdapter::SendTo(const void* pv,
|
||||
}
|
||||
|
||||
SetError(ENOTCONN);
|
||||
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
@ -617,28 +615,26 @@ int OpenSSLAdapter::Recv(void* pv, size_t cb, int64_t* timestamp) {
|
||||
switch (state_) {
|
||||
case SSL_NONE:
|
||||
return AsyncSocketAdapter::Recv(pv, cb, timestamp);
|
||||
|
||||
case SSL_WAIT:
|
||||
case SSL_CONNECTING:
|
||||
SetError(ENOTCONN);
|
||||
return SOCKET_ERROR;
|
||||
|
||||
case SSL_CONNECTED:
|
||||
break;
|
||||
|
||||
case SSL_ERROR:
|
||||
default:
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
// Don't trust OpenSSL with zero byte reads
|
||||
if (cb == 0)
|
||||
if (cb == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssl_read_needs_write_ = false;
|
||||
|
||||
int code = SSL_read(ssl_, pv, checked_cast<int>(cb));
|
||||
int error = SSL_get_error(ssl_, code);
|
||||
|
||||
switch (error) {
|
||||
case SSL_ERROR_NONE:
|
||||
return code;
|
||||
@ -661,7 +657,6 @@ int OpenSSLAdapter::Recv(void* pv, size_t cb, int64_t* timestamp) {
|
||||
Error("SSL_read", (code ? code : -1), false);
|
||||
break;
|
||||
}
|
||||
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
@ -671,14 +666,11 @@ int OpenSSLAdapter::RecvFrom(void* pv,
|
||||
int64_t* timestamp) {
|
||||
if (socket_->GetState() == Socket::CS_CONNECTED) {
|
||||
int ret = Recv(pv, cb, timestamp);
|
||||
|
||||
*paddr = GetRemoteAddress();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SetError(ENOTCONN);
|
||||
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
@ -689,12 +681,11 @@ int OpenSSLAdapter::Close() {
|
||||
}
|
||||
|
||||
Socket::ConnState OpenSSLAdapter::GetState() const {
|
||||
// if (signal_close_)
|
||||
// return CS_CONNECTED;
|
||||
ConnState state = socket_->GetState();
|
||||
if ((state == CS_CONNECTED) &&
|
||||
((state_ == SSL_WAIT) || (state_ == SSL_CONNECTING)))
|
||||
((state_ == SSL_WAIT) || (state_ == SSL_CONNECTING))) {
|
||||
state = CS_CONNECTING;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@ -737,8 +728,9 @@ void OpenSSLAdapter::OnReadEvent(AsyncSocket* socket) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state_ != SSL_CONNECTED)
|
||||
if (state_ != SSL_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't let ourselves go away during the callbacks
|
||||
// PRefPtr<OpenSSLAdapter> lock(this); // TODO(benwright): fix this
|
||||
@ -762,8 +754,9 @@ void OpenSSLAdapter::OnWriteEvent(AsyncSocket* socket) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state_ != SSL_CONNECTED)
|
||||
if (state_ != SSL_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't let ourselves go away during the callbacks
|
||||
// PRefPtr<OpenSSLAdapter> lock(this); // TODO(benwright): fix this
|
||||
|
Reference in New Issue
Block a user