diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2021-09-12 11:55:40 +0000 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-12-16 22:21:35 +0330 |
commit | dfdb52efa753d21767492eb1e812245a2141c82e (patch) | |
tree | dbf22ebd3b69670eba6a5ed6bc74278b902682a1 /Userland/Services/WebServer/main.cpp | |
parent | 2341b0159a7ed86f4665df21df1357c16f3081f3 (diff) | |
download | serenity-dfdb52efa753d21767492eb1e812245a2141c82e.zip |
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.
Diffstat (limited to 'Userland/Services/WebServer/main.cpp')
-rw-r--r-- | Userland/Services/WebServer/main.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
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<int> 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(); }; |