Skip to content

Commit

Permalink
SocketTls: increase shutdown receive buffer size but remove assert
Browse files Browse the repository at this point in the history
doing a proper shutdown is not that critical and if the peer just keeps sending we dont want to wait forever
  • Loading branch information
mporsch committed Aug 5, 2023
1 parent 85c1a7a commit 7676945
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/socket_tls_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,11 @@ size_t SocketTlsImpl::Write(char const *data, size_t size, Duration timeout)
void SocketTlsImpl::Shutdown()
{
if(SSL_shutdown(ssl.get()) <= 0) {
char buf[32];
// sent the shutdown, but have not received one from the peer yet
// spend some time trying to receive it, but go on eventually
char buf[1024];
SetDeadline(deadline, std::chrono::seconds(1));
for(int i = 1; i <= handshakeStepsMax; ++i) {
for(int i = 0; i < handshakeStepsMax; ++i) {
auto res = SSL_read(ssl.get(), buf, sizeof(buf));
if(res < 0) {
if(!HandleResult(res)) {
Expand All @@ -328,16 +330,15 @@ void SocketTlsImpl::Shutdown()
} else if(res == 0) {
break;
}
assert(i < handshakeStepsMax);
}

(void)SSL_shutdown(ssl.get());
}
}

bool SocketTlsImpl::HandleResult(int ret)
bool SocketTlsImpl::HandleResult(int res)
{
auto error = SSL_get_error(ssl.get(), ret);
auto error = SSL_get_error(ssl.get(), res);
if(HandleError(error)) {
lastError = SSL_ERROR_NONE;
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/socket_tls_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct SocketTlsImpl : public SocketImpl
Duration timeout);
void Shutdown();

bool HandleResult(int ret);
bool HandleResult(int res);
bool HandleLastError();
bool HandleError(int error);
};
Expand Down

0 comments on commit 7676945

Please sign in to comment.