Skip to content

ServerTCPConnection

[Source]

A server-side TCP connection actor driven by a ServerTCPConnectionNotify.

Created by TCPListener when a client connects — there is no public constructor. Wraps lori's TCPConnection class and ServerLifecycleEventReceiver trait, forwarding lifecycle callbacks to the notifier returned by TCPListenNotify.on_connected().

Sending data

write and writev are fire-and-forget behaviors: they call send() on the underlying connection and discard the result. A send that cannot be accepted (connection not open, backpressure) is silently dropped — no callback fires for it. An accepted send produces on_send_accepted, then exactly one of on_sent or on_send_failed on the notifier.

Synchronous methods

Callbacks receive conn: ServerTCPConnection ref. Synchronous methods on the actor — buffer_until, socket options, close, set_timer, etc. — are callable from any callback and take effect immediately.

actor tag ServerTCPConnection is
  TCPConnectionActor[RuntimeBackend ref] tag,
  ServerLifecycleEventReceiver[RuntimeBackend ref] ref

Implements


Public Behaviours

write

[Source]

Send data on this connection. Fire-and-forget: the send is silently dropped if the connection is not open or is under backpressure. An accepted send produces on_send_accepted, then on_sent or on_send_failed on the notifier.

be write(
  data: ByteSeq)

Parameters


writev

[Source]

Send multiple buffers in a single syscall. Same fire-and-forget semantics as write.

be writev(
  data: ByteSeqIter val)

Parameters


mute

[Source]

Stop reading from the socket until unmute is called. Takes effect on the next turn, not immediately — use YieldReading from on_received for an immediate one-shot pause.

be mute()

unmute

[Source]

Resume reading after a mute.

be unmute()

dispose

[Source]

be dispose()

Public Functions

buffer_until

[Source]

Set the number of bytes to buffer before delivering data via on_received. Pass Streaming to deliver all available data as it arrives.

fun ref buffer_until(
  qty: (BufferSize | Streaming val))
: BufferUntilResult

Parameters

Returns


close

[Source]

Gracefully close the connection. Sends already accepted by the underlying connection are delivered before close completes. Because close is synchronous and write is a behavior, a write call in the same callback runs after close — use write before close, not after.

fun ref close()
: None val

Returns


hard_close

[Source]

Close the connection immediately, dropping any queued data.

fun ref hard_close()
: None val

Returns


start_tls

[Source]

Initiate a TLS handshake on an established plaintext connection. Returns None when the handshake starts, or a StartTLSError if the upgrade cannot proceed. On success, on_tls_ready fires. On failure, on_tls_failure fires followed by on_closed.

fun ref start_tls(
  ssl_ctx: SSLContext val,
  host: String val = "")
: (None val | StartTLSError)

Parameters

Returns


set_nodelay

[Source]

Turn Nagle on/off. Returns 0 on success, or a non-zero errno on failure.

fun box set_nodelay(
  state: Bool val)
: U32 val

Parameters

Returns


keepalive

[Source]

Set the TCP keepalive timeout. Pass 0 to disable.

fun ref keepalive(
  secs: U32 val)
: None val

Parameters

  • secs: U32 val

Returns


local_address

[Source]

Return the local IP address.

fun ref local_address()
: NetAddress val

Returns


remote_address

[Source]

Return the remote IP address.

fun ref remote_address()
: NetAddress val

Returns


idle_timeout

[Source]

Set or disable the idle timeout. The timer fires when no data is sent or received for the configured duration. Pass None to disable.

fun ref idle_timeout(
  duration: (IdleTimeout | None val))
: None val

Parameters

Returns


set_timer

[Source]

Create a one-shot timer. Returns a TimerToken on success. Only one timer can be active at a time; cancel the existing one first.

fun ref set_timer(
  duration: TimerDuration)
: (TimerToken val | SetTimerError)

Parameters

Returns


cancel_timer

[Source]

Cancel an active timer. Safe to call with stale tokens.

fun ref cancel_timer(
  token: TimerToken val)
: None val

Parameters

Returns


set_read_buffer_minimum

[Source]

Set the shrink-back floor for the read buffer.

fun ref set_read_buffer_minimum(
  new_min: ReadBufferSize)
: (ReadBufferResized val | ReadBufferResizeBelowBufferSize val)

Parameters

Returns


resize_read_buffer

[Source]

Force the read buffer to a specific size.

fun ref resize_read_buffer(
  size': ReadBufferSize)
: ReadBufferResizeResult

Parameters

Returns


get_so_rcvbuf

[Source]

Get the OS receive buffer size. Returns (errno, value).

fun box get_so_rcvbuf()
: (U32 val , U32 val)

Returns


set_so_rcvbuf

[Source]

Set the OS receive buffer size. Returns 0 on success, or errno.

fun box set_so_rcvbuf(
  bufsize: U32 val)
: U32 val

Parameters

  • bufsize: U32 val

Returns


get_so_sndbuf

[Source]

Get the OS send buffer size. Returns (errno, value).

fun box get_so_sndbuf()
: (U32 val , U32 val)

Returns


set_so_sndbuf

[Source]

Set the OS send buffer size. Returns 0 on success, or errno.

fun box set_so_sndbuf(
  bufsize: U32 val)
: U32 val

Parameters

  • bufsize: U32 val

Returns


getsockopt_u32

[Source]

Get a socket option as a U32. Returns (errno, value).

fun box getsockopt_u32(
  level: I32 val,
  option_name: I32 val)
: (U32 val , U32 val)

Parameters

  • level: I32 val
  • option_name: I32 val

Returns


setsockopt_u32

[Source]

Set a socket option as a U32. Returns 0 on success, or errno.

fun box setsockopt_u32(
  level: I32 val,
  option_name: I32 val,
  option: U32 val)
: U32 val

Parameters

  • level: I32 val
  • option_name: I32 val
  • option: U32 val

Returns


is_closed

[Source]

True when the connection is closed or closing.

fun box is_closed()
: Bool val

Returns


is_writeable

[Source]

True when the socket can currently send.

fun box is_writeable()
: Bool val

Returns