srctree

Robin Linden parent 97e4b8d9 a3de5603
net: Fix crash on ssl handshake failure

This patch switches from the asio handshake method that propagatesfailure by throwing to the one that sets an error_code.

inlinesplit
net/socket.cpp added: 6, removed: 3, total 3
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2021 Mikael Larsson <c.mikael.larsson@gmail.com>
// SPDX-FileCopyrightText: 2023 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -93,10 +94,12 @@ std::string Socket::read_bytes(std::size_t bytes) {
}
 
struct SecureSocket::Impl : public BaseSocketImpl {
// TODO(robinlinden): Better error propagation.
bool connect(std::string_view host, std::string_view service) {
if (BaseSocketImpl::connect(resolver, socket.next_layer(), host, service)) {
socket.handshake(asio::ssl::stream_base::handshake_type::client);
return true;
asio::error_code ec;
socket.handshake(asio::ssl::stream_base::handshake_type::client, ec);
return !ec;
}
return false;
}