mirror of
https://github.com/janet-lang/janet
synced 2025-09-04 20:08:04 +00:00
Add methods to streams.
This makes streams polymorphic with files in many cases. printf family functions still need porting.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
(defn handler
|
||||
"Simple handler for connections."
|
||||
[stream]
|
||||
(def id (gensym))
|
||||
(def b @"")
|
||||
(print "Connection " id "!")
|
||||
(while (net/read stream 1024 b)
|
||||
(net/write stream b)
|
||||
(buffer/clear b))
|
||||
(printf "Done %v!" id)
|
||||
(net/close 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)))
|
||||
|
||||
(net/server "127.0.0.1" "8000" handler)
|
||||
|
Reference in New Issue
Block a user