1
0
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:
Calvin Rose
2024-09-06 00:00:09 -05:00
parent 5f70a85f7e
commit f553c5da47
2 changed files with 14 additions and 2 deletions

View File

@@ -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)))