tur/net
stdlib/net.tur
stub networking type (Socket) for linear resource tracking.
Since: Phase LT4
defstruct
linear
Socket
(defstruct Socket :linear [fd :int])
a linear (exactly-once) wrapper around a POSIX socket fd.
Since: LT4
defn
socket-fd
(socket-fd [s : Socket] :int)
return the raw file descriptor from a Socket.
Parameters
| s | a Socket value. |
Returns
The underlying file descriptor (int).
Example
(socket-fd my-socket) ; => 5
Since: LT4
defn
socket-valid?
(socket-valid? [s : Socket] :bool)
return true if the Socket wraps a non-negative fd.
Parameters
| s | a Socket value. |
Returns
true if fd >= 0, false otherwise.
Example
(socket-valid? my-socket) ; => true
Since: LT4
defn
socket-close
(socket-close [s : Socket] :int)
close a Socket and release the underlying fd.
Parameters
| s | a Socket to close (by value; handle is consumed). |
Returns
0 on success, -1 on error.
Example
(socket-close my-socket) ; => 0
Since: LT4