From dfdb52efa753d21767492eb1e812245a2141c82e Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sun, 12 Sep 2021 11:55:40 +0000 Subject: 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. --- Userland/Services/WebServer/main.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Userland/Services/WebServer/main.cpp') diff --git a/Userland/Services/WebServer/main.cpp b/Userland/Services/WebServer/main.cpp index eb032eec3b..d78aef0fbb 100644 --- a/Userland/Services/WebServer/main.cpp +++ b/Userland/Services/WebServer/main.cpp @@ -72,9 +72,20 @@ ErrorOr serenity_main(Main::Arguments arguments) auto server = TRY(Core::TCPServer::try_create()); server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - VERIFY(client_socket); - auto client = WebServer::Client::construct(client_socket.release_nonnull(), server); + auto maybe_client_socket = server->accept(); + if (maybe_client_socket.is_error()) { + warnln("Failed to accept the client: {}", maybe_client_socket.error()); + return; + } + + auto maybe_buffered_socket = Core::Stream::BufferedTCPSocket::create(maybe_client_socket.release_value()); + if (maybe_buffered_socket.is_error()) { + warnln("Could not obtain a buffered socket for the client: {}", maybe_buffered_socket.error()); + return; + } + + VERIFY(!maybe_buffered_socket.value().set_blocking(true).is_error()); + auto client = WebServer::Client::construct(maybe_buffered_socket.release_value(), server); client->start(); }; -- cgit v1.2.3