1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00
serenity/Applications/Downloader/main.cpp
Andreas Kling 6d5a54690e 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. :^)
2019-04-08 04:56:11 +02:00

30 lines
905 B
C++

#include <LibGUI/GApplication.h>
#include <LibGUI/GHttpRequest.h>
#include <LibGUI/GHttpResponse.h>
#include <LibGUI/GNetworkJob.h>
#include <stdio.h>
int main(int argc, char** argv)
{
GApplication app(argc, argv);
GHttpRequest request;
request.set_hostname("www.google.com");
request.set_path("/");
auto job = request.schedule();
job->on_finish = [&job] (bool success) {
if (!success) {
dbgprintf("on_finish: request failed :(\n");
return;
}
auto& response = static_cast<const GHttpResponse&>(*job->response());
printf("%s{%p}: on_receive: code=%d\n", job->class_name(), job, response.code());
//printf("payload:\n");
//printf("%s", response.payload().pointer());
printf("payload was %d bytes\n", response.payload().size());
};
printf("Entering main loop...\n");
return app.exec();
}