TCPBackend¶
The TCP operations a connection and listener need from the runtime.
RuntimeBackend is the production implementation; test code can
substitute a fake to drive the connection state machine without
real sockets.
Constructors¶
create¶
Returns¶
- TCPBackend ref^
Public Functions¶
listen¶
Open a listening socket bound to host:port and subscribe
the_actor for accept-readiness events. Returns the ASIO event,
or a null event on failure.
fun ref listen(
the_actor: AsioEventNotify tag,
host: String val,
port: String val,
ip_version: IPVersion = reference)
: AsioEventID
Parameters¶
- the_actor: AsioEventNotify tag
- host: String val
- port: String val
- ip_version: IPVersion = reference
Returns¶
accept¶
Accept one pending connection on the listening socket behind
event. Returns the fd (> 0), 0 if none is ready, or -1 on
error.
Parameters¶
- event: AsioEventID
Returns¶
- I32 val
close¶
Close the socket.
Parameters¶
- fd: U32 val
Returns¶
- None val
connect¶
Start non-blocking TCP connection attempts to host:port.
Returns the number of attempts started (one per resolved
address). Zero means every attempt failed immediately.
fun ref connect(
the_actor: AsioEventNotify tag,
host: String val,
port: String val,
from: String val,
asio_flags: U32 val,
ip_version: IPVersion = reference)
: U32 val
Parameters¶
- the_actor: AsioEventNotify tag
- host: String val
- port: String val
- from: String val
- asio_flags: U32 val
- ip_version: IPVersion = reference
Returns¶
- U32 val
keepalive¶
Enable TCP keepalive on fd with an interval of secs seconds.
Parameters¶
Returns¶
- None val
peername¶
Fill ip with the remote address of fd. Returns true on
success.
Parameters¶
- fd: U32 val
- ip: NetAddress tag
Returns¶
- Bool val
receive¶
Receive up to size bytes into buffer. The call is synchronous
and non-blocking: SocketResultRetry means no data was
available, SocketResultError means an unrecoverable error or
peer close.
fun ref receive(
event: AsioEventID,
buffer: Pointer[U8 val] tag,
size: USize val)
: (SocketResult , USize val)
Parameters¶
- event: AsioEventID
- buffer: Pointer[U8 val] tag
- size: USize val
Returns¶
- (SocketResult , USize val)
shutdown¶
Shut down the write side of fd.
Parameters¶
- fd: U32 val
Returns¶
- None val
sockname¶
Fill ip with the local address of fd. Returns true on
success.
Parameters¶
- fd: U32 val
- ip: NetAddress tag
Returns¶
- Bool val
sendv¶
Send count buffers from data starting at index from.
Returns the tri-state socket result plus the number of bytes
sent on SocketResultOk. The call is synchronous and
non-blocking.
fun ref sendv(
event: AsioEventID,
data: Array[ByteSeq] box,
from: USize val,
count: USize val,
first_buffer_byte_offset: USize val = 0)
: (SocketResult , USize val) ?
Parameters¶
- event: AsioEventID
- data: Array[ByteSeq] box
- from: USize val
- count: USize val
- first_buffer_byte_offset: USize val = 0
Returns¶
- (SocketResult , USize val) ?
writev_max¶
Maximum number of buffers a single sendv call may carry.
Returns¶
- I32 val