http server

This commit is contained in:
agra
2026-02-17 19:26:43 +02:00
parent 4fd87309d9
commit 4aff004118
8 changed files with 356 additions and 84 deletions

View File

@@ -15,15 +15,9 @@ main :: () -> s32 {
opt : s32 = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, @opt, 4);
addr := SockAddr.{
sin_len = 16,
sin_family = 2,
sin_port = htons(PORT),
sin_addr = 0,
sin_zero = 0
};
addr := SockAddr.{ sin_len = 16, sin_family = 2, sin_port = htons(PORT) };
if bind(fd, @addr, 16) < 0 {
if bind(fd, addr, 16) < 0 {
print("error: bind()\n");
return 1;
}
@@ -40,8 +34,8 @@ main :: () -> s32 {
if client < 0 { continue; }
// Read request
buf := alloc(4096);
read(client, buf, 4096);
buf : [4096]u8 = ---;
read(client, buf, buf.len);
// Send response
body := "<html><body><h1>Hello from sx!</h1></body></html>";