tur/fd
stdlib/fd.tur
Fd: an opaque newtype over a POSIX file descriptor.
Since: stdlib-opaque-handle-types-plan, I/O sweep
defopaque
Fd
(Fd)
defn
fd->int
(fd->int [fd : Fd] :)
recover the raw :int file descriptor from an Fd.
Parameters
| fd | the Fd handle to unwrap |
Returns
The underlying file descriptor as a plain :int.
Example
(if (< (fd->int fd) 0) (handle-error))
Since: I/O sweep
defn
int->fd
(int->fd [n : int] :)
wrap a raw :int file descriptor as an Fd.
Parameters
| n | a raw file descriptor (e.g. 0/1/2 for stdin/stdout/stderr) |
Returns
An Fd wrapping n.
Example
(def stdin-fd (int->fd 0))
Since: I/O sweep
defn
fd-valid?
(fd-valid? [fd : Fd] :)
return true if the Fd is a real descriptor (>= 0).
Parameters
| fd | the Fd handle to test |
Returns
true when the underlying fd is non-negative; false for the -1 error value.
Example
(let [fd (async-socket-accept listen)]
(when (fd-valid? fd) (serve fd)))
Since: I/O sweep