mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00

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. :^)
25 lines
804 B
C++
25 lines
804 B
C++
#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();
|
|
}
|