Module eco.ssl

SSL/TLS support.

This module provides TLS-enabled stream connections on top of eco.socket TCP sockets.

Functions

listen (ipaddr, port[, options]) Create a TLS server listener.
connect (ipaddr, port[, options]) Create a TLS client connection.

Class ssl_client

ssl_client:send (data[, timeout]) Send data.
ssl_client:write () Alias of ssl_client:send.
ssl_client:sendfile (path, len[, offset[, timeout]]) Send file content.
ssl_client:recv () Alias of ssl_client:read.
ssl_client:read () See read
ssl_client:readfull () See readfull
ssl_client:readuntil () See readuntil
ssl_client:close () Close the TLS connection.

Class ssl_server

ssl_server:close () Close the server and free its TLS context.
ssl_server:accept () Accept a TLS client.


Functions

listen (ipaddr, port[, options])
Create a TLS server listener.

Internally this calls eco.socket.listen_tcp and wraps accepted sockets with TLS using a server context.

options fields used by TLS:

  • ca: Path to CA certificate file.
  • cert: Path to server certificate file.
  • key: Path to server private key file.
  • insecure: When true, disables/relaxes peer verification (backend dependent).

Other fields are passed to eco.socket.listen_tcp.

Parameters:

  • ipaddr string Listen address.
  • port int Listen port.
  • options table Options table. (optional)

Returns:

    ssl_server

Or

  1. nil On failure.
  2. string Error message.
connect (ipaddr, port[, options])
Create a TLS client connection.

Internally this calls eco.socket.connect_tcp and performs a TLS handshake.

options fields used by TLS:

  • ca: Path to CA certificate file.
  • cert: Path to client certificate file (optional, for mTLS).
  • key: Path to client private key file (optional, for mTLS).
  • insecure: When true, disables/relaxes peer verification (backend dependent).
  • server_name: SNI server name.
  • ctx: An existing ssl context object to reuse.

Other fields are passed to eco.socket.connect_tcp.

If options.ctx is provided, it is reused and will NOT be freed when the returned client is closed.

Parameters:

  • ipaddr string Remote address.
  • port int Remote port.
  • options table Options table. (optional)

Returns:

    ssl_client

Or

  1. nil On failure.
  2. string Error message.

Class ssl_client

SSL client object.

Instances are returned by connect or ssl_server:accept.

ssl_client:send (data[, timeout])
Send data.

Parameters:

  • data string Data to send.
  • timeout number Timeout in seconds (optional)

Returns:

    int Bytes sent.

Or

  1. nil On failure.
  2. string Error message.
ssl_client:write ()
Alias of ssl_client:send.
ssl_client:sendfile (path, len[, offset[, timeout]])
Send file content.

This is a convenience helper that reads from a file and sends exactly len bytes (unless EOF/error occurs).

Parameters:

  • path string File path.
  • len int Bytes to send.
  • offset int Start offset in file. (optional)
  • timeout number Timeout in seconds (optional)

Returns:

    int Bytes sent.

Or

  1. nil On failure.
  2. string Error message.
ssl_client:recv ()
Alias of ssl_client:read.
ssl_client:read ()
See read
ssl_client:readfull ()
See readfull
ssl_client:readuntil ()
See readuntil
ssl_client:close ()
Close the TLS connection.

Frees internal TLS state and closes the underlying TCP socket.

Class ssl_server

SSL server listener.

Instances are returned by listen.

ssl_server:close ()
Close the server and free its TLS context.
ssl_server:accept ()
Accept a TLS client.

This accepts an incoming TCP connection and then performs a TLS handshake.

Returns:

  1. ssl_client Accepted TLS client.
  2. table Peer address table.

Or

  1. nil On failure.
  2. string Error message.
generated by LDoc 1.5.0 Last updated 2026-04-09 14:48:22