1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-16 07:17:16 +00:00

Add net/listen and net/accept-loop.

These are the elements that make up net/server, which has been moved
into pure Janet instead.
This commit is contained in:
Calvin Rose
2020-11-09 11:18:09 -06:00
parent 099a912992
commit 6f1d5d3b73
2 changed files with 49 additions and 28 deletions

View File

@@ -2722,6 +2722,28 @@
:on-status (or onsignal (make-onsignal env 1))
:source "repl"}))
###
###
### Extras
###
###
(defmacro- guarddef
[sym form]
(if (dyn sym)
form))
(guarddef net/listen
(defn net/server
"Start a server asynchornously with net/listen and net/accept-loop. Returns the new server stream."
[host port &opt handler type]
(def s (net/listen host port type))
(if handler
(ev/go (fn [] (net/accept-loop s handler))))
s))
(undef guarddef)
###
###
### CLI Tool Main