1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-29 14:47:42 +00:00

Add backpressure capability to net.

This commit is contained in:
Calvin Rose
2020-05-31 15:46:01 -05:00
parent 71d8e6b4cd
commit 3f434f2a44
2 changed files with 79 additions and 18 deletions

View File

@@ -1,14 +1,19 @@
(defn handler
"Simple handler for connections."
[stream]
(defer (:close stream)
(def id (gensym))
(def b @"")
(print "Connection " id "!")
(while (:read stream 1024 b)
(:write stream b)
(buffer/clear b))
(printf "Done %v!" id)))
(def id (gensym))
(def b @"")
(print "Connection " id "!")
(while (:read stream 1024 b)
(:write stream b)
(buffer/clear b))
(printf "Done %v!" id))
(print "Starting echo server on 127.0.0.1:8000")
(net/server "127.0.0.1" "8000" handler)
(def server (net/server "127.0.0.1" "8000"))
# Run server.
(while true
(with [conn (:accept server)]
(handler conn)))