FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Functions
Network functions

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

Collaboration diagram for Network functions:

Functions

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...
 
int tds7_get_instance_port (struct addrinfo *addr, const char *instance)
 Get port of given instance. More...
 
int tds7_get_instance_ports (FILE *output, struct addrinfo *addr)
 Get port of all instances. More...
 
const char * tds_addrinfo2str (struct addrinfo *addr, char *name, int namemax)
 
static void tds_addrinfo_set_port (struct addrinfo *addr, unsigned int port)
 
void tds_close_socket (TDSSOCKET *tds)
 Close current socket for last socket close entire connection for MARS send FIN request.
 
static TDSERRNO tds_connect_socket (TDSSOCKET *tds, struct addrinfo *addr, unsigned int port, int timeout, int *p_oserr)
 
int tds_connection_read (TDSSOCKET *tds, unsigned char *buf, int buflen)
 
static int tds_connection_signaled (TDSCONNECTION *conn)
 
int tds_connection_write (TDSSOCKET *tds, const unsigned char *buf, int buflen, int final)
 
DSTRtds_dstr_get (TDSSOCKET *tds, DSTR *s, size_t len)
 Reads a string from wire and put in a DSTR. More...
 
TDSRET tds_flush_packet (TDSSOCKET *tds)
 Flush packet to server. More...
 
unsigned char tds_get_byte (TDSSOCKET *tds)
 Return a single byte from the input buffer. 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...
 
size_t tds_get_string (TDSSOCKET *tds, size_t string_len, char *dest, size_t dest_size)
 Fetch a string from the wire. 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...
 
TDS_USMALLINT tds_get_usmallint (TDSSOCKET *tds)
 Get an int16 from the server.
 
int tds_goodread (TDSSOCKET *tds, unsigned char *buf, int buflen)
 Loops until we have received some characters return -1 on failure.
 
int tds_goodwrite (TDSSOCKET *tds, const unsigned char *buffer, size_t buflen)
 
int tds_init_write_buf (TDSSOCKET *tds)
 
TDSERRNO tds_open_socket (TDSSOCKET *tds, struct addrinfo *addr, unsigned int port, int timeout, int *p_oserr)
 
unsigned char tds_peek (TDSSOCKET *tds)
 Reads a byte from the TDS stream without removing it. More...
 
int tds_put_buf (TDSSOCKET *tds, const unsigned char *buf, int dsize, int ssize)
 
int tds_put_byte (TDSSOCKET *tds, unsigned char c)
 
int tds_put_cancel (TDSSOCKET *tds)
 
int tds_put_int (TDSSOCKET *tds, TDS_INT i)
 
int tds_put_int8 (TDSSOCKET *tds, TDS_INT8 i)
 
int tds_put_n (TDSSOCKET *tds, const void *buf, size_t n)
 
int tds_put_smallint (TDSSOCKET *tds, TDS_SMALLINT si)
 
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_read_packet (TDSSOCKET *tds)
 Read in one 'packet' from the server. More...
 
int tds_select (TDSSOCKET *tds, unsigned tds_sel, int timeout_seconds)
 Select on a socket until it's available or the timeout expires. More...
 
void tds_socket_flush (TDS_SYS_SOCKET sock)
 
static int tds_socket_read (TDSCONNECTION *conn, TDSSOCKET *tds, unsigned char *buf, int buflen)
 Read from an OS socket remove tds, save error somewhere, report error in another way. More...
 
int tds_socket_set_nonblocking (TDS_SYS_SOCKET sock)
 Set socket to non-blocking. More...
 
static int tds_socket_write (TDSCONNECTION *conn, TDSSOCKET *tds, const unsigned char *buf, int buflen)
 Write to an OS socket. More...
 
void tds_unget_byte (TDSSOCKET *tds)
 Unget will always work as long as you don't call it twice in a row. More...
 
void tds_wakeup_close (TDSPOLLWAKEUP *wakeup)
 
int tds_wakeup_init (TDSPOLLWAKEUP *wakeup)
 
void tds_wakeup_send (TDSPOLLWAKEUP *wakeup, char cancel)
 
TDSRET tds_write_packet (TDSSOCKET *tds, unsigned char final)
 

Detailed Description

Functions for reading or writing from network.

Function Documentation

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.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
char_convconversion structure
[out]wire_sizesize readed from wire
outbufbuffer to write to
outbytesleftbuffer length
Returns
bytes readed

Here is the call graph for this function:

Here is the caller graph for this function:

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

Get port of given instance.

Returns
port number or 0 if error

Here is the call graph for this function:

int tds7_get_instance_ports ( FILE *  output,
struct addrinfo *  addr 
)

Get port of all instances.

Returns
default port number or 0 if error
Remarks
experimental, cf. MC-SQLR.pdf.

Here is the call graph for this function:

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.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
[out]soutput string
[in]lenstring length (in characters)
Returns
string or NULL on error

Here is the call graph for this function:

Here is the caller graph for this function:

TDSRET tds_flush_packet ( TDSSOCKET tds)

Flush packet to server.

Returns
TDS_FAIL or TDS_SUCCESS

Here is the caller graph for this function:

unsigned char tds_get_byte ( TDSSOCKET tds)

Return a single byte from the input buffer.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.

Here is the call graph for this function:

Here is the caller graph for this function:

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)

Here is the call graph for this function:

Here is the caller graph for this function:

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)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

TDS_UINT tds_get_uint ( TDSSOCKET tds)

Get an int32 from the server.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.

Here is the call graph for this function:

Here is the caller graph for this function:

TDS_UINT8 tds_get_uint8 ( TDSSOCKET tds)

Get an uint64 from the server.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.

Here is the call graph for this function:

int 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

Here is the call graph for this function:

unsigned char tds_peek ( TDSSOCKET tds)

Reads a byte from the TDS stream without removing it.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Write to an OS socket.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.

Here is the caller graph for this function: