NCBI C++ ToolKit
Classes | Functions
Network functions

Functions for reading or writing from network. More...

+ Collaboration diagram for Network functions:

Classes

struct  retry_addr
 

Functions

int tds_socket_set_nonblocking (TDS_SYS_SOCKET sock)
 Set socket to non-blocking. More...
 
static void tds_addrinfo_set_port (struct addrinfo *addr, unsigned int port)
 
const char * tds_addrinfo2str (struct addrinfo *addr, char *name, int namemax)
 
static TDSERRNO tds_connect_socket (TDSSOCKET *tds, struct addrinfo *addr, unsigned int port, int timeout, int *p_oserr)
 
TDSERRNO tds_open_socket (TDSSOCKET *tds, struct addrinfo *addr, unsigned int port, int timeout, int *p_oserr)
 
void tds_close_socket (TDSSOCKET *tds)
 Close current socket. More...
 
void tds_connection_close (TDSCONNECTION *conn)
 
int tds_select (TDSSOCKET *tds, unsigned tds_sel, int timeout_seconds)
 Select on a socket until it's available or the timeout expires. More...
 
static ssize_t tds_socket_read (TDSCONNECTION *conn, TDSSOCKET *tds, unsigned char *buf, size_t buflen)
 Read from an OS socket @TODO remove tds, save error somewhere, report error in another way. More...
 
static ssize_t tds_socket_write (TDSCONNECTION *conn, TDSSOCKET *tds, const unsigned char *buf, size_t buflen)
 Write to an OS socket. More...
 
int tds_wakeup_init (TDSPOLLWAKEUP *wakeup)
 
void tds_wakeup_close (TDSPOLLWAKEUP *wakeup)
 
void tds_wakeup_send (TDSPOLLWAKEUP *wakeup, char cancel)
 
static int tds_connection_signaled (TDSCONNECTION *conn)
 
ssize_t tds_goodread (TDSSOCKET *tds, unsigned char *buf, size_t buflen)
 Loops until we have received some characters return -1 on failure. More...
 
ssize_t tds_connection_read (TDSSOCKET *tds, unsigned char *buf, size_t buflen)
 
ssize_t tds_goodwrite (TDSSOCKET *tds, const unsigned char *buffer, size_t buflen)
 
void tds_socket_flush (TDS_SYS_SOCKET sock)
 
ssize_t tds_connection_write (TDSSOCKET *tds, const unsigned char *buf, size_t buflen, int final)
 
int tds7_get_instance_ports (FILE *output, struct addrinfo *addr)
 Get port of all instances. More...
 
int tds7_get_instance_port (struct addrinfo *addr, const char *instance)
 Get port of given instance. More...
 
int tds_read_packet (TDSSOCKET *tds)
 Read in one 'packet' from the server. More...
 
TDSRET tds_write_packet (TDSSOCKET *tds, unsigned char final)
 
int tds_put_cancel (TDSSOCKET *tds)
 
unsigned char tds_get_byte (TDSSOCKET *tds)
 Return a single byte from the input buffer \tds. More...
 
void tds_unget_byte (TDSSOCKET *tds)
 Unget will always work as long as you don't call it twice in a row. More...
 
unsigned char tds_peek (TDSSOCKET *tds)
 Reads a byte from the TDS stream without removing it \tds. More...
 
TDS_USMALLINT tds_get_usmallint (TDSSOCKET *tds)
 Get an int16 from the server. More...
 
TDS_UINT tds_get_uint (TDSSOCKET *tds)
 Get an int32 from the server. More...
 
TDS_UINT8 tds_get_uint8 (TDSSOCKET *tds)
 Get an uint64 from the server. More...
 
size_t tds_get_string (TDSSOCKET *tds, size_t string_len, char *dest, size_t dest_size)
 Fetch a string from the wire. More...
 
TDSRET tds_get_char_data (TDSSOCKET *tds, char *row_buffer, size_t wire_size, TDSCOLUMN *curcol)
 Fetch character data the wire. More...
 
void * tds_get_n (TDSSOCKET *tds, void *dest, size_t need)
 Get N bytes from the buffer and return them in the already allocated space given to us. More...
 
static size_t read_and_convert (TDSSOCKET *tds, TDSICONV *char_conv, size_t *wire_size, char *outbuf, size_t outbytesleft)
 For UTF-8 and similar, tds_iconv() may encounter a partial sequence when the chunk boundary is not aligned with the character boundary. More...
 
DSTRtds_dstr_get (TDSSOCKET *tds, DSTR *s, size_t len)
 Reads a string from wire and put in a DSTR. More...
 
int tds_put_n (TDSSOCKET *tds, const void *buf, size_t n)
 
int tds_put_string (TDSSOCKET *tds, const char *s, int len)
 Output a string to wire automatic translate string to unicode if needed. More...
 
int tds_put_buf (TDSSOCKET *tds, const unsigned char *buf, int dsize, int ssize)
 
int tds_put_int8 (TDSSOCKET *tds, TDS_INT8 i)
 
int tds_put_int (TDSSOCKET *tds, TDS_INT i)
 
int tds_put_smallint (TDSSOCKET *tds, TDS_SMALLINT si)
 
int tds_put_byte (TDSSOCKET *tds, unsigned char c)
 
int tds_init_write_buf (TDSSOCKET *tds)
 
TDSRET tds_flush_packet (TDSSOCKET *tds)
 Flush packet to server. More...
 
static int tds_get_socket_error (TDS_SYS_SOCKET sock)
 Returns error stored in the socket. More...
 
static TDSERRNO tds_setup_socket (TDS_SYS_SOCKET *p_sock, struct addrinfo *addr, unsigned int port, int *p_oserr)
 Setup the socket and attempt a connection. More...
 
static TDSPACKETtds_get_packet (TDSCONNECTION *conn, unsigned len)
 
static void tds_packet_cache_add (TDSCONNECTION *conn, TDSPACKET *packet)
 
 TDS_COMPILE_CHECK (additional, TDS_ADDITIONAL_SPACE !=0)
 
void tds_freeze (TDSSOCKET *tds, TDSFREEZE *freeze, unsigned size_len)
 Stop writing to server and cache every packet not sending them to server. More...
 
unsigned int tds_freeze_written (TDSFREEZE *freeze)
 Compute how many bytes has been written from freeze. More...
 
TDSRET tds_freeze_abort (TDSFREEZE *freeze)
 Discard all data written after the freeze. More...
 
TDSRET tds_freeze_close (TDSFREEZE *freeze)
 Stop keeping data for this specific freeze. More...
 
static void tds_freeze_update_size (const TDSFREEZE *freeze, int32_t size)
 
TDSRET tds_freeze_close_len (TDSFREEZE *freeze, int32_t size)
 Stop keeping data for this specific freeze. More...
 
int tds_socket_set_nosigpipe (TDS_SYS_SOCKET sock, int on)
 Set socket to not throw SIGPIPE. More...
 

Detailed Description

Functions for reading or writing from network.

Function Documentation

◆ read_and_convert()

static size_t read_and_convert ( TDSSOCKET tds,
TDSICONV char_conv,
size_t *  wire_size,
char *  outbuf,
size_t  outbytesleft 
)
static

For UTF-8 and similar, tds_iconv() may encounter a partial sequence when the chunk boundary is not aligned with the character boundary.

In that event, it will return an error, and some number of bytes (less than a character) will remain in the tail end of temp[]. They are moved to the beginning, ptemp is adjusted to point just behind them, and the next chunk is read. \tds

Parameters
char_convconversion structure
[out]wire_sizesize readed from wire
outbufbuffer to write to
outbytesleftbuffer length
Returns
bytes readed

Definition at line 293 of file read.c.

References tds_output_stream::buffer, outbuf, r(), tds_staticout_stream::stream, tds, tds_convert_stream, tds_datain_stream_init, tds_staticout_stream_init, and to_client.

Referenced by tds_get_char_data(), and tds_get_string().

◆ tds7_get_instance_port()

int tds7_get_instance_port ( struct addrinfo addr,
const char *  instance 
)

◆ tds7_get_instance_ports()

int tds7_get_instance_ports ( FILE *  output,
struct addrinfo addr 
)

◆ tds_addrinfo2str()

const char* tds_addrinfo2str ( struct addrinfo addr,
char *  name,
int  namemax 
)

◆ tds_addrinfo_set_port()

static void tds_addrinfo_set_port ( struct addrinfo addr,
unsigned int  port 
)
static

Definition at line 178 of file net.c.

References assert, and NULL.

Referenced by tds7_get_instance_port(), tds7_get_instance_ports(), and tds_connect_socket().

◆ tds_close_socket()

void tds_close_socket ( TDSSOCKET tds)

Close current socket.

For last socket close entire connection. For MARS send FIN request. This attempts a graceful disconnection, for ungraceful call tds_connection_close.

Definition at line 384 of file net.c.

References CLOSESOCKET, tds_socket::conn, conn, INVALID_SOCKET, IS_TDSDEAD, n, sock_errno, tds, tds_append_fin, tds_connection_close(), TDS_DEAD, tds_disconnect, tds_get_ctx, tds_get_s, TDS_IS_SOCKET_INVALID, tds_mutex_lock, tds_mutex_unlock, tds_set_s, tds_set_state, TDSECLOS, and tdserror.

Referenced by tds_goodread(), and tds_goodwrite().

◆ TDS_COMPILE_CHECK()

TDS_COMPILE_CHECK ( additional  ,
TDS_ADDITIONAL_SPACE = 0 
)

◆ tds_connect_socket()

static TDSERRNO tds_connect_socket ( TDSSOCKET tds,
struct addrinfo addr,
unsigned int  port,
int  timeout,
int p_oserr 
)
static

◆ tds_connection_close()

void tds_connection_close ( TDSCONNECTION conn)

◆ tds_connection_read()

ssize_t tds_connection_read ( TDSSOCKET tds,
unsigned char *  buf,
size_t  buflen 
)

Definition at line 807 of file net.c.

References buf, tds_socket::conn, conn, tds, tds_goodread(), tds_socket_read(), and tds_ssl_read().

◆ tds_connection_signaled()

static int tds_connection_signaled ( TDSCONNECTION conn)
static

Definition at line 697 of file net.c.

References conn, len, and READSOCKET.

Referenced by tds_goodread().

◆ tds_connection_write()

ssize_t tds_connection_write ( TDSSOCKET tds,
const unsigned char *  buf,
size_t  buflen,
int  final 
)

◆ tds_dstr_get()

DSTR* tds_dstr_get ( TDSSOCKET tds,
DSTR s,
size_t  len 
)

Reads a string from wire and put in a DSTR.

On error we read the bytes from the wire anyway. \tds

Parameters
[out]soutput string
[in]lenstring length (in characters)
Returns
string or NULL on error

Definition at line 318 of file read.c.

References CHECK_TDS_EXTRA, len, NULL, tds, tds_dstr_alloc(), tds_dstr_buf(), tds_dstr_setlen(), tds_get_n(), tds_get_string(), and TDS_UNLIKELY.

◆ tds_flush_packet()

TDSRET tds_flush_packet ( TDSSOCKET tds)

Flush packet to server.

Returns
TDS_FAIL or TDS_SUCCESS

Definition at line 286 of file write.c.

References IS_TDSDEAD, tds_socket::out_buf_max, tds_socket::out_pos, result, tds, TDS_FAIL, TDS_FAILED, and tds_write_packet.

◆ tds_freeze()

void tds_freeze ( TDSSOCKET tds,
TDSFREEZE freeze,
unsigned  size_len 
)

Stop writing to server and cache every packet not sending them to server.

This is used to write data without worrying to compute length before. If size_len is provided the number of bytes written between tds_freeze and tds_freeze_close will be written as a number of size size_len. This call should be followed by a tds_freeze_close, tds_freeze_close_len or a tds_freeze_abort. Failing to match tds_freeze with a close would possibly result in a disconnection from the server.

Parameters
[out]freezestructure to initialize
size_lenlength of the size to automatically write on close (0, 1, 2, or 4)

Definition at line 907 of file packet.c.

References CHECK_FREEZE_EXTRA, CHECK_TDS_EXTRA, tds_socket::frozen, tds_socket::frozen_packets, NULL, tds_socket::out_buf_max, tds_socket::out_pos, tds_freeze::pkt, tds_freeze::pkt_pos, tds_socket::send_packet, tds_freeze::size_len, tds_freeze::tds, tds, tds_extra_assert, tds_put_n, and tds_write_packet().

◆ tds_freeze_abort()

TDSRET tds_freeze_abort ( TDSFREEZE freeze)

◆ tds_freeze_close()

TDSRET tds_freeze_close ( TDSFREEZE freeze)

Stop keeping data for this specific freeze.

If size_len was used for tds_freeze this function write the written bytes at position when tds_freeze was called. After this call freeze should not be used.

Parameters
[in]freezestructure to work on

Definition at line 996 of file packet.c.

References tds_freeze::size_len, tds_freeze_close_len(), and tds_freeze_written().

◆ tds_freeze_close_len()

TDSRET tds_freeze_close_len ( TDSFREEZE freeze,
int32_t  size 
)

Stop keeping data for this specific freeze.

Similar to tds_freeze_close but specify the size to be written instead of letting tds_freeze_close compute it. After this call freeze should not be used.

Parameters
[in]freezestructure to work on
[in]sizesize to write

Definition at line 1031 of file packet.c.

References tds_packet::buf, CHECK_FREEZE_EXTRA, tds_socket::conn, tds_packet::data_len, tds_socket::frozen, tds_socket::frozen_packets, tds_connection::list_mtx, next(), tds_packet::next, NULL, tds_freeze::pkt, tds_socket::send_packet, ncbi::grid::netcache::search::fields::size, tds_freeze::size_len, tds_freeze::tds, tds, tds_connection_write, tds_extra_assert, TDS_FAIL, TDS_FAILED, tds_freeze_update_size(), tds_mutex_lock, tds_mutex_unlock, tds_packet_cache_add(), TDS_SUCCESS, and TDS_UNLIKELY.

Referenced by tds_freeze_close().

◆ tds_freeze_update_size()

static void tds_freeze_update_size ( const TDSFREEZE freeze,
int32_t  size 
)
static

◆ tds_freeze_written()

unsigned int tds_freeze_written ( TDSFREEZE freeze)

Compute how many bytes has been written from freeze.

Returns
bytes written since tds_freeze call

Definition at line 935 of file packet.c.

References CHECK_FREEZE_EXTRA, tds_packet::data_len, tds_packet::next, NULL, tds_socket::out_pos, tds_freeze::pkt, tds_freeze::pkt_pos, ncbi::grid::netcache::search::fields::size, tds_freeze::tds, and tds.

Referenced by tds_freeze_close().

◆ tds_get_byte()

unsigned char tds_get_byte ( TDSSOCKET tds)

Return a single byte from the input buffer \tds.

Definition at line 72 of file read.c.

References tds_socket::in_buf, tds_socket::in_len, tds_socket::in_pos, tds, and tds_read_packet.

Referenced by tds_peek().

◆ tds_get_char_data()

TDSRET tds_get_char_data ( TDSSOCKET tds,
char *  row_buffer,
size_t  wire_size,
TDSCOLUMN curcol 
)

Fetch character data the wire.

Output is NOT null terminated. If char_conv is not NULL, convert data accordingly.

Parameters
tdsstate information for the socket and the TDS protocol
row_bufferdestination buffer in current_row. Can't be NULL
wire_sizesize to read from wire (in bytes)
curcolcolumn information
Returns
TDS_SUCCESS or TDS_FAIL (probably memory error on text data)

Definition at line 213 of file read.c.

References assert, tds_column::char_conv, tds_column::column_cur_size, tds_column::column_size, NULL, read_and_convert(), tds, TDS_DBG_NETWORK, TDS_FAIL, tds_get_n(), TDS_SUCCESS, TDS_UNLIKELY, and tdsdump_log.

◆ tds_get_n()

void* tds_get_n ( TDSSOCKET tds,
void *  dest,
size_t  need 
)

Get N bytes from the buffer and return them in the already allocated space given to us.

We ASSUME that the person calling this function has done the bounds checking for us since they know how many bytes they want here. dest of NULL means we just want to eat the bytes. (tethe.nosp@m.row@.nosp@m.nol.o.nosp@m.rg)

Definition at line 250 of file read.c.

References tds_packet::capacity, tds_socket::in_buf, tds_socket::in_len, tds_socket::in_pos, int, NULL, tds_socket::recv_packet, tds, tds_close_socket, tds_read_packet, and TDS_UNLIKELY.

Referenced by tds_dstr_get(), tds_get_char_data(), tds_get_string(), tds_get_uint(), tds_get_uint8(), and tds_get_usmallint().

◆ tds_get_packet()

static TDSPACKET* tds_get_packet ( TDSCONNECTION conn,
unsigned  len 
)
static

◆ tds_get_socket_error()

static int tds_get_socket_error ( TDS_SYS_SOCKET  sock)
static

Returns error stored in the socket.

Definition at line 217 of file net.c.

References sock_errno, sock_strerror, sock_strerror_free, SOCKLEN_T, TDS_DBG_ERROR, tds_getsockopt, and tdsdump_log.

Referenced by tds_open_socket().

◆ tds_get_string()

size_t tds_get_string ( TDSSOCKET tds,
size_t  string_len,
char *  dest,
size_t  dest_size 
)

Fetch a string from the wire.

Output string is NOT null terminated. If TDS version is 7 or 8 read unicode string and convert it. This function should be use to read server default encoding strings like columns name, table names, etc, not for data (use tds_get_char_data instead)

Returns
bytes written to dest
Parameters
tdsconnection information
string_lenlength of string to read from wire (in server characters, bytes for tds4-tds5, ucs2 for tds7+)
destdestination buffer, if NULL string is read and discarded
dest_sizedestination buffer size, in bytes

Definition at line 184 of file read.c.

References tds_connection::char_convs, client2server_chardata, client2ucs2, tds_socket::conn, conv, IS_TDS7_PLUS, NULL, read_and_convert(), tds, and tds_get_n().

Referenced by tds_dstr_get().

◆ tds_get_uint()

TDS_UINT tds_get_uint ( TDSSOCKET tds)

Get an int32 from the server.

\tds

Definition at line 131 of file read.c.

References tds_socket::conn, tds_connection::emul_little_endian, tds, TDS_GET_A4, TDS_GET_A4LE, and tds_get_n().

◆ tds_get_uint8()

TDS_UINT8 tds_get_uint8 ( TDSSOCKET tds)

Get an uint64 from the server.

\tds

Definition at line 148 of file read.c.

References tds_socket::conn, tds_connection::emul_little_endian, tds, TDS_GET_A4, TDS_GET_A4LE, and tds_get_n().

◆ tds_get_usmallint()

TDS_USMALLINT tds_get_usmallint ( TDSSOCKET tds)

Get an int16 from the server.

Definition at line 113 of file read.c.

References tds_socket::conn, tds_connection::emul_little_endian, tds, TDS_GET_A2, TDS_GET_A2LE, and tds_get_n().

◆ tds_goodread()

ssize_t tds_goodread ( TDSSOCKET tds,
unsigned char *  buf,
size_t  buflen 
)

◆ tds_goodwrite()

ssize_t tds_goodwrite ( TDSSOCKET tds,
const unsigned char *  buffer,
size_t  buflen 
)
Parameters
tdsthe famous socket
bufferdata to send
buflenbytes in buffer
last1 if this is the last packet, else 0
Returns
length written (>0), <0 on failure

Definition at line 829 of file net.c.

References assert, buffer, tds_socket::conn, len, tds_socket::query_timeout, sock_errno, sock_strerror, sock_strerror_free, tds, tds_close_socket(), tds_connection_close(), TDS_DBG_NETWORK, tds_get_ctx, TDS_INT_CANCEL, TDS_INT_CONTINUE, tds_select(), tds_socket_write(), tdsdump_log, tdserror, TDSETIME, TDSEWRIT, TDSSELWRITE, and TDSSOCK_WOULDBLOCK.

Referenced by tds_connection_write().

◆ tds_init_write_buf()

int tds_init_write_buf ( TDSSOCKET tds)

◆ tds_open_socket()

TDSERRNO tds_open_socket ( TDSSOCKET tds,
struct addrinfo addr,
unsigned int  port,
int  timeout,
int p_oserr 
)

◆ tds_packet_cache_add()

static void tds_packet_cache_add ( TDSCONNECTION conn,
TDSPACKET packet 
)
static

◆ tds_peek()

unsigned char tds_peek ( TDSSOCKET tds)

Reads a byte from the TDS stream without removing it \tds.

Definition at line 100 of file read.c.

References tds_socket::in_pos, result, tds, and tds_get_byte().

◆ tds_put_buf()

int tds_put_buf ( TDSSOCKET tds,
const unsigned char *  buf,
int  dsize,
int  ssize 
)

Definition at line 141 of file write.c.

References buf, NULL, tds, tds_put_byte(), and tds_put_n().

◆ tds_put_byte()

int tds_put_byte ( TDSSOCKET tds,
unsigned char  c 
)

◆ tds_put_cancel()

int tds_put_cancel ( TDSSOCKET tds)

◆ tds_put_int()

int tds_put_int ( TDSSOCKET tds,
TDS_INT  i 
)

◆ tds_put_int8()

int tds_put_int8 ( TDSSOCKET tds,
TDS_INT8  i 
)

◆ tds_put_n()

int tds_put_n ( TDSSOCKET tds,
const void *  buf,
size_t  n 
)

◆ tds_put_smallint()

int tds_put_smallint ( TDSSOCKET tds,
TDS_SMALLINT  si 
)

◆ tds_put_string()

int tds_put_string ( TDSSOCKET tds,
const char *  s,
int  len 
)

Output a string to wire automatic translate string to unicode if needed.

Returns
bytes written to wire
Parameters
tdsstate information for the socket and the TDS protocol
sstring to write
lenlength of string in characters, or -1 for null terminated

Definition at line 93 of file write.c.

References assert, tds_connection::char_convs, tdsiconvdir::charset, client, client2server_chardata, client2ucs2, tds_socket::conn, tdsiconvinfo::from, int, IS_TDS50, IS_TDS7_PLUS, len, r(), tds_dataout_stream::stream, tds, tds_convert_stream, tds_dataout_stream_init, tds_put_n(), tds_staticin_stream_init, to_server, and tds_dataout_stream::written.

◆ tds_read_packet()

int tds_read_packet ( TDSSOCKET tds)

Read in one 'packet' from the server.

This is a wrapped outer packet of the protocol (they bundle result packets into chunks and wrap them at what appears to be 512 bytes regardless of how that breaks internal packet up. (tetherow@nol.org)

Returns
bytes read or -1 on failure

Definition at line 530 of file packet.c.

References tds_packet::buf, tds_packet::capacity, tds_socket::conn, conn, tds_packet::data_len, tds_socket::in_buf, tds_socket::in_flag, tds_socket::in_len, tds_socket::in_pos, int, IS_TDSDEAD, tds_packet::len, len, tds_packet::next, NULL, tds_socket::query_timeout, tds_socket::recv_packet, tds, TDS72_SMP, tds_close_socket, tds_cond_timedwait, tds_connection_read, TDS_DBG_NETWORK, TDS_GET_A2BE, tds_get_ctx, TDS_INT_CONTINUE, tds_mutex_lock, tds_mutex_unlock, tds_packet_cache_add(), tds_realloc_packet, TDS_UNLIKELY, tdsdump_dump_buf, tdsdump_log, tdserror, and TDSETIME.

◆ tds_select()

int tds_select ( TDSSOCKET tds,
unsigned  tds_sel,
int  timeout_seconds 
)

Select on a socket until it's available or the timeout expires.

Meanwhile, call the interrupt function.

Returns
>0 ready descriptors 0 timeout <0 error (cf. errno). Caller should close socket and return failure. This function does not call tdserror or close the socket because it can't know the context in which it's being called.

Definition at line 447 of file net.c.

References assert, tds_socket::conn, pollfd::events, pollfd::fd, NULL, poll, POLLERR, POLLIN, pollfd::revents, set_sock_errno, sock_errno, sock_strerror, sock_strerror_free, tds, TDS_DBG_ERROR, TDS_DBG_NETWORK, tds_get_ctx, tds_get_parent, tds_get_s, TDS_INT_CANCEL, TDS_INT_CONTINUE, TDS_IS_SOCKET_INVALID, tds_ssl_pending(), tds_wakeup_get_fd(), tdsdump_log, TDSPOLLURG, TDSSELREAD, TDSSOCK_ECONNRESET, TDSSOCK_EINPROGRESS, TDSSOCK_EINTR, timeout_seconds, tds_connection::tls_session, and tds_connection::wakeup.

Referenced by tds_connect_socket(), tds_goodread(), and tds_goodwrite().

◆ tds_setup_socket()

static TDSERRNO tds_setup_socket ( TDS_SYS_SOCKET p_sock,
struct addrinfo addr,
unsigned int  port,
int p_oserr 
)
static

Setup the socket and attempt a connection.

Function allocate the socket in *p_sock and try to start a connection.

Parameters
p_sockwhere returned socket is stored. Socket is stored even on error. Can be INVALID_SOCKET.
addraddress to use for attempting the connection
portport to connect to
p_oserrwhere system error is returned
Returns
TDSEOK is success, TDSEINPROGRESS if connection attempt is started or any other error.

Definition at line 249 of file net.c.

References len, NULL, sock_errno, sock_strerror, sock_strerror_free, tds_addrinfo2str(), tds_addrinfo_set_port(), TDS_DBG_ERROR, TDS_DBG_INFO1, TDS_DBG_INFO2, TDS_IS_SOCKET_INVALID, tds_socket_set_nonblocking(), tdsdump_dump_buf, tdsdump_log, TDSECONN, TDSEINPROGRESS, TDSEOK, TDSESOCK, TDSEUSCT, TDSSOCK_EINPROGRESS, and TRUE.

Referenced by tds_open_socket().

◆ tds_socket_flush()

void tds_socket_flush ( TDS_SYS_SOCKET  sock)

Definition at line 882 of file net.c.

Referenced by tds_connection_write().

◆ tds_socket_read()

static ssize_t tds_socket_read ( TDSCONNECTION conn,
TDSSOCKET tds,
unsigned char *  buf,
size_t  buflen 
)
static

Read from an OS socket @TODO remove tds, save error somewhere, report error in another way.

Returns
0 if blocking, <0 error >0 bytes read

Definition at line 564 of file net.c.

References buf, cnt, conn, len, READSOCKET, sock_errno, tds, tds_connection_close(), TDSEREAD, tdserror, TDSESEOF, and TDSSOCK_WOULDBLOCK.

Referenced by tds_connection_read(), and tds_goodread().

◆ tds_socket_set_nonblocking()

int tds_socket_set_nonblocking ( TDS_SYS_SOCKET  sock)

Set socket to non-blocking.

Parameters
socksocket to set
Returns
0 on success or error code

Definition at line 164 of file net.c.

References IOCTLSOCKET, and sock_errno.

Referenced by tds7_get_instance_port(), tds7_get_instance_ports(), tds_connect_socket(), and tds_setup_socket().

◆ tds_socket_set_nosigpipe()

int tds_socket_set_nosigpipe ( TDS_SYS_SOCKET  sock,
int  on 
)

Set socket to not throw SIGPIPE.

Not many systems support this feature (in this case ENOTSUP can be returned).

Parameters
socksocket to set
onflag if enable or disable
Returns
0 on success or error code

Definition at line 72 of file net.c.

References sock_errno.

◆ tds_socket_write()

static ssize_t tds_socket_write ( TDSCONNECTION conn,
TDSSOCKET tds,
const unsigned char *  buf,
size_t  buflen 
)
static

Write to an OS socket.

Returns
0 if blocking, <0 error >0 bytes readed

Definition at line 601 of file net.c.

References assert, buf, cnt, conn, len, sock_errno, sock_strerror, sock_strerror_free, tds, tds_connection_close(), TDS_DBG_NETWORK, tdsdump_log, tdserror, TDSEWRIT, TDSSOCK_EINTR, TDSSOCK_WOULDBLOCK, and WRITESOCKET.

Referenced by tds_connection_write(), and tds_goodwrite().

◆ tds_unget_byte()

void tds_unget_byte ( TDSSOCKET tds)

Unget will always work as long as you don't call it twice in a row.

It it may work if you call it multiple times as long as you don't backup over the beginning of network packet boundary which can occur anywhere in the token stream. \tds

Definition at line 89 of file read.c.

References tds_socket::in_pos, and tds.

◆ tds_wakeup_close()

void tds_wakeup_close ( TDSPOLLWAKEUP wakeup)

◆ tds_wakeup_init()

int tds_wakeup_init ( TDSPOLLWAKEUP wakeup)

◆ tds_wakeup_send()

void tds_wakeup_send ( TDSPOLLWAKEUP wakeup,
char  cancel 
)

Definition at line 684 of file net.c.

References tds_poll_wakeup::s_signal, and tds_poll_wakeup::s_signaled.

◆ tds_write_packet()

TDSRET tds_write_packet ( TDSSOCKET tds,
unsigned char  final 
)
Modified on Sun May 19 04:42:27 2024 by modify_doxy.py rev. 669887