1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

LibCore+Userland: Convert TCPServer to use the Serenity Stream API

This is intended as a real-usecase test of the Serenity Stream API, and
seemed like a good candidate due to its low amount of users.
This commit is contained in:
sin-ack 2021-09-12 11:55:40 +00:00 committed by Ali Mohammad Pur
parent 2341b0159a
commit dfdb52efa7
11 changed files with 263 additions and 124 deletions

View file

@ -52,15 +52,15 @@ int main(int argc, char** argv)
server->on_ready_to_accept = [&next_id, &clients, &server] {
int id = next_id++;
auto client_socket = server->accept();
if (!client_socket) {
perror("accept");
auto maybe_client_socket = server->accept();
if (maybe_client_socket.is_error()) {
warnln("accept: {}", maybe_client_socket.error());
return;
}
outln("Client {} connected", id);
auto client = Client::create(id, move(client_socket));
auto client = Client::create(id, maybe_client_socket.release_value());
client->on_exit = [&clients, id] {
Core::deferred_invoke([&clients, id] {
clients.remove(id);