extract function

main
Daniel Barlow 2022-07-03 11:09:02 +01:00
parent 60d4466857
commit 67e03c6736
1 changed files with 7 additions and 7 deletions

View File

@ -20,6 +20,12 @@
(on-connected connected-fd))) (on-connected connected-fd)))
)) ))
(fn get-input [fd]
(let [buf (unistd.read fd 1024)]
(if (and buf (> (# buf) 0))
buf
"\n,exit")))
(fn start [pathname] (fn start [pathname]
(unistd.unlink pathname) (unistd.unlink pathname)
(unix-socket-listener (unix-socket-listener
@ -29,17 +35,11 @@
repl-coro (coroutine.create repl)] repl-coro (coroutine.create repl)]
(watch-fd fd fcntl.O_RDONLY (watch-fd fd fcntl.O_RDONLY
(fn [fd] (fn [fd]
(let [buf (unistd.read fd 1024) (coroutine.resume repl-coro (get-input fd))
input
(if (and buf (> (# buf) 0))
buf
"\n,exit")]
(coroutine.resume repl-coro input))
(if (= (coroutine.status repl-coro) :dead) (if (= (coroutine.status repl-coro) :dead)
(do (do
(sock:write "bye!\n") (sock:write "bye!\n")
(sock:close) (sock:close)
(unistd.close fd)
false) false)
true true
))) )))