nemasu / asmttpd

Web server for Linux written in amd64 assembly.
GNU General Public License v2.0
3.03k stars 199 forks source link

Program cannot be restarted right away after exiting if clients have connected. #31

Closed nemasu closed 7 years ago

nemasu commented 7 years ago

Listening socket isn't closed when program exists.

triforce commented 7 years ago

Do we need to use a shutdown before the sys_close call?

nemasu commented 7 years ago

Ah my bad, I think instead of using shutdown, we just need to add the flag SO_REUSEADDR to the bind port.

triforce commented 7 years ago

So we will need a new syscall to SYS_SETSOCKOPT with rdx = SO_REUSEADDR after sys_create_tcp_socket.

The pointer to 1 might be an issue as the stack isn't setup the same as it is for the cork syscalls so may need to make use of some r registers to save the rbp/rsp?

nemasu commented 7 years ago

I've changed it to use bss data instead of stack, and it's calling the correct functions successfully (SO_REUSEADDR), but I still get the bind error when I close it after a client connects.

nemasu commented 7 years ago

Ah, I figured it out, need to call REUSEADDR before bind, not after. :)