Skip to content

Network backends

A backend is the part of tdslite that moves bytes over the network. Choose it by platform; the rest of the API is the same for all of them.

Backend Platform Header Driver type Encryption Network buffer
Arduino Arduino, ESP32, ESP8266 (Arduino core) <tdslite.h> tdsl::arduino_driver<Client> With a TLS client such as WiFiClientSecure Yours
BSD sockets Linux, macOS, ESP-IDF (lwIP), Zephyr, FreeRTOS + lwIP <tdslite-net/socket/tdsl_netimpl_socket.hpp> tdsl::socket_driver No Yours
ESP-IDF TLS ESP-IDF 5.0+ <tdslite-net/esp-idf/tdsl_netimpl_esp_tls.hpp> tdsl::esp_tls_driver Always (esp-tls) Yours
Boost.ASIO Desktop <tdslite-net/asio/tdsl_netimpl_asio.hpp> tdsl::driver<tdsl::net::tdsl_netimpl_asio> No 16 kB, internal
Boost.ASIO TLS Desktop <tdslite-net/asio/tdsl_netimpl_asio_tls.hpp> tdsl::driver<tdsl::net::tdsl_netimpl_asio_tls> Always (OpenSSL) 16 kB, internal

"Yours" means you pass the buffer to the driver's constructor:

tdsl::uint8_t net_buf [768] = {};
tdsl::arduino_driver<EthernetClient> driver{net_buf};

Backend options are set through driver.network(), before connect.

Arduino

tdsl::arduino_driver<Client> works with any client type that has the EthernetClient interface: EthernetClient, WiFiClient, WiFiClientSecure, or your own (see Write a network backend). The network interface (e.g. Ethernet.begin()) must be up before connect.

Function Description
driver.network().client() The client object, e.g. to configure a TLS client
driver.network().set_tls_client(enabled, max_record_payload = 4096) Tell tdslite that the client encrypts the connection, and the most data the client puts into one TLS record. A larger TDS packet is refused instead of being sent split

| driver.network().set_receive_timeout(ms) | How long a receive waits for data (default 30000 ms). A receive that times out closes the connection |

BSD sockets

Header-only, nothing to link. CI tests it on Linux, and on ESP-IDF (in QEMU); the other platforms in the table aren't covered by CI yet.

Function Description
driver.network().set_socket_timeouts(connect_ms, io_ms) Timeout of each connection attempt (default 10000 ms), and of each send and receive (default 30000 ms). A receive that times out closes the connection

ESP-IDF TLS

Like the BSD sockets backend, with esp-tls underneath. Every connection is a TDS 8.0 strict one. Needs about 30 kB of heap while connected (mbedTLS's), and about 500 bytes more stack than the BSD sockets backend.

Function Description
driver.network().set_tls_options(options) Set the TLS options below
driver.network().set_socket_timeouts(connect_ms, io_ms) As for BSD sockets

tdsl::net::tdsl_esp_tls_options:

Field Default Description
ca_pem nullptr PEM text of the CA certificate(s) to trust, NUL-terminated. Takes precedence over use_crt_bundle
use_crt_bundle false Trust the public CAs of ESP-IDF's certificate bundle (CONFIG_MBEDTLS_CERTIFICATE_BUNDLE), e.g. for Azure SQL
host_name nullptr Host name to check the certificate against and send as SNI. nullptr: the host given to connect
alpn true Send the tds/8.0 ALPN protocol ID (needs CONFIG_MBEDTLS_SSL_ALPN)

CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN must be at least the TDS packet size.

Boost.ASIO

Compiled libraries, built by tdslite's CMake project: link with tdslite.net.asio or tdslite.net.asio.tls. The TLS target exists only when CMake finds OpenSSL.

tdsl::net::tdsl_asio_tls_options, set with driver.network().set_tls_options(options):

Field Default Description
verify true Check the server's certificate chain and host name. false leaves the connection open to anyone in the middle
ca_file empty PEM file with the CA certificate(s) to trust. Empty: the system's certificate store
host_name empty Host name to check the certificate against and send as SNI. Empty: the host given to connect
alpn true Send the tds/8.0 ALPN protocol ID