#net_async
#connect
connect : (host : String) -> Int -> Async <Clock, Net host | e> (Result String (Connection host))
connect host portConnects to host on port, parking until the handshake finishes
instead of blocking the thread.
The returned socket is already non-blocking. Resolving host still
blocks; only the handshake parks, which is the wait an unreachable or
overloaded peer makes unbounded. On every failure the socket is closed
before the Err is returned, so the caller has nothing to release.
#connectWithin
connectWithin : Duration -> (host : String) -> Int -> Async <Clock, Net host | e> (Result String (Connection host))
connectWithin d host portconnect that gives up after d with Err "timed out".
#accept
accept : Listener a -> Async <Clock, Net a | e> (Result String (Connection a))
accept lisAccepts the next connection, parking until one arrives. The listener and the accepted socket are switched to non-blocking mode.
The connection is at the listener's authority: it is reached through the address the listener was granted.
#recv
recv : Connection h -> Int -> Async <Clock, Net h | e> (Result String Bytes)
recv conn nReceives up to n bytes, parking until some arrive.
The result is sized to what arrived, not to n. An empty result is end
of stream.
#recvWithin
recvWithin : Duration -> Connection h -> Int -> Async <Clock, Net h | e> (Result String Bytes)
recvWithin d conn nrecv that gives up after d with Err "timed out".
#send
send : Connection h -> Bytes -> Async <Clock, Net h | e> (Result String Int)
send conn bytesSends what the socket will take now, parking until it takes some.
The count may be short; sendAll loops.
#sendAll
sendAll : Connection h -> Bytes -> Async <Clock, Net h | e> (Result String Unit)
sendAll conn bytesSends every byte, parking as needed.
#sendAllWithin
sendAllWithin : Duration -> Connection h -> Bytes -> Async <Clock, Net h | e> (Result String Unit)
sendAllWithin d conn bytessendAll that gives up after d with Err "timed out".
#sendString
sendString : Connection h -> String -> Async <Clock, Net h | e> (Result String Unit)
sendString conn sSends a string as UTF-8, parking as needed.
#close
close : Connection h -> Async <Net h | e> (Result String Unit)
close connCloses a connection.
#closeListener
closeListener : Listener a -> Async <Net a | e> (Result String Unit)
closeListener lisCloses a listener. A task parked in accept on it wakes with an error,
which ends a serve loop.
#serve
serve : Listener a -> (Connection a -> Async <Clock, Net a | e> (Result String Unit)) -> Async <Clock, Net a | e> (Result String Unit)
serve lis handleAccepts connections until accept fails, running handle on each in
a task of its own and closing the connection when the handler finishes.
A failure in handle closes that connection and the loop continues. A
failure in accept, including the listener being closed, ends the loop
with the error.