LibCore+LibHTTP: Check the status of the socket after EINPROGRESS

Previously the system would assume the socket was connected after the
file descriptor became writeable. Just because the fd is signaled as
ready for output does not necessarily indicate the socket is connected.
Instead, we should check the status of the socket with SO_ERROR and
handle successes/errors accordingly.
This commit is contained in:
brapru 2021-08-12 11:28:19 -04:00 committed by Ali Mohammad Pur
commit d456af1cd3
Notes: sideshowbarker 2024-07-18 07:01:38 +09:00
3 changed files with 30 additions and 6 deletions

View file

@ -20,6 +20,12 @@ void HttpJob::start()
dbgln_if(CHTTPJOB_DEBUG, "HttpJob: on_connected callback");
on_socket_connected();
};
m_socket->on_error = [this] {
dbgln_if(CHTTPJOB_DEBUG, "HttpJob: on_error callback");
deferred_invoke([this](auto&) {
did_fail(Core::NetworkJob::Error::ConnectionFailed);
});
};
bool success = m_socket->connect(m_request.url().host(), m_request.url().port());
if (!success) {
deferred_invoke([this](auto&) {