Module

whiplash/socket

src/whiplash/socket.pooka

The 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

class

Socket

src/whiplash/socket.pooka:9
class Socket
function

listen

src/whiplash/socket.pooka:89
listen(address: String, port: Int) -> Result(Socket, String)
INFERREDfn(String, Int) -> Result(whiplash/socket.Socket, String)

Listen for TCP connections on address (an IPv4 or IPv6 address).

function

accept

src/whiplash/socket.pooka:93
accept(listener: Socket) -> Result(Socket, String)
INFERREDfn(whiplash/socket.Socket) -> Result(whiplash/socket.Socket, String)
function

connect

src/whiplash/socket.pooka:97
connect(port: Int) -> Result(Socket, String)
INFERREDfn(Int) -> Result(whiplash/socket.Socket, String)
function

recv

src/whiplash/socket.pooka:101
recv(socket: Socket, timeout: Int) -> Result(BitArray, String)
INFERREDfn(whiplash/socket.Socket, Int) -> Result(BitArray, String)
function

idle

src/whiplash/socket.pooka:109
idle(
  socket: Socket,
  wait: Int,
  left: Int,
  resume: fn(Result(BitArray, String)) -> Nil
) -> Nil
INFERREDfn(whiplash/socket.Socket, Int, Int, fn(Result(BitArray, String)) -> Nil) -> Nil

Wait 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.

function

doze

src/whiplash/socket.pooka:121
doze(left: Int, resume: fn(Bool) -> Nil) -> Nil
INFERREDfn(Int, fn(Bool) -> Nil) -> Nil

Hibernate 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.

function

send

src/whiplash/socket.pooka:125
send(socket: Socket, head: BitArray, body: BitArray) -> Result(Nil, String)
INFERREDfn(whiplash/socket.Socket, BitArray, BitArray) -> Result(Nil, String)
function

send_parts

src/whiplash/socket.pooka:130
send_parts(socket: Socket, head: BitArray, parts: List(BitArray)) -> Result(
  Nil,
  String
)
INFERREDfn(whiplash/socket.Socket, BitArray, List(BitArray)) -> Result(Nil, String)

Send head, then each part in order, in one write without joining them.

function

transfer

src/whiplash/socket.pooka:137
transfer(socket: Socket, owner: Pid) -> Result(Nil, String)
INFERREDfn(whiplash/socket.Socket, Pid) -> Result(Nil, String)
function

close

src/whiplash/socket.pooka:141
close(socket: Socket) -> Nil
INFERREDfn(whiplash/socket.Socket) -> Nil
function

port

src/whiplash/socket.pooka:145
port(socket: Socket) -> Result(Int, String)
INFERREDfn(whiplash/socket.Socket) -> Result(Int, String)
function

unique

src/whiplash/socket.pooka:149
unique() -> Int
INFERREDfn() -> Int
function

now

src/whiplash/socket.pooka:153
now() -> Int
INFERREDfn() -> Int
function

arm

src/whiplash/socket.pooka:159
arm(socket: Socket) -> Result(Nil, String)
INFERREDfn(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.

function

events

src/whiplash/socket.pooka:166
events(
  socket: Socket,
  data: fn(BitArray) -> m,
  closed: fn(String) -> m,
  exited: fn(Pid, String) -> m
) -> otp.Subject(m)
INFERREDfn(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.

function

listen_tls

src/whiplash/socket.pooka:176
listen_tls(address: String, port: Int, certificate: String, key: String) -> Result(
  Socket,
  String
)
INFERREDfn(String, Int, String, String) -> Result(whiplash/socket.Socket, String)

TLS uses OTP ssl; certificate files and ALPN selection stay explicit.

function

connect_tls

src/whiplash/socket.pooka:184
connect_tls(port: Int, certificate: String, protocols: List(String)) -> Result(
  Socket,
  String
)
INFERREDfn(Int, String, List(String)) -> Result(whiplash/socket.Socket, String)

A verified loopback TLS client, used by integration tests and fixtures.

function

negotiated

src/whiplash/socket.pooka:192
negotiated(socket: Socket) -> Option(String)
INFERREDfn(whiplash/socket.Socket) -> Option(String)

None is plain TCP. TLS defaults to HTTP/1.1 when ALPN was not negotiated.

function

passive

src/whiplash/socket.pooka:198
passive(socket: Socket) -> Result(BitArray, String)
INFERREDfn(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).

function

send_file

src/whiplash/socket.pooka:204
send_file(socket: Socket, head: BitArray, path: String, size: Int) -> Result(
  Nil,
  String
)
INFERREDfn(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.

function

credit

src/whiplash/socket.pooka:212
credit(delta: Int) -> Int
INFERREDfn(Int) -> Int

Add to this process's count of unacknowledged stream chunks; returns it.

function

date

src/whiplash/socket.pooka:217
date() -> String
INFERREDfn() -> String

The current time as an HTTP date, such as "Sun, 06 Nov 1994 08:49:37 GMT".