mirror of
https://github.com/janet-lang/janet
synced 2025-09-03 19:38:04 +00:00
Update ev.c with workaround for failing chat server.
2 issues: - With poll backend, we were polling for writes even after we finished writing. Presents as wasting a lot of CPU. - Fixes strange closing behavior of chat server.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
(defn handler
|
||||
[connection]
|
||||
(print "created " connection)
|
||||
(print "connection: " connection)
|
||||
(net/write connection "Whats your name?\n")
|
||||
(def name (string/trim (string (ev/read connection 100))))
|
||||
(print name " connected")
|
||||
@@ -23,13 +23,14 @@
|
||||
(put conmap name nil)
|
||||
(:close connection))
|
||||
(while (def msg (ev/read connection 100))
|
||||
(broadcast name (string msg)))
|
||||
(broadcast name (string msg)))
|
||||
(print name " disconnected")))))
|
||||
|
||||
(defn main [& args]
|
||||
(printf "STARTING SERVER...")
|
||||
(flush)
|
||||
(def my-server (net/listen "127.0.0.1" "8000"))
|
||||
'(handler (net/accept my-server))
|
||||
(forever
|
||||
(def connection (net/accept my-server))
|
||||
(ev/call handler connection)))
|
||||
|
Reference in New Issue
Block a user