tur/async_socket
non-blocking TCP socket I/O for the cooperative scheduler.
Since: Phase T24
async-socket-listen
(async-socket-listen [port :int backlog :int])
create a non-blocking TCP listening socket on the given port.
| port | TCP port number to bind and listen on | |
| backlog | maximum length of the pending connection queue |
int -- the listen file descriptor, or -1 on error
(async-socket-listen 8080 128) ; => 4
Since: Phase T24
async-socket-accept
(async-socket-accept [listen-fd :int])
accept an incoming connection, parking the fiber until one arrives.
| listen-fd | listening file descriptor returned by async-socket-listen |
int -- the accepted client file descriptor, or -1 on error
(async-socket-accept listen-fd) ; => 7
Since: Phase T24
async-socket-connect
(async-socket-connect [host :cstr port :int])
connect to a TCP server at host:port, parking the fiber until complete.
| host | IPv4 address string (e.g. "127.0.0.1") | |
| port | TCP port number to connect to |
int -- the connected file descriptor, or -1 on error
(async-socket-connect "127.0.0.1" 8080) ; => 5
Since: Phase T24
async-socket-send
(async-socket-send [fd :int data :cstr len :int])
send data on a connected socket, parking the fiber on EAGAIN.
| fd | connected socket file descriptor | |
| data | pointer to the bytes to send | |
| len | number of bytes to send |
int -- total bytes sent, or -1 on error
(async-socket-send fd "GET / HTTP/1.0\r\n" 16) ; => 16
Since: Phase T24
async-socket-recv
(async-socket-recv [fd :int buf-size :int])
receive up to buf-size bytes from a connected socket.
| fd | connected socket file descriptor | |
| buf-size | maximum number of bytes to receive |
int -- bytes received (> 0), 0 on connection close, -1 on error
(async-socket-recv fd 4096) ; => 256
Since: Phase T24
async-socket-recv-buf
(async-socket-recv-buf)
retrieve the buffer pointer from the last async-socket-recv call.
ptr<void> -- pointer to the receive buffer in fiber-local storage (caller must free)
(async-socket-recv-buf) ; => buf-ptr
Since: Phase T24
async-socket-recv-len
(async-socket-recv-len)
retrieve the byte count from the last async-socket-recv call.
int -- number of bytes received in the most recent async-socket-recv
(async-socket-recv-len) ; => 256
Since: Phase T24
async-socket-close
(async-socket-close [fd :int])
close a socket and unregister it from IO polling.
| fd | socket file descriptor to close |
(async-socket-close fd)
Since: Phase T24