tdslite latest
C++ API reference
Loading...
Searching...
No Matches
tdsl::net::network_io_base< Implementation > Struct Template Reference

Base network type. More...

#include <tdslite-net/base/network_io_base.hpp>

Public Types

enum class  e_conection_state : tdsl::int8_t {
  attempt_in_progress = 0 , connected = 1 , disconnected = -1 , connection_failed = -2 ,
  resolve_failed = -3
}
 
using network_io_result = expected< tdsl::size_t, tdsl::int32_t >
 
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

 network_io_base () noexcept
 
template<typename T , traits::enable_when::same_any_of< T, string_view, wstring_view, progmem_string_view > = true>
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.
 
template<typename T >
void do_write (tdsl::span< T > data) noexcept
 Append data to network buffer.
 
tdsl::size_t do_get_write_offset () noexcept
 Get current write offset.
 
template<typename T >
void do_write (tdsl::size_t offset, tdsl::span< T > data) noexcept
 Append data to network buffer, starting from 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::uint16_t k_min_tds_packet_size = {512}
 Smallest/largest valid TDS packet size (MS-TDS 2.2.7.9)
 
static constexpr tdsl::uint16_t k_max_tds_packet_size = {32767}
 

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 = {false}
 
bool response_too_large = {false}
 
tdsl::uint16_t conn_retry_count {10}
 
tdsl::uint16_t conn_retry_delay_ms {3000}
 
tdsl_buffer_object network_buffer = {}
 

Detailed Description

template<typename Implementation>
struct tdsl::net::network_io_base< Implementation >

Base network type.

Template Parameters
ImplementationConcrete network implementation type

Member Typedef Documentation

◆ network_io_result

template<typename Implementation >
using tdsl::net::network_io_base< Implementation >::network_io_result = expected<tdsl::size_t, tdsl::int32_t>

◆ tds_msg_handler_result

template<typename Implementation >
using tdsl::net::network_io_base< Implementation >::tds_msg_handler_result = packet_handler_result<bool, false>

◆ tds_packet_data_callback

template<typename Implementation >
using tdsl::net::network_io_base< Implementation >::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.

Returns amount of needed bytes, if any.

◆ connection_state_callback_ctx

template<typename Implementation >
using tdsl::net::network_io_base< Implementation >::connection_state_callback_ctx = callback<void, void (*)( void *, e_conection_state)>

Member Enumeration Documentation

◆ e_conection_state

template<typename Implementation >
enum class tdsl::net::network_io_base::e_conection_state : tdsl::int8_t
strong
Enumerator
attempt_in_progress 
connected 
disconnected 
connection_failed 
resolve_failed 

Constructor & Destructor Documentation

◆ network_io_base()

template<typename Implementation >
tdsl::net::network_io_base< Implementation >::network_io_base ( )
inlinenoexcept

Member Function Documentation

◆ connect()

template<typename Implementation >
template<typename T , traits::enable_when::same_any_of< T, string_view, wstring_view, progmem_string_view > = true>
tdsl::expected< tdsl::traits::true_type, int > tdsl::net::network_io_base< Implementation >::connect ( T  host,
tdsl::uint16_t  port 
)
inlinenoexcept

Connect to host: port.

Parameters
[in]hostHostname or IP address
[in]portTCP port number
Returns
int 0 if connection is successful, false otherwise.

◆ abandon_response()

template<typename Implementation >
tdsl::uint32_t tdsl::net::network_io_base< Implementation >::abandon_response ( tdsl::uint32_t  processed)
inlinenoexcept

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.

Parameters
[in]processedNumber of complete TDS messages so far
Returns
processed

◆ is_response_too_large()

template<typename Implementation >
bool tdsl::net::network_io_base< Implementation >::is_response_too_large ( ) const
inlinenoexcept

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()).

◆ do_receive_tds_pdu()

template<typename Implementation >
tdsl::uint32_t tdsl::net::network_io_base< Implementation >::do_receive_tds_pdu ( )
inlinenoexcept

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)

◆ do_send_tds_pdu()

template<typename Implementation >
tdsl::detail::e_send_status tdsl::net::network_io_base< Implementation >::do_send_tds_pdu ( tdsl::detail::e_tds_message_type  mtype)
inlinenoexcept

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.

Parameters
[in]mtypeThe type of the message currently in the network buffer

If sending a packet fails, the rest of the message is discarded.

Returns
e_send_status::success if the message is sent
e_send_status::request_too_large if the message was incomplete and discarded (nothing is sent)
e_send_status::network_error if sending failed

◆ discard_tx()

template<typename Implementation >
void tdsl::net::network_io_base< Implementation >::discard_tx ( )
inlinenoexcept

Discard the message being built in the network buffer, including its overflow state.

◆ do_write() [1/2]

template<typename Implementation >
template<typename T >
void tdsl::net::network_io_base< Implementation >::do_write ( tdsl::span< T >  data)
inlinenoexcept

Append data to network buffer.

Parameters
[in]dataData to append

◆ do_get_write_offset()

template<typename Implementation >
tdsl::size_t tdsl::net::network_io_base< Implementation >::do_get_write_offset ( )
inlinenoexcept

Get current write offset.

◆ do_write() [2/2]

template<typename Implementation >
template<typename T >
void tdsl::net::network_io_base< Implementation >::do_write ( tdsl::size_t  offset,
tdsl::span< T >  data 
)
inlinenoexcept

Append data to network buffer, starting from offset.

Parameters
[in]offsetOffset to start from
[in]dataData to append

◆ register_packet_data_callback()

template<typename Implementation >
void tdsl::net::network_io_base< Implementation >::register_packet_data_callback ( tds_packet_data_callback::function_type  cb,
void *  user_ptr 
)
inlinenoexcept

Set TDS packet data callback.

Parameters
[in]cbNew callback
[in]user_ptruptr

◆ set_tds_packet_size()

template<typename Implementation >
void tdsl::net::network_io_base< Implementation >::set_tds_packet_size ( tdsl::uint16_t  value)
inlinenoexcept

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.

Parameters
[in]valueNew packet size. Values outside of the [512, 32767] range are ignored and the current packet size is kept.

◆ set_connection_timeout_params()

template<typename Implementation >
void tdsl::net::network_io_base< Implementation >::set_connection_timeout_params ( tdsl::uint16_t  attempts,
tdsl::uint16_t  delay_ms 
)
inlinenoexcept

Set the conn retry count.

Parameters
attemptsNumber of attempts
delay_msDelay between each attempt (millseconds)

◆ is_strict_encryption()

template<typename Implementation >
bool tdsl::net::network_io_base< Implementation >::is_strict_encryption ( ) const
inlinenoexcept

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.

◆ as_packet()

template<typename Implementation >
static byte_view tdsl::net::network_io_base< Implementation >::as_packet ( byte_view  header,
byte_view  message 
)
inlinestaticprotectednoexcept

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.

Returns
An empty view when the header isn't directly in front of the message (do_send() called by other code with two separate buffers): the caller must not send then.

Member Data Documentation

◆ k_min_tds_packet_size

template<typename Implementation >
constexpr tdsl::uint16_t tdsl::net::network_io_base< Implementation >::k_min_tds_packet_size = {512}
staticconstexpr

Smallest/largest valid TDS packet size (MS-TDS 2.2.7.9)

◆ k_max_tds_packet_size

template<typename Implementation >
constexpr tdsl::uint16_t tdsl::net::network_io_base< Implementation >::k_max_tds_packet_size = {32767}
staticconstexpr

◆ strict_encryption

template<typename Implementation >
bool tdsl::net::network_io_base< Implementation >::strict_encryption = {false}
protected

◆ response_too_large

template<typename Implementation >
bool tdsl::net::network_io_base< Implementation >::response_too_large = {false}
protected

◆ conn_retry_count

template<typename Implementation >
tdsl::uint16_t tdsl::net::network_io_base< Implementation >::conn_retry_count {10}
protected

◆ conn_retry_delay_ms

template<typename Implementation >
tdsl::uint16_t tdsl::net::network_io_base< Implementation >::conn_retry_delay_ms {3000}
protected

◆ network_buffer

template<typename Implementation >
tdsl_buffer_object tdsl::net::network_io_base< Implementation >::network_buffer = {}
protected

The documentation for this struct was generated from the following file: