|
tdslite latest
C++ API reference
|
Synchronous networking code for Arduino-like devices. More...
#include <tdslite-net/arduino/tdsl_netimpl_arduino.hpp>
Public Types | |
| enum | e_send_error : tdsl::int32_t { write_failed = -1 , packet_too_large = -2 , not_contiguous = -3 } |
| Error codes of do_send() More... | |
| using | network_io_result = typename network_io_base< tdsl_netimpl_arduino< EthernetClientType > >::network_io_result |
| enum | e_conection_state |
| using | tds_msg_handler_result = packet_handler_result< bool, false > |
| using | tds_packet_data_callback = callback< void, tdsl::uint32_t(*)(void *, tdsl::detail::e_tds_message_type, tdsl::binary_reader< tdsl::endian::little > &)> |
| Packet data callback. | |
| using | connection_state_callback_ctx = callback< void, void(*)(void *, e_conection_state)> |
Public Member Functions | |
| template<tdsl::uint32_t BufSize, typename... Args> | |
| tdsl_netimpl_arduino (tdsl::uint8_t(&network_io_buffer)[BufSize], Args &&... args) | |
| Construct a new tdsl driver object. | |
| template<typename... Args> | |
| tdsl_netimpl_arduino (tdsl::byte_span network_io_buffer, Args &&... args) | |
| Construct a new tdsl driver object. | |
| EthernetClientType & | client () noexcept |
| The client object, e.g. | |
| void | set_tls_client (bool enabled, tdsl::uint32_t max_record_payload=k_default_tls_max_record_payload) noexcept |
| Tell whether the client encrypts the connection with TLS (e.g. | |
| void | set_receive_timeout (tdsl::uint32_t timeout_ms) noexcept |
| How long to wait for more of a response before giving up on it (30 seconds by default). | |
| template<typename T > | |
| tdsl::expected< tdsl::traits::true_type, int > | do_connect (T target, tdsl::uint16_t port) |
Try to connect to the target endpoint target : port. | |
| tdsl::int32_t | do_disconnect () |
| tdsl::int32_t | do_send (byte_view header, byte_view message) noexcept |
Send a TDS packet (header and message) to the connected endpoint, in a single write: network_io_base puts the header directly in front of the message. | |
| auto | do_recv (tdsl::uint32_t transfer_exactly, byte_span dst_buf) -> network_io_result |
Read exactly dst_buf.size() bytes from socket. | |
| auto | do_recv (tdsl::uint32_t transfer_exactly) noexcept -> network_io_result |
| tdsl::expected< tdsl::traits::true_type, int > | connect (T host, tdsl::uint16_t port) noexcept |
Connect to host: port. | |
| tdsl::uint32_t | abandon_response (tdsl::uint32_t processed) noexcept |
| Give up on the response currently being received. | |
| bool | is_response_too_large () const noexcept |
| Whether the last response had an item (e.g. | |
| tdsl::uint32_t | do_receive_tds_pdu () noexcept |
| Receive one, complete TDS PDU. | |
| tdsl::detail::e_send_status | do_send_tds_pdu (tdsl::detail::e_tds_message_type mtype) noexcept |
| Send contents of the message buffer in one or more TDS PDU's, depending on negotiated packet size. | |
| void | discard_tx () noexcept |
| Discard the message being built in the network buffer, including its overflow state. | |
| void | do_write (tdsl::span< T > data) noexcept |
Append data to network buffer. | |
| void | do_write (tdsl::size_t offset, tdsl::span< T > data) noexcept |
Append data to network buffer, starting from offset. | |
| tdsl::size_t | do_get_write_offset () noexcept |
| Get current write offset. | |
| void | register_packet_data_callback (tds_packet_data_callback::function_type cb, void *user_ptr) noexcept |
| Set TDS packet data callback. | |
| void | set_tds_packet_size (tdsl::uint16_t value) noexcept |
| Update negotiated packet size. | |
| void | set_connection_timeout_params (tdsl::uint16_t attempts, tdsl::uint16_t delay_ms) noexcept |
| Set the conn retry count. | |
| bool | is_strict_encryption () const noexcept |
| Whether the current connection is a TDS 8.0 "strict" one (TLS from the first byte). | |
Static Public Attributes | |
| static constexpr tdsl::uint32_t | k_default_tls_max_record_payload = {4096} |
| The default for set_tls_client()'s max_record_payload: the ESP32 Arduino core's NetworkClientSecure (WiFiClientSecure) puts up to 4096 bytes into a TLS record. | |
| static constexpr tdsl::uint32_t | k_default_receive_timeout_ms = {30000} |
| The default for set_receive_timeout() | |
| static constexpr tdsl::uint16_t | k_min_tds_packet_size |
| Smallest/largest valid TDS packet size (MS-TDS 2.2.7.9) | |
| static constexpr tdsl::uint16_t | k_max_tds_packet_size |
Static Protected Member Functions | |
| static byte_view | as_packet (byte_view header, byte_view message) noexcept |
| The whole TDS packet given to do_send(header, message). | |
Protected Attributes | |
| bool | strict_encryption |
| bool | response_too_large |
| tdsl::uint16_t | conn_retry_count |
| tdsl::uint16_t | conn_retry_delay_ms |
| tdsl_buffer_object | network_buffer |
Synchronous networking code for Arduino-like devices.
This implementation does not depend on any concrete type and will work with any EthernetClientType class that provides the following public API interface:
const unsigned char* buf, unsigned long lenconst char* host, unsigned short portunsigned char* buf, unsigned long amountstop() functionAlso, the implementation depends on following global free functions as well:
| using tdsl::net::tdsl_netimpl_arduino< EthernetClientType >::network_io_result = typename network_io_base<tdsl_netimpl_arduino<EthernetClientType> >::network_io_result |
|
inherited |
|
inherited |
Packet data callback.
Returns amount of needed bytes, if any.
|
inherited |
| enum tdsl::net::tdsl_netimpl_arduino::e_send_error : tdsl::int32_t |
Error codes of do_send()
| Enumerator | |
|---|---|
| write_failed | |
| packet_too_large | |
| not_contiguous | |
|
stronginherited |
|
inline |
Construct a new tdsl driver object.
| [in] | network_io_buffer | Network I/O buffer |
|
inline |
Construct a new tdsl driver object.
| [in] | network_io_buffer | Network I/O buffer |
|
inlinenoexcept |
The client object, e.g.
to configure a TLS client (CA certificate, ALPN) before connecting.
|
inlinenoexcept |
Tell whether the client encrypts the connection with TLS (e.g.
WiFiClientSecure). Its connections are then TDS 8.0 "strict" ones: the TLS handshake comes first, and everything after it, the login included, is encrypted. The client does the TLS part (including checking the server's certificate), so it must be configured for that.
SQL Server drops a strict connection when a TDS packet arrives in more than one TLS record. tdslite writes each packet with a single write() call, and refuses a packet larger than max_record_payload, the most data the client puts into one record. A packet is at most the TDS packet size (4096 by default, see connection_parameters::packet_size).
| [in] | enabled | The client encrypts the connection |
| [in] | max_record_payload | The most data the client puts into one TLS record |
|
inlinenoexcept |
How long to wait for more of a response before giving up on it (30 seconds by default).
Raise it for requests that take longer than that before sending their result.
When the time is up, the request fails with a network error and the connection is closed: the rest of the response may still arrive, and it would otherwise be read as the response to the next request. Reconnect before the next request.
| [in] | timeout_ms | Timeout, in milliseconds |
|
inline |
Try to connect to the target endpoint target : port.
| [in] | target | Host name or IP address |
| [in] | port | Port number |
|
inline |
|
inlinenoexcept |
Send a TDS packet (header and message) to the connected endpoint, in a single write: network_io_base puts the header directly in front of the message.
Two writes would cost an extra small TCP segment per packet, and with Nagle's algorithm on, a delayed ACK wait. On a TLS connection, it also keeps the packet in one TLS record (see set_tls_client()).
|
inline |
Read exactly dst_buf.size() bytes from socket.
| [in] | dst_buf | Destination |
|
inlinenoexcept |
|
inlinenoexceptinherited |
Connect to host: port.
| [in] | host | Hostname or IP address |
| [in] | port | TCP port number |
|
inlinenoexceptinherited |
Give up on the response currently being received.
The rest of the response (if any) is still on its way, and nothing tells where it ends: the next request would read it as its own response (e.g. the previous query's result, as a success). The only way to keep the stream in step is to close the connection, so that the next request fails instead and the application reconnects.
| [in] | processed | Number of complete TDS messages so far |
processed
|
inlinenoexceptinherited |
Whether the last response had an item (e.g.
a row, the column metadata or a message) larger than the network buffer. Such a response is given up on, and the connection closed (see abandon_response()).
|
inlinenoexceptinherited |
Receive one, complete TDS PDU.
TDS packet data can span multiple TDS messages. In such scenarios, each TDS message will have its EOM flag set to false except the last TDS message for the packet data.
The amount of successfully read TDS messages. (for diagnostic purposes only)
The main TDS message receive loop.
The loop is mildly stream-based, meaning it will not wait for a whole TDS packet data to arrive before delivering the data down to parsing, but it waits until we have a complete TDS message before doing so.
The downstream parsing code immediately parses the tokens and fires the callback functions, which allows us to discard the processed data from receive buffer (e.g. a processed ROW token's data)
|
inlinenoexceptinherited |
Send contents of the message buffer in one or more TDS PDU's, depending on negotiated packet size.
If any part of the message could not be written into the network buffer (i.e. the message is larger than the buffer), nothing is sent and the message is discarded.
| [in] | mtype | The type of the message currently in the network buffer |
If sending a packet fails, the rest of the message is discarded.
|
inlinenoexceptinherited |
Discard the message being built in the network buffer, including its overflow state.
|
inlinenoexceptinherited |
Append data to network buffer.
| [in] | data | Data to append |
|
inlinenoexceptinherited |
Append data to network buffer, starting from offset.
| [in] | offset | Offset to start from |
| [in] | data | Data to append |
|
inlinenoexceptinherited |
Get current write offset.
|
inlinenoexceptinherited |
Set TDS packet data callback.
| [in] | cb | New callback |
| [in] | user_ptr | uptr |
|
inlinenoexceptinherited |
Update negotiated packet size.
The packet size may be larger than the network buffer. Incoming packets are received in chunks, and outgoing messages are never larger than the network buffer anyway.
| [in] | value | New packet size. Values outside of the [512, 32767] range are ignored and the current packet size is kept. |
|
inlinenoexceptinherited |
Set the conn retry count.
| attempts | Number of attempts |
| delay_ms | Delay between each attempt (millseconds) |
|
inlinenoexceptinherited |
Whether the current connection is a TDS 8.0 "strict" one (TLS from the first byte).
The server then uses the TDS 7.2+ message framing (ALL_HEADERS, 8-byte DONE row counts), even though tdslite logs in as TDS 7.1.
|
inlinestaticprotectednoexceptinherited |
The whole TDS packet given to do_send(header, message).
do_send_tds_pdu() always puts the header directly in front of the message in memory, so a network implementation can send a packet with a single write.
|
staticconstexpr |
The default for set_tls_client()'s max_record_payload: the ESP32 Arduino core's NetworkClientSecure (WiFiClientSecure) puts up to 4096 bytes into a TLS record.
|
staticconstexpr |
The default for set_receive_timeout()
|
staticconstexprinherited |
Smallest/largest valid TDS packet size (MS-TDS 2.2.7.9)
|
staticconstexprinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |