NCBI C++ ToolKit
|
Functions for reading or writing from network. More...
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... | |
DSTR * | tds_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 TDSPACKET * | tds_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... | |
Functions for reading or writing from network.
|
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
char_conv | conversion structure | |
[out] | wire_size | size readed from wire |
outbuf | buffer to write to | |
outbytesleft | buffer length |
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().
Get port of given instance.
Definition at line 1072 of file net.c.
References CLOSESOCKET, pollfd::fd, int, l(), msg(), NULL, poll, POLLIN, sock_errno, sock_strerror, sock_strerror_free, strcasecmp, strlcpy, tds_addrinfo2str(), tds_addrinfo_set_port(), TDS_DBG_ERROR, TDS_DBG_INFO1, TDS_INT_CANCEL, TDS_INT_CONTINUE, TDS_IS_SOCKET_INVALID, tds_socket_set_nonblocking(), tdsdump_dump_buf, tdsdump_log, tdserror, TDSETIME, TDSSOCK_EINTR, and rapidjson::value.
Get port of all instances.
Definition at line 936 of file net.c.
References CLOSESOCKET, pollfd::fd, i, msg(), names, NULL, output, poll, POLLIN, sock_errno, sock_strerror, sock_strerror_free, util::strcmp(), strtok_r, tds_addrinfo2str(), tds_addrinfo_set_port(), TDS_DBG_ERROR, TDS_DBG_INFO1, TDS_INT_CANCEL, TDS_INT_CONTINUE, TDS_IS_SOCKET_INVALID, tds_socket_set_nonblocking(), TDS_VECTOR_SIZE, tdsdump_dump_buf, tdsdump_log, tdserror, TDSETIME, TDSSOCK_EINTR, and rapidjson::value.
Definition at line 196 of file net.c.
References getnameinfo, NI_NUMERICHOST, and NULL.
Referenced by tds7_get_instance_port(), tds7_get_instance_ports(), tds_connect_socket(), and tds_setup_socket().
Definition at line 178 of file net.c.
Referenced by tds7_get_instance_port(), tds7_get_instance_ports(), and tds_connect_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, count, 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 | ( | additional | , |
TDS_ADDITIONAL_SPACE ! | = 0 |
||
) |
|
static |
Definition at line 210 of file net.c.
References tds_socket::conn, conn, len, sock_errno, sock_strerror, sock_strerror_free, SOCKLEN_T, tds, tds_addrinfo2str(), tds_addrinfo_set_port(), tds_connection_close(), TDS_DBG_ERROR, TDS_DBG_INFO1, TDS_DBG_INFO2, tds_getsockopt, TDS_IS_SOCKET_INVALID, TDS_MAJOR, TDS_MINOR, tds_select(), tds_socket_set_nonblocking(), tdsdump_dump_buf, tdsdump_log, TDSECONN, TDSEOK, TDSEUSCT, TDSSELERR, TDSSELWRITE, TDSSOCK_EINPROGRESS, and TDSSOCK_ETIMEDOUT.
Referenced by tds_open_socket().
void tds_connection_close | ( | TDSCONNECTION * | conn | ) |
Definition at line 415 of file net.c.
References CLOSESOCKET, conn, INVALID_SOCKET, n, TDS_DEAD, TDS_IS_SOCKET_INVALID, tds_mutex_lock, tds_mutex_unlock, and tds_set_state.
Referenced by tds_close_socket(), tds_connect_socket(), tds_goodread(), tds_goodwrite(), tds_open_socket(), tds_socket_read(), and tds_socket_write().
Definition at line 807 of file net.c.
References buf, tds_socket::conn, conn, tds, tds_goodread(), tds_socket_read(), and tds_ssl_read().
|
static |
Definition at line 697 of file net.c.
References conn, len, and READSOCKET.
Referenced by tds_goodread().
ssize_t tds_connection_write | ( | TDSSOCKET * | tds, |
const unsigned char * | buf, | ||
size_t | buflen, | ||
int | final | ||
) |
Definition at line 894 of file net.c.
References buf, tds_socket::conn, conn, int, tds, TDS_DBG_WARN, tds_get_s, tds_goodwrite(), tds_socket_flush(), tds_socket_write(), tds_ssl_write(), and tdsdump_log.
Reads a string from wire and put in a DSTR.
On error we read the bytes from the wire anyway. \tds
[out] | s | output string |
[in] | len | string length (in characters) |
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.
Flush packet to server.
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.
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.
[out] | freeze | structure to initialize |
size_len | length 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().
Discard all data written after the freeze.
After this call freeze should not be used.
[in] | freeze | structure to work on |
Definition at line 961 of file packet.c.
References CHECK_FREEZE_EXTRA, tds_socket::conn, tds_packet::data_len, tds_socket::frozen, tds_socket::frozen_packets, tds_connection::list_mtx, tds_packet::next, NULL, tds_socket::out_pos, tds_freeze::pkt, tds_freeze::pkt_pos, tds_freeze::tds, tds, tds_mutex_lock, tds_mutex_unlock, tds_packet_cache_add(), tds_set_current_send_packet(), and TDS_SUCCESS.
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.
[in] | freeze | structure to work on |
Definition at line 996 of file packet.c.
References tds_freeze::size_len, tds_freeze_close_len(), and tds_freeze_written().
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.
[in] | freeze | structure to work on |
[in] | size | size 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().
Definition at line 1002 of file packet.c.
References tds_packet::buf, tds_packet::data_len, tds_packet::next, tds_freeze::pkt, tds_freeze::pkt_pos, ncbi::grid::netcache::search::fields::size, tds_freeze::size_len, and tds_packet_get_data_start.
Referenced by tds_freeze_close_len().
Compute how many bytes has been written from freeze.
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().
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().
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.
tds | state information for the socket and the TDS protocol |
row_buffer | destination buffer in current_row. Can't be NULL |
wire_size | size to read from wire (in bytes) |
curcol | column information |
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.
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) row@ nol.o 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().
|
static |
Definition at line 68 of file packet.c.
References tds_packet::buf, tds_packet::capacity, conn, tds_packet::data_len, len, tds_packet::next, NULL, tds_packet::sid, tds_alloc_packet, tds_free_packets, TDS_MARK_UNDEFINED, tds_mutex_lock, tds_mutex_unlock, and tds_packet_zero_data_start.
Referenced by tds_write_packet().
|
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().
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)
tds | connection information |
string_len | length of string to read from wire (in server characters, bytes for tds4-tds5, ucs2 for tds7+) |
dest | destination buffer, if NULL string is read and discarded |
dest_size | destination 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().
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().
Get an uint64 from the server.
\tds
Definition at line 148 of file read.c.
References tds_socket::conn, tds_connection::emul_little_endian, l(), tds, TDS_GET_A4, TDS_GET_A4LE, and tds_get_n().
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().
Loops until we have received some characters return -1 on failure.
Definition at line 757 of file net.c.
References buf, tds_socket::conn, tds_socket::in_cancel, len, NULL, tds_socket::query_timeout, sock_errno, tds, tds_close_socket(), tds_connection_close(), tds_connection_signaled(), tds_get_ctx, TDS_INT_CANCEL, TDS_INT_CONTINUE, tds_put_cancel, tds_select(), tds_socket_read(), TDSEREAD, tdserror, TDSETIME, TDSPOLLURG, TDSSELREAD, and TDSSOCK_WOULDBLOCK.
Referenced by tds_connection_read().
tds | the famous socket |
buffer | data to send |
buflen | bytes in buffer |
last | 1 if this is the last packet, else 0 |
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().
Definition at line 274 of file write.c.
References tds_socket::out_buf, tds_socket::out_buf_max, tds_socket::out_pos, tds, and TDS_MARK_UNDEFINED.
TDSERRNO tds_open_socket | ( | TDSSOCKET * | tds, |
struct addrinfo * | addr, | ||
unsigned int | port, | ||
int | timeout, | ||
int * | p_oserr | ||
) |
Definition at line 296 of file net.c.
References retry_addr::addr, addrinfo, CLOSESOCKET, tds_socket::conn, conn, pollfd::events, exit(), pollfd::fd, free(), i, INVALID_SOCKET, len, retry_addr::next_retry_time, NULL, poll, POLLERR, POLLOUT, retry_addr::retry_count, pollfd::revents, sock_errno, sock_strerror, sock_strerror_free, start_time, tds_socket::state, tds, tds_connect_socket(), tds_connection_close(), TDS_DBG_ERROR, TDS_DBG_INFO1, TDS_DBG_INFO2, tds_get_socket_error(), tds_gettime_ms, TDS_IDLE, TDS_IS_SOCKET_INVALID, TDS_MAJOR, TDS_MINOR, tds_new0, tds_setup_socket(), tdsdump_log, TDSECONN, TDSEINPROGRESS, TDSEMEM, TDSEOK, TDSESOCK, TDSSELERR, TDSSELWRITE, TDSSOCK_EINTR, TDSSOCK_ETIMEDOUT, and TRUE.
|
static |
Definition at line 104 of file packet.c.
References assert, conn, count, last(), tds_packet::next, tds_free_packets, and tds_mutex_check_owned.
Referenced by tds_freeze_abort(), tds_freeze_close_len(), and tds_read_packet().
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().
Definition at line 141 of file write.c.
References buf, NULL, tds, tds_put_byte(), and tds_put_n().
Definition at line 265 of file write.c.
References tds_socket::out_buf, tds_socket::out_buf_max, tds_socket::out_pos, tds, and tds_write_packet.
Referenced by tds_put_buf(), tds_put_int(), tds_put_int8(), and tds_put_smallint().
Definition at line 770 of file packet.c.
References tds_socket::conn, tds_socket::in_cancel, IS_TDS7_PLUS, tds_socket::login, tds, TDS_CANCEL, tds_connection_write, TDS_DBG_NETWORK, TDS_FAIL, TDS_PUT_A4, TDS_SUCCESS, and tdsdump_dump_buf.
Definition at line 199 of file write.c.
References tds_socket::conn, tds_connection::emul_little_endian, i, tds_socket::out_buf, tds_socket::out_buf_max, tds_socket::out_pos, tds, tds_put_byte(), tds_put_n(), TDS_PUT_UA4, TDS_PUT_UA4LE, and tds_write_packet.
Definition at line 153 of file write.c.
References tds_socket::conn, tds_connection::emul_little_endian, i, tds_socket::out_buf, tds_socket::out_buf_max, tds_socket::out_pos, tds, tds_put_byte(), tds_put_n(), TDS_PUT_UA4, TDS_PUT_UA4LE, and tds_write_packet.
Definition at line 59 of file write.c.
References buf, int, n, tds_socket::out_buf, tds_socket::out_buf_max, tds_socket::out_pos, tds, and tds_write_packet.
Referenced by tds_put_buf(), tds_put_int(), tds_put_int8(), tds_put_smallint(), and tds_put_string().
int tds_put_smallint | ( | TDSSOCKET * | tds, |
TDS_SMALLINT | si | ||
) |
Definition at line 233 of file write.c.
References tds_socket::conn, tds_connection::emul_little_endian, tds_socket::out_buf, tds_socket::out_buf_max, tds_socket::out_pos, si, tds, tds_put_byte(), tds_put_n(), TDS_PUT_UA2, TDS_PUT_UA2LE, and tds_write_packet.
Output a string to wire automatic translate string to unicode if needed.
tds | state information for the socket and the TDS protocol |
s | string to write |
len | length 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.
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)
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.
Select on a socket until it's available or the timeout expires.
Meanwhile, call the interrupt function.
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().
|
static |
Setup the socket and attempt a connection.
Function allocate the socket in *p_sock and try to start a connection.
p_sock | where returned socket is stored. Socket is stored even on error. Can be INVALID_SOCKET. |
addr | address to use for attempting the connection |
port | port to connect to |
p_oserr | where system error is returned |
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().
void tds_socket_flush | ( | TDS_SYS_SOCKET | sock | ) |
Definition at line 882 of file net.c.
Referenced by tds_connection_write().
|
static |
Read from an OS socket @TODO remove tds, save error somewhere, report error in another way.
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().
int tds_socket_set_nonblocking | ( | TDS_SYS_SOCKET | sock | ) |
Set socket to non-blocking.
sock | socket to set |
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().
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).
sock | socket to set |
on | flag if enable or disable |
Definition at line 72 of file net.c.
References sock_errno.
|
static |
Write to an OS socket.
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().
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.
void tds_wakeup_close | ( | TDSPOLLWAKEUP * | wakeup | ) |
Definition at line 674 of file net.c.
References CLOSESOCKET, tds_poll_wakeup::s_signal, tds_poll_wakeup::s_signaled, and TDS_IS_SOCKET_INVALID.
int tds_wakeup_init | ( | TDSPOLLWAKEUP * | wakeup | ) |
Definition at line 643 of file net.c.
References INVALID_SOCKET, tds_poll_wakeup::s_signal, tds_poll_wakeup::s_signaled, and socketpair.
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.
Definition at line 716 of file packet.c.
References tds_packet::capacity, CHECK_TDS_EXTRA, tds_connection::client_spid, tds_socket::conn, tds_packet::data_len, tds_connection::encrypt_single_packet, tds_socket::frozen, IS_TDS7_PLUS, tds_socket::login, tds_packet::next, NULL, tds_socket::out_buf, tds_socket::out_buf_max, tds_socket::out_flag, tds_socket::out_pos, tds_socket::send_packet, tds, tds_connection_write, TDS_DBG_NETWORK, TDS_FAIL, tds_get_packet(), tds_packet_get_data_start, TDS_PUT_A2, TDS_PUT_A2BE, tds_set_current_send_packet(), tds_ssl_deinit(), TDS_SUCCESS, TDS_UNLIKELY, and tdsdump_dump_buf.
Referenced by tds_freeze().