Refactored the interface of the io package

This commit is contained in:
2025-04-07 18:02:36 +02:00
parent 08ea91f46c
commit a9d783c675
12 changed files with 29 additions and 35 deletions

View File

@ -6,30 +6,30 @@ main() {
socket := sys.socket(2, 1, 0)
if socket < 0 {
io.error("socket error\n")
io.write("socket error\n")
sys.exit(1)
}
if net.bind(socket, 8080) != 0 {
io.error("bind error\n")
io.write("bind error\n")
sys.exit(1)
}
if sys.listen(socket, 128) != 0 {
io.error("listen error\n")
io.write("listen error\n")
sys.exit(1)
}
io.out("listening...\n")
io.write("listening...\n")
loop {
conn := sys.accept(socket, 0, 0)
if conn >= 0 {
io.write(conn, "HTTP/1.0 200 OK\r\nContent-Length: 6\r\n\r\nHello\n")
io.writeTo(conn, "HTTP/1.0 200 OK\r\nContent-Length: 6\r\n\r\nHello\n")
sys.close(conn)
} else {
io.error("accept error\n")
io.write("accept error\n")
}
}
}