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

ProtocolServer+LibProtocol: Introduce a server for handling downloads

This patch adds ProtocolServer, a server that handles network requests
on behalf of its clients. The first protocol implemented is HTTP.

The idea here is to use a plug-in architecture where any number of
protocols can be added and implemented without having to mess around
with each client program that wants to use the protocol.

A simple client API is provided through LibProtocol::Client. :^)
This commit is contained in:
Andreas Kling 2019-11-23 21:45:33 +01:00
parent 61f611bf3c
commit fd4349a9f2
21 changed files with 475 additions and 0 deletions

View file

@ -0,0 +1,25 @@
#include <LibCore/CEventLoop.h>
#include <LibCore/CLocalServer.h>
#include <LibCore/CoreIPCServer.h>
#include <ProtocolServer/HttpProtocol.h>
#include <ProtocolServer/PSClientConnection.h>
int main(int, char**)
{
CEventLoop event_loop;
(void)*new HttpProtocol;
auto server = CLocalServer::construct();
unlink("/tmp/psportal");
server->listen("/tmp/psportal");
server->on_ready_to_accept = [&] {
auto client_socket = server->accept();
if (!client_socket) {
dbg() << "ProtocolServer: accept failed.";
return;
}
static int s_next_client_id = 0;
int client_id = ++s_next_client_id;
IPC::Server::new_connection_ng_for_client<PSClientConnection>(*client_socket, client_id);
};
return event_loop.exec();
}