Implemented length storage of allocated memory
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
// Open server and client in 2 terminals:
|
||||
// [1] q run examples/server
|
||||
// [2] curl http://127.0.0.1:8080
|
||||
import io
|
||||
import net
|
||||
import sys
|
||||
|
||||
@ -8,30 +9,30 @@ main() {
|
||||
socket := sys.socket(2, 1, 0)
|
||||
|
||||
if socket < 0 {
|
||||
sys.write(1, "socket error\n", 13)
|
||||
io.error("socket error\n")
|
||||
sys.exit(1)
|
||||
}
|
||||
|
||||
if net.bind(socket, 8080) != 0 {
|
||||
sys.write(1, "bind error\n", 11)
|
||||
io.error("bind error\n")
|
||||
sys.exit(1)
|
||||
}
|
||||
|
||||
if sys.listen(socket, 128) != 0 {
|
||||
sys.write(1, "listen error\n", 13)
|
||||
io.error("listen error\n")
|
||||
sys.exit(1)
|
||||
}
|
||||
|
||||
sys.write(1, "listening...\n", 13)
|
||||
io.out("listening...\n")
|
||||
|
||||
loop {
|
||||
conn := sys.accept(socket, 0, 0)
|
||||
|
||||
if conn >= 0 {
|
||||
sys.write(conn, "HTTP/1.0 200 OK\r\nContent-Length: 6\r\n\r\nHello\n", 44)
|
||||
io.write(conn, "HTTP/1.0 200 OK\r\nContent-Length: 6\r\n\r\nHello\n")
|
||||
sys.close(conn)
|
||||
} else {
|
||||
sys.write(1, "error\n", 6)
|
||||
io.error("accept error\n")
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user