1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +00:00

LibGUI: Make GSocket connection asynchronous.

Now connect() will return immediately. Later on, when the socket is actually
connected, it will call GSocket::on_connected from the event loop. :^)
This commit is contained in:
Andreas Kling 2019-04-08 04:53:45 +02:00
parent 65d6318c33
commit 6d5a54690e
11 changed files with 65 additions and 29 deletions

View file

@ -13,19 +13,14 @@ GHttpJob::~GHttpJob()
{
}
void GHttpJob::start()
void GHttpJob::on_socket_connected()
{
ASSERT(!m_socket);
m_socket = new GTCPSocket(this);
int success = m_socket->connect(m_request.hostname(), m_request.port());
if (!success)
return did_fail(GNetworkJob::Error::ConnectionFailed);
auto raw_request = m_request.to_raw_request();
#if 0
printf("raw_request:\n%s\n", String::from_byte_buffer(raw_request).characters());
#endif
printf("raw_request:\n%s\n", raw_request.pointer());
success = m_socket->send(raw_request);
bool success = m_socket->send(raw_request);
if (!success)
return deferred_invoke([this](auto&){ did_fail(GNetworkJob::Error::TransmissionFailed); });
@ -99,3 +94,16 @@ void GHttpJob::start()
did_finish(move(response));
});
}
void GHttpJob::start()
{
ASSERT(!m_socket);
m_socket = new GTCPSocket(this);
m_socket->on_connected = [this] {
printf("Socket on_connected callback\n");
on_socket_connected();
};
bool success = m_socket->connect(m_request.hostname(), m_request.port());
if (!success)
return did_fail(GNetworkJob::Error::ConnectionFailed);
}