acompiled

The catalog contains seeded project examples. Your workspace stores your own projects and conversations.

zeroeight/tiny-http

Public
Star9

An HTTP/1.0 server for Linux in x86-64 assembly. No libc; every build starts it and curls it.

SO_REUSEADDR, so a restart doesn't wait out TIME_WAIT

Browse files
zeroeightcommitted 1 parent 39e4cf8 commit 490b1a78c0cefb1286d372761858defb29204d06
failing 3 steps in 3.15 s
1 file changed +13−0
modified src/server.asm +13−0
@@ -17,10 +17,13 @@
1717 %define SYS_SENDTO 44
1818 %define SYS_BIND 49
1919 %define SYS_LISTEN 50
20+%define SYS_SETSOCKOPT 54
2021 %define SYS_EXIT 60
2122
2223 %define AF_INET 2
2324 %define SOCK_STREAM 1
25+%define SOL_SOCKET 1
26+%define SO_REUSEADDR 2
2427 %define MSG_NOSIGNAL 0x4000 ; a client that hangs up must not kill us
2528
2629 %define REQUEST_MAX 4096
@@ -66,6 +69,14 @@ _start:
6669 js fail_socket
6770 mov r12d, eax ; r12 = the listening socket, for good
6871
72+ mov eax, SYS_SETSOCKOPT ; restart without waiting out TIME_WAIT
73+ mov edi, r12d
74+ mov esi, SOL_SOCKET
75+ mov edx, SO_REUSEADDR
76+ lea r10, [one]
77+ mov r8d, 4
78+ syscall
79+
6980 mov eax, SYS_BIND
7081 mov edi, r12d
7182 lea rsi, [addr]
@@ -216,6 +227,8 @@ routes: ; path status content type body
216227 garbled_route:
217228 dq 0, 0, bad, bad.len, plain, plain.len, garbled, garbled.len
218229
230+one: dd 1
231+
219232 text ok, "HTTP/1.0 200 OK", 13, 10
220233 text missing, "HTTP/1.0 404 Not Found", 13, 10
221234 text bad, "HTTP/1.0 400 Bad Request", 13, 10