No matching definitions.

tur/async_socket

stdlib/async_socket.tur

non-blocking TCP socket I/O for the cooperative scheduler.

Since: Phase T24

defn

async-socket-listen

(async-socket-listen [port :int backlog :int])

create a non-blocking TCP listening socket on the given port.

portTCP port number to bind and listen on
backlogmaximum length of the pending connection queue

int -- the listen file descriptor, or -1 on error

(async-socket-listen 8080 128)  ; => 4

Since: Phase T24

defn

async-socket-accept

(async-socket-accept [listen-fd :int])

accept an incoming connection, parking the fiber until one arrives.

listen-fdlistening 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

defn

async-socket-connect

(async-socket-connect [host :cstr port :int])

connect to a TCP server at host:port, parking the fiber until complete.

hostIPv4 address string (e.g. "127.0.0.1")
portTCP 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

defn

async-socket-send

(async-socket-send [fd :int data :cstr len :int])

send data on a connected socket, parking the fiber on EAGAIN.

fdconnected socket file descriptor
datapointer to the bytes to send
lennumber 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

defn

async-socket-recv

(async-socket-recv [fd :int buf-size :int])

receive up to buf-size bytes from a connected socket.

fdconnected socket file descriptor
buf-sizemaximum 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

defn

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

defn

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

defn

async-socket-close

(async-socket-close [fd :int])

close a socket and unregister it from IO polling.

fdsocket file descriptor to close
(async-socket-close fd)

Since: Phase T24