Introduced more logging calls.
Build and Test Module / build-and-test (push) Has been cancelled Details

This commit is contained in:
Andrew Lalis 2025-05-29 22:52:43 -04:00
parent 905e3f93f8
commit 93d983424e
3 changed files with 12 additions and 9 deletions

View File

@ -6,7 +6,8 @@
"dependencies": { "dependencies": {
"handy-http-primitives": "~>1.6", "handy-http-primitives": "~>1.6",
"photon": "~>0.10", "photon": "~>0.10",
"streams": "~>3.6" "streams": "~>3.6",
"slf4d": "~>4.0"
}, },
"description": "Implementations of HTTP transport protocols.", "description": "Implementations of HTTP transport protocols.",
"license": "CC0", "license": "CC0",

View File

@ -4,6 +4,7 @@
"handy-http-primitives": "1.6.0", "handy-http-primitives": "1.6.0",
"photon": "0.10.2", "photon": "0.10.2",
"sharded-map": "2.7.0", "sharded-map": "2.7.0",
"slf4d": "4.0.0",
"streams": "3.6.0" "streams": "3.6.0"
} }
} }

View File

@ -10,6 +10,7 @@ import handy_http_primitives;
import handy_http_primitives.address; import handy_http_primitives.address;
import streams; import streams;
import slf4d;
import photon; import photon;
/** /**
@ -30,12 +31,14 @@ class Http1Transport : HttpTransport {
} }
void start() { void start() {
debugF!"Starting HTTP1Transport server on port %d."(port);
startloop(); startloop();
go(() => runServer()); go(() => runServer());
runFibers(); runFibers();
} }
void stop() { void stop() {
debugF!"Stopping HTTP1Transport server on port %d."(port);
this.running = false; this.running = false;
this.serverSocket.shutdown(SocketShutdown.BOTH); this.serverSocket.shutdown(SocketShutdown.BOTH);
this.serverSocket.close(); this.serverSocket.close();
@ -45,14 +48,14 @@ class Http1Transport : HttpTransport {
this.running = true; this.running = true;
serverSocket.setOption(SocketOptionLevel.SOCKET, SocketOption.REUSEADDR, 1); serverSocket.setOption(SocketOptionLevel.SOCKET, SocketOption.REUSEADDR, 1);
serverSocket.bind(new InternetAddress("127.0.0.1", port)); serverSocket.bind(new InternetAddress("127.0.0.1", port));
traceF!"Bound to %s."(serverSocket.localAddress().toString());
serverSocket.listen(100); serverSocket.listen(100);
while (running) { while (running) {
try { try {
Socket clientSocket = serverSocket.accept(); Socket clientSocket = serverSocket.accept();
go(() => handleClient(clientSocket, requestHandler)); go(() => handleClient(clientSocket, requestHandler));
} catch (SocketAcceptException e) { } catch (SocketAcceptException e) {
import std.stdio; warn("Failed to accept socket connection.", e);
stderr.writefln!"Failed to accept socket connection: %s"(e);
} }
} }
} }
@ -73,10 +76,10 @@ void handleClient(Socket clientSocket, HttpRequestHandler requestHandler) {
// Get remote address from the socket. // Get remote address from the socket.
import handy_http_primitives.address; import handy_http_primitives.address;
ClientAddress addr = getAddress(clientSocket); ClientAddress addr = getAddress(clientSocket);
traceF!"Handling client request from %s."(addr.toString());
auto result = readHttpRequest(&bufferedInput, addr); auto result = readHttpRequest(&bufferedInput, addr);
if (result.hasError) { if (result.hasError) {
import std.stdio; warnF!"Failed to read HTTP request: %s"(result.error.message);
stderr.writeln("Failed to read HTTP request: " ~ result.error.message);
inputStream.closeStream(); inputStream.closeStream();
return; return;
} }
@ -90,11 +93,9 @@ void handleClient(Socket clientSocket, HttpRequestHandler requestHandler) {
try { try {
requestHandler.handle(request, response); requestHandler.handle(request, response);
} catch (Exception e) { } catch (Exception e) {
import std.stdio; error("Exception thrown while handling request.", e);
stderr.writeln("Exception thrown while handling request: " ~ e.msg);
} catch (Throwable t) { } catch (Throwable t) {
import std.stdio; errorF!"Throwable error while handling request: %s"(t.msg);
stderr.writeln("Throwable error while handling request: " ~ t.msg);
throw t; throw t;
} }