Skip to content

Commit

Permalink
Fix socket wait with OpenSSL 3.0.14
Browse files Browse the repository at this point in the history
IB-8121

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma committed Jul 16, 2024
1 parent 2b5db85 commit 677a121
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/crypto/Connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Connect::Connect(const string &_url, string _method, int _timeout, const vector<

BIO_set_nbio(d, _timeout > 0);
auto start = chrono::high_resolution_clock::now();
#if OPENSSL_VERSION_NUMBER < 0x30000000L
while(BIO_do_connect(d) != 1)
{
if(_timeout == 0)
Expand All @@ -122,6 +123,10 @@ Connect::Connect(const string &_url, string _method, int _timeout, const vector<
THROW_NETWORKEXCEPTION("Failed to create connection with host timeout: '%s'", hostname.c_str())
this_thread::sleep_for(chrono::milliseconds(50));
}
#else
if(BIO_do_connect_retry(d, timeout, -1) < 1)
THROW_NETWORKEXCEPTION("Failed to create connection with host timeout: '%s'", hostname.c_str())
#endif

if(usessl > 0)
{
Expand Down Expand Up @@ -179,9 +184,11 @@ Connect::Connect(const string &_url, string _method, int _timeout, const vector<
}
}

#if OPENSSL_VERSION_NUMBER < 0x30000000L
if(int fd = BIO_get_fd(d, nullptr);
_timeout > 0 && BIO_socket_wait(fd, BIO_should_read(d), _timeout) == -1)
DEBUG("select failed");
#endif

BIO_printf(d, "%s %s HTTP/1.1\r\n", method.c_str(), path.c_str());
addHeader("Connection", "close");
Expand Down Expand Up @@ -333,7 +340,8 @@ Connect::Result Connect::exec(initializer_list<pair<string_view,string_view>> he

if(!r.isRedirect() || recursive > 3)
return r;
string url = r.headers["Location"].find("://") != string::npos ? r.headers["Location"] : baseurl + r.headers["Location"];
string location = r.headers.find("Location") == r.headers.cend() ? r.headers["location"] : r.headers["Location"];
string url = location.find("://") != string::npos ? location : baseurl + location;
Connect c(url, method, timeout);
c.recursive = recursive + 1;
return c.exec(headers);
Expand Down

0 comments on commit 677a121

Please sign in to comment.