Module
whiplash/socket
src/whiplash/socket.pookaThe socket is an opaque handle. This bridge only asks OTP to move bytes, transfer ownership, and tell the time; HTTP and process policy live in Pooka.
API reference
- classSocket
- functionlisten
- functionaccept
- functionconnect
- functionrecv
- functionidle
- functiondoze
- functionsend
- functionsend_parts
- functiontransfer
- functionclose
- functionport
- functionunique
- functionnow
- functionarm
- functionevents
- functionlisten_tls
- functionconnect_tls
- functionnegotiated
- functionpassive
- functionsend_file
- functioncredit
- functiondate
class Socket
listen(address: String, port: Int) -> Result(Socket, String)
fn(String, Int) -> Result(whiplash/socket.Socket, String)Listen for TCP connections on address (an IPv4 or IPv6 address).
accept(listener: Socket) -> Result(Socket, String)
fn(whiplash/socket.Socket) -> Result(whiplash/socket.Socket, String)connect(port: Int) -> Result(Socket, String)
fn(Int) -> Result(whiplash/socket.Socket, String)recv(socket: Socket, timeout: Int) -> Result(BitArray, String)
fn(whiplash/socket.Socket, Int) -> Result(BitArray, String)idle(
socket: Socket,
wait: Int,
left: Int,
resume: fn(Result(BitArray, String)) -> Nil
) -> Nil
fn(whiplash/socket.Socket, Int, Int, fn(Result(BitArray, String)) -> Nil) -> NilWait up to left milliseconds for bytes, then call resume with what
came. After wait quiet milliseconds the process hibernates, so an idle
keep-alive connection holds little memory. Hibernation discards the call
stack: this must be the caller's last call, and resume carries on.
doze(left: Int, resume: fn(Bool) -> Nil) -> Nil
fn(Int, fn(Bool) -> Nil) -> NilHibernate until a message arrives or left milliseconds pass, then call
resume with whether the time ran out. For a process that takes all its
events from its mailbox; like idle, it must be the caller's last call.
send(socket: Socket, head: BitArray, body: BitArray) -> Result(Nil, String)
fn(whiplash/socket.Socket, BitArray, BitArray) -> Result(Nil, String)send_parts(socket: Socket, head: BitArray, parts: List(BitArray)) -> Result(
Nil,
String
)
fn(whiplash/socket.Socket, BitArray, List(BitArray)) -> Result(Nil, String)Send head, then each part in order, in one write without joining them.
transfer(socket: Socket, owner: Pid) -> Result(Nil, String)
fn(whiplash/socket.Socket, Pid) -> Result(Nil, String)close(socket: Socket) -> Nil
fn(whiplash/socket.Socket) -> Nilport(socket: Socket) -> Result(Int, String)
fn(whiplash/socket.Socket) -> Result(Int, String)unique() -> Int
fn() -> Intnow() -> Int
fn() -> Intarm(socket: Socket) -> Result(Nil, String)
fn(whiplash/socket.Socket) -> Result(Nil, String)Admit one TCP delivery. Rearm only after consuming that delivery; replies from workers do not admit another packet into the connection mailbox.
events(
socket: Socket,
data: fn(BitArray) -> m,
closed: fn(String) -> m,
exited: fn(Pid, String) -> m
) -> otp.Subject(m)
fn(whiplash/socket.Socket, fn(BitArray) -> a, fn(String) -> a, fn(Pid, String) -> a) -> $package/pooka_otp/pooka/otp.Subject(a)A typed mailbox shared by this socket's bytes, application replies, and linked-process exits. The owner must handle parent exits as well as workers. No private OTP subject representation crosses this boundary.
listen_tls(address: String, port: Int, certificate: String, key: String) -> Result(
Socket,
String
)
fn(String, Int, String, String) -> Result(whiplash/socket.Socket, String)TLS uses OTP ssl; certificate files and ALPN selection stay explicit.
connect_tls(port: Int, certificate: String, protocols: List(String)) -> Result(
Socket,
String
)
fn(Int, String, List(String)) -> Result(whiplash/socket.Socket, String)A verified loopback TLS client, used by integration tests and fixtures.
negotiated(socket: Socket) -> Option(String)
fn(whiplash/socket.Socket) -> Option(String)None is plain TCP. TLS defaults to HTTP/1.1 when ALPN was not negotiated.
passive(socket: Socket) -> Result(BitArray, String)
fn(whiplash/socket.Socket) -> Result(BitArray, String)Return to passive reads after a streaming conversation, retaining data already delivered to this socket's mailbox (including pipelined requests).
send_file(socket: Socket, head: BitArray, path: String, size: Int) -> Result(
Nil,
String
)
fn(whiplash/socket.Socket, BitArray, String, Int) -> Result(Nil, String)Write a head, then a regular file through the kernel's sendfile. TLS sockets answer Error("unsupported"); stream the file instead.
credit(delta: Int) -> Int
fn(Int) -> IntAdd to this process's count of unacknowledged stream chunks; returns it.
date() -> String
fn() -> StringThe current time as an HTTP date, such as "Sun, 06 Nov 1994 08:49:37 GMT".