---
name: "tls_accept_socket"
section: "3"
platform: "linux"
package: "libretls"
version: "3.8.1-3"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/tls_accept_socket"
---

# tls\_accept\_socket(3)

accept an incoming client connection in a TLS server

## NAME

**tls\_accept\_socket**, **tls\_accept\_fds**, **tls\_accept\_cbs** – accept an incoming client connection in a TLS server

## SYNOPSIS

**#include \<tls.h\>**

*int*\

**tls\_accept\_socket**(*struct tls \*tls*, *struct tls \*\*cctx*, *int socket*);

*int*\

**tls\_accept\_fds**(*struct tls \*tls*, *struct tls \*\*cctx*, *int fd\_read*, *int fd\_write*);

*int*\

**tls\_accept\_cbs**(*struct tls \*tls*, *struct tls \*\*cctx*, *ssize\_t (\*tls\_read\_cb)(struct tls \*ctx, void \*buf, size\_t buflen, void \*cb\_arg)*, *ssize\_t (\*tls\_write\_cb)(struct tls \*ctx, const void \*buf, size\_t buflen, void \*cb\_arg)*, *void \*cb\_arg*);

## DESCRIPTION

After creating a TLS server context *tls* with [tls\_server(3)](/tls_server/3.md) and configuring it with [tls\_configure(3)](/tls_configure/3.md), a server can accept a new client connection by calling **tls\_accept\_socket**() on an already established socket connection.

Alternatively, a new client connection can be accepted over a pair of existing file descriptors by calling **tls\_accept\_fds**().

Calling **tls\_accept\_cbs**() allows read and write callback functions to handle data transfers. The specified *cb\_arg* parameter is passed back to the functions, and can contain a pointer to any caller-specified data.

All these functions create a new context suitable for reading and writing and return it in \**cctx*.

## RETURN VALUES

These functions return 0 on success or -1 on error.

## SEE ALSO

[tls\_close(3)](/tls_close/3.md), [tls\_config\_set\_session\_id(3)](/tls_config_set_session_id/3.md), [tls\_configure(3)](/tls_configure/3.md), [tls\_connect(3)](/tls_connect/3.md), [tls\_init(3)](/tls_init/3.md), [tls\_server(3)](/tls_server/3.md)

## HISTORY

**tls\_accept\_socket**() appeared in OpenBSD 5.6 and got its final name in OpenBSD 5.7.

**tls\_accept\_fds**() appeared in OpenBSD 5.8 and **tls\_accept\_cbs**() in OpenBSD 6.1.

## AUTHORS

Joel Sing ⟨*jsing@openbsd.org*⟩

**tls\_accept\_cbs**() was written by Tobias Pape ⟨*tobias@netshed.de*⟩.
