mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
MYSQLND_NET refactored not to use any direct reference to MYSQLND (the connection)
QC will need an ifdef-layer to compile with this
This commit is contained in:
parent
33eb2ab6f1
commit
b5f5770399
7 changed files with 384 additions and 241 deletions
|
@ -219,7 +219,7 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_conn, dtor)(MYSQLND * conn TSRMLS_DC)
|
||||||
conn->m->free_options(conn TSRMLS_CC);
|
conn->m->free_options(conn TSRMLS_CC);
|
||||||
|
|
||||||
if (conn->net) {
|
if (conn->net) {
|
||||||
mysqlnd_net_free(conn->net TSRMLS_CC);
|
mysqlnd_net_free(conn->net, conn->stats, &conn->error_info TSRMLS_CC);
|
||||||
conn->net = NULL;
|
conn->net = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,6 +389,7 @@ MYSQLND_METHOD(mysqlnd_conn, simple_command)(MYSQLND * conn, enum php_mysqlnd_se
|
||||||
DBG_ERR_FMT("Error while sending %s packet", mysqlnd_command_to_text[command]);
|
DBG_ERR_FMT("Error while sending %s packet", mysqlnd_command_to_text[command]);
|
||||||
php_error(E_WARNING, "Error while sending %s packet. PID=%d", mysqlnd_command_to_text[command], getpid());
|
php_error(E_WARNING, "Error while sending %s packet. PID=%d", mysqlnd_command_to_text[command], getpid());
|
||||||
}
|
}
|
||||||
|
CONN_SET_STATE(conn, CONN_QUIT_SENT);
|
||||||
DBG_ERR("Server is gone");
|
DBG_ERR("Server is gone");
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
} else if (ok_packet != PROT_LAST) {
|
} else if (ok_packet != PROT_LAST) {
|
||||||
|
@ -644,8 +645,7 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND * conn,
|
||||||
unsigned int mysql_flags
|
unsigned int mysql_flags
|
||||||
TSRMLS_DC)
|
TSRMLS_DC)
|
||||||
{
|
{
|
||||||
char *errstr = NULL;
|
size_t host_len;
|
||||||
int errcode = 0, host_len;
|
|
||||||
zend_bool unix_socket = FALSE;
|
zend_bool unix_socket = FALSE;
|
||||||
zend_bool named_pipe = FALSE;
|
zend_bool named_pipe = FALSE;
|
||||||
zend_bool reconnect = FALSE;
|
zend_bool reconnect = FALSE;
|
||||||
|
@ -756,7 +756,9 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND * conn,
|
||||||
goto err; /* OOM */
|
goto err; /* OOM */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAIL == conn->net->m.connect(conn->net, conn->scheme, conn->scheme_len, conn->persistent, &errstr, &errcode TSRMLS_CC)) {
|
if (FAIL == conn->net->m.connect_ex(conn->net, conn->scheme, conn->scheme_len, conn->persistent,
|
||||||
|
conn->stats, &conn->error_info TSRMLS_CC))
|
||||||
|
{
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -952,13 +954,13 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND * conn,
|
||||||
err:
|
err:
|
||||||
PACKET_FREE(greet_packet);
|
PACKET_FREE(greet_packet);
|
||||||
|
|
||||||
if (errstr) {
|
DBG_ERR_FMT("[%u] %.128s (trying to connect via %s)", conn->error_info.error_no, conn->error_info.error, conn->scheme);
|
||||||
DBG_ERR_FMT("[%u] %.128s (trying to connect via %s)", errcode, errstr, conn->scheme);
|
if (!conn->error_info.error_no) {
|
||||||
SET_CLIENT_ERROR(conn->error_info, errcode? errcode:CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, errstr);
|
SET_CLIENT_ERROR(conn->error_info, CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, conn->error_info.error? conn->error_info.error:"Unknown error");
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "[%u] %.128s (trying to connect via %s)", errcode, errstr, conn->scheme);
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "[%u] %.128s (trying to connect via %s)",
|
||||||
/* no mnd_ since we don't allocate it */
|
conn->error_info.error_no, conn->error_info.error, conn->scheme);
|
||||||
efree(errstr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->m->free_contents(conn TSRMLS_CC);
|
conn->m->free_contents(conn TSRMLS_CC);
|
||||||
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_CONNECT_FAILURE);
|
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_CONNECT_FAILURE);
|
||||||
|
|
||||||
|
@ -1680,7 +1682,7 @@ MYSQLND_METHOD(mysqlnd_conn, close)(MYSQLND * conn, enum_connection_close_type c
|
||||||
DBG_ENTER("mysqlnd_conn::close");
|
DBG_ENTER("mysqlnd_conn::close");
|
||||||
DBG_INF_FMT("conn=%llu", conn->thread_id);
|
DBG_INF_FMT("conn=%llu", conn->thread_id);
|
||||||
|
|
||||||
if (conn->state >= CONN_READY) {
|
if (CONN_GET_STATE(conn) >= CONN_READY) {
|
||||||
MYSQLND_INC_CONN_STATISTIC(conn->stats, statistic);
|
MYSQLND_INC_CONN_STATISTIC(conn->stats, statistic);
|
||||||
MYSQLND_DEC_CONN_STATISTIC(conn->stats, STAT_OPENED_CONNECTIONS);
|
MYSQLND_DEC_CONN_STATISTIC(conn->stats, STAT_OPENED_CONNECTIONS);
|
||||||
if (conn->persistent) {
|
if (conn->persistent) {
|
||||||
|
@ -2483,7 +2485,7 @@ MYSQLND_METHOD(mysqlnd_conn, init)(MYSQLND * conn TSRMLS_DC)
|
||||||
mysqlnd_stats_init(&conn->stats, STAT_LAST);
|
mysqlnd_stats_init(&conn->stats, STAT_LAST);
|
||||||
SET_ERROR_AFF_ROWS(conn);
|
SET_ERROR_AFF_ROWS(conn);
|
||||||
|
|
||||||
conn->net = mysqlnd_net_init(conn->persistent TSRMLS_CC);
|
conn->net = mysqlnd_net_init(conn->persistent, conn->stats, &conn->error_info TSRMLS_CC);
|
||||||
conn->protocol = mysqlnd_protocol_init(conn->persistent TSRMLS_CC);
|
conn->protocol = mysqlnd_protocol_init(conn->persistent TSRMLS_CC);
|
||||||
|
|
||||||
DBG_RETURN(conn->stats && conn->net && conn->protocol? PASS:FAIL);
|
DBG_RETURN(conn->stats && conn->net && conn->protocol? PASS:FAIL);
|
||||||
|
|
|
@ -105,8 +105,6 @@ mysqlnd_auth_handshake(MYSQLND * conn,
|
||||||
auth_packet->auth_plugin_name = auth_protocol;
|
auth_packet->auth_plugin_name = auth_protocol;
|
||||||
|
|
||||||
if (!PACKET_WRITE(auth_packet, conn)) {
|
if (!PACKET_WRITE(auth_packet, conn)) {
|
||||||
CONN_SET_STATE(conn, CONN_QUIT_SENT);
|
|
||||||
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,20 +162,21 @@ mysqlnd_handle_local_infile(MYSQLND *conn, const char *filename, zend_bool *is_w
|
||||||
int bufsize;
|
int bufsize;
|
||||||
size_t ret;
|
size_t ret;
|
||||||
MYSQLND_INFILE infile;
|
MYSQLND_INFILE infile;
|
||||||
|
MYSQLND_NET * net = conn->net;
|
||||||
|
|
||||||
DBG_ENTER("mysqlnd_handle_local_infile");
|
DBG_ENTER("mysqlnd_handle_local_infile");
|
||||||
|
|
||||||
if (!(conn->options.flags & CLIENT_LOCAL_FILES)) {
|
if (!(conn->options.flags & CLIENT_LOCAL_FILES)) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "LOAD DATA LOCAL INFILE forbidden");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "LOAD DATA LOCAL INFILE forbidden");
|
||||||
/* write empty packet to server */
|
/* write empty packet to server */
|
||||||
ret = conn->net->m.send(conn, empty_packet, 0 TSRMLS_CC);
|
ret = net->m.send_ex(net, empty_packet, 0, conn->stats, &conn->error_info TSRMLS_CC);
|
||||||
*is_warning = TRUE;
|
*is_warning = TRUE;
|
||||||
goto infile_error;
|
goto infile_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
infile = conn->infile;
|
infile = conn->infile;
|
||||||
/* allocate buffer for reading data */
|
/* allocate buffer for reading data */
|
||||||
buf = (zend_uchar *)mnd_ecalloc(1, buflen);
|
buf = (zend_uchar *) mnd_ecalloc(1, buflen);
|
||||||
|
|
||||||
*is_warning = FALSE;
|
*is_warning = FALSE;
|
||||||
|
|
||||||
|
@ -188,13 +189,13 @@ mysqlnd_handle_local_infile(MYSQLND *conn, const char *filename, zend_bool *is_w
|
||||||
tmp_error_no = infile.local_infile_error(info, tmp_buf, sizeof(tmp_buf) TSRMLS_CC);
|
tmp_error_no = infile.local_infile_error(info, tmp_buf, sizeof(tmp_buf) TSRMLS_CC);
|
||||||
SET_CLIENT_ERROR(conn->error_info, tmp_error_no, UNKNOWN_SQLSTATE, tmp_buf);
|
SET_CLIENT_ERROR(conn->error_info, tmp_error_no, UNKNOWN_SQLSTATE, tmp_buf);
|
||||||
/* write empty packet to server */
|
/* write empty packet to server */
|
||||||
ret = conn->net->m.send(conn, empty_packet, 0 TSRMLS_CC);
|
ret = net->m.send_ex(net, empty_packet, 0, conn->stats, &conn->error_info TSRMLS_CC);
|
||||||
goto infile_error;
|
goto infile_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read data */
|
/* read data */
|
||||||
while ((bufsize = infile.local_infile_read (info, buf + MYSQLND_HEADER_SIZE, buflen - MYSQLND_HEADER_SIZE TSRMLS_CC)) > 0) {
|
while ((bufsize = infile.local_infile_read (info, buf + MYSQLND_HEADER_SIZE, buflen - MYSQLND_HEADER_SIZE TSRMLS_CC)) > 0) {
|
||||||
if ((ret = conn->net->m.send(conn, buf, bufsize TSRMLS_CC)) == 0) {
|
if ((ret = net->m.send_ex(net, buf, bufsize, conn->stats, &conn->error_info TSRMLS_CC)) == 0) {
|
||||||
DBG_ERR_FMT("Error during read : %d %s %s", CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
|
DBG_ERR_FMT("Error during read : %d %s %s", CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
|
||||||
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
|
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
|
||||||
goto infile_error;
|
goto infile_error;
|
||||||
|
@ -202,7 +203,7 @@ mysqlnd_handle_local_infile(MYSQLND *conn, const char *filename, zend_bool *is_w
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send empty packet for eof */
|
/* send empty packet for eof */
|
||||||
if ((ret = conn->net->m.send(conn, empty_packet, 0 TSRMLS_CC)) == 0) {
|
if ((ret = net->m.send_ex(net, empty_packet, 0, conn->stats, &conn->error_info TSRMLS_CC)) == 0) {
|
||||||
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
|
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
|
||||||
goto infile_error;
|
goto infile_error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,48 +59,88 @@ mysqlnd_set_sock_no_delay(php_stream * stream TSRMLS_DC)
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ mysqlnd_net::network_read */
|
/* {{{ mysqlnd_net::network_read_ex */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
MYSQLND_METHOD(mysqlnd_net, network_read)(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC)
|
MYSQLND_METHOD(mysqlnd_net, network_read_ex)(MYSQLND_NET * const net, zend_uchar * const buffer, const size_t count,
|
||||||
|
MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
{
|
{
|
||||||
enum_func_status return_value = PASS;
|
enum_func_status return_value = PASS;
|
||||||
size_t to_read = count, ret;
|
size_t to_read = count, ret;
|
||||||
size_t old_chunk_size = conn->net->stream->chunk_size;
|
size_t old_chunk_size = net->stream->chunk_size;
|
||||||
DBG_ENTER("mysqlnd_net::network_read");
|
zend_uchar * p = buffer;
|
||||||
|
|
||||||
|
DBG_ENTER("mysqlnd_net::network_read_ex");
|
||||||
DBG_INF_FMT("count="MYSQLND_SZ_T_SPEC, count);
|
DBG_INF_FMT("count="MYSQLND_SZ_T_SPEC, count);
|
||||||
conn->net->stream->chunk_size = MIN(to_read, conn->net->options.net_read_buffer_size);
|
|
||||||
|
net->stream->chunk_size = MIN(to_read, net->options.net_read_buffer_size);
|
||||||
while (to_read) {
|
while (to_read) {
|
||||||
if (!(ret = php_stream_read(conn->net->stream, (char *) buffer, to_read))) {
|
if (!(ret = php_stream_read(net->stream, (char *) p, to_read))) {
|
||||||
DBG_ERR_FMT("Error while reading header from socket");
|
DBG_ERR_FMT("Error while reading header from socket");
|
||||||
return_value = FAIL;
|
return_value = FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buffer += ret;
|
p += ret;
|
||||||
to_read -= ret;
|
to_read -= ret;
|
||||||
}
|
}
|
||||||
MYSQLND_INC_CONN_STATISTIC_W_VALUE(conn->stats, STAT_BYTES_RECEIVED, count - to_read);
|
MYSQLND_INC_CONN_STATISTIC_W_VALUE(stats, STAT_BYTES_RECEIVED, count - to_read);
|
||||||
conn->net->stream->chunk_size = old_chunk_size;
|
net->stream->chunk_size = old_chunk_size;
|
||||||
DBG_RETURN(return_value);
|
DBG_RETURN(return_value);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ mysqlnd_net::network_write */
|
/* {{{ mysqlnd_net::network_write_ex */
|
||||||
static size_t
|
static size_t
|
||||||
MYSQLND_METHOD(mysqlnd_net, network_write)(MYSQLND * const conn, const zend_uchar * const buf, size_t count TSRMLS_DC)
|
MYSQLND_METHOD(mysqlnd_net, network_write_ex)(MYSQLND_NET * const net, const zend_uchar * const buffer, const size_t count,
|
||||||
|
MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
{
|
{
|
||||||
size_t ret;
|
size_t ret;
|
||||||
DBG_ENTER("mysqlnd_net::network_write");
|
DBG_ENTER("mysqlnd_net::network_write_ex");
|
||||||
ret = php_stream_write(conn->net->stream, (char *)buf, count);
|
ret = php_stream_write(net->stream, (char *)buffer, count);
|
||||||
DBG_RETURN(ret);
|
DBG_RETURN(ret);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ mysqlnd_net::open_pipe */
|
||||||
|
|
||||||
/* {{{ mysqlnd_net::connect */
|
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
MYSQLND_METHOD(mysqlnd_net, connect)(MYSQLND_NET * net, const char * const scheme, size_t scheme_len, zend_bool persistent, char **errstr, int * errcode TSRMLS_DC)
|
MYSQLND_METHOD(mysqlnd_net, open_pipe)(MYSQLND_NET * const net, const char * const scheme, const size_t scheme_len,
|
||||||
|
const zend_bool persistent,
|
||||||
|
MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
|
{
|
||||||
|
#if PHP_API_VERSION < 20100412
|
||||||
|
unsigned int streams_options = ENFORCE_SAFE_MODE;
|
||||||
|
#else
|
||||||
|
unsigned int streams_options = 0;
|
||||||
|
#endif
|
||||||
|
DBG_ENTER("mysqlnd_net::open_pipe");
|
||||||
|
if (persistent) {
|
||||||
|
streams_options |= STREAM_OPEN_PERSISTENT;
|
||||||
|
}
|
||||||
|
streams_options |= IGNORE_URL;
|
||||||
|
net->stream = php_stream_open_wrapper((char*) scheme + sizeof("pipe://") - 1, "r+", streams_options, NULL);
|
||||||
|
if (!net->stream) {
|
||||||
|
SET_CLIENT_ERROR(*error_info, CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, "Unknown errror while connecting");
|
||||||
|
DBG_RETURN(FAIL);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Streams are not meant for C extensions! Thus we need a hack. Every connected stream will
|
||||||
|
be registered as resource (in EG(regular_list). So far, so good. However, it won't be
|
||||||
|
unregistered yntil the script ends. So, we need to take care of that.
|
||||||
|
*/
|
||||||
|
net->stream->in_free = 1;
|
||||||
|
zend_hash_index_del(&EG(regular_list), net->stream->rsrc_id);
|
||||||
|
net->stream->in_free = 0;
|
||||||
|
|
||||||
|
DBG_RETURN(PASS);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
|
/* {{{ mysqlnd_net::open_tcp_or_unix */
|
||||||
|
static enum_func_status
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, open_tcp_or_unix)(MYSQLND_NET * const net, const char * const scheme, const size_t scheme_len,
|
||||||
|
const zend_bool persistent,
|
||||||
|
MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
{
|
{
|
||||||
#if PHP_API_VERSION < 20100412
|
#if PHP_API_VERSION < 20100412
|
||||||
unsigned int streams_options = ENFORCE_SAFE_MODE;
|
unsigned int streams_options = ENFORCE_SAFE_MODE;
|
||||||
|
@ -110,52 +150,39 @@ MYSQLND_METHOD(mysqlnd_net, connect)(MYSQLND_NET * net, const char * const schem
|
||||||
unsigned int streams_flags = STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT;
|
unsigned int streams_flags = STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT;
|
||||||
char * hashed_details = NULL;
|
char * hashed_details = NULL;
|
||||||
int hashed_details_len = 0;
|
int hashed_details_len = 0;
|
||||||
|
char * errstr = NULL;
|
||||||
|
int errcode = 0;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
DBG_ENTER("mysqlnd_net::connect");
|
|
||||||
|
|
||||||
net->packet_no = net->compressed_envelope_packet_no = 0;
|
DBG_ENTER("mysqlnd_net::open_tcp_or_unix");
|
||||||
|
|
||||||
if (net->stream) {
|
if (persistent) {
|
||||||
/* close before opening a new one */
|
hashed_details_len = mnd_sprintf(&hashed_details, 0, "%p", net);
|
||||||
DBG_INF_FMT("Freeing stream. abstract=%p", net->stream->abstract);
|
DBG_INF_FMT("hashed_details=%s", hashed_details);
|
||||||
if (net->persistent) {
|
|
||||||
php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR);
|
|
||||||
} else {
|
|
||||||
php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE);
|
|
||||||
}
|
|
||||||
net->stream = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scheme_len > (sizeof("pipe://") - 1) && !memcmp(scheme, "pipe://", sizeof("pipe://") - 1)) {
|
if (net->options.timeout_connect) {
|
||||||
if (persistent) {
|
tv.tv_sec = net->options.timeout_connect;
|
||||||
streams_options |= STREAM_OPEN_PERSISTENT;
|
tv.tv_usec = 0;
|
||||||
}
|
|
||||||
streams_options |= IGNORE_URL;
|
|
||||||
net->stream = php_stream_open_wrapper((char*) scheme + sizeof("pipe://") - 1, "r+", streams_options, NULL);
|
|
||||||
} else {
|
|
||||||
if (persistent) {
|
|
||||||
hashed_details_len = mnd_sprintf(&hashed_details, 0, "%p", net);
|
|
||||||
DBG_INF_FMT("hashed_details=%s", hashed_details);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (net->options.timeout_connect) {
|
|
||||||
tv.tv_sec = net->options.timeout_connect;
|
|
||||||
tv.tv_usec = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
DBG_INF_FMT("calling php_stream_xport_create");
|
|
||||||
net->stream = php_stream_xport_create(scheme, scheme_len, streams_options, streams_flags,
|
|
||||||
hashed_details, (net->options.timeout_connect) ? &tv : NULL,
|
|
||||||
NULL /*ctx*/, errstr, errcode);
|
|
||||||
}
|
}
|
||||||
if (*errstr || !net->stream) {
|
|
||||||
|
DBG_INF_FMT("calling php_stream_xport_create");
|
||||||
|
net->stream = php_stream_xport_create(scheme, scheme_len, streams_options, streams_flags,
|
||||||
|
hashed_details, (net->options.timeout_connect) ? &tv : NULL,
|
||||||
|
NULL /*ctx*/, &errstr, &errcode);
|
||||||
|
if (errstr || !net->stream) {
|
||||||
|
DBG_ERR("Error");
|
||||||
if (hashed_details) {
|
if (hashed_details) {
|
||||||
mnd_sprintf_free(hashed_details);
|
mnd_sprintf_free(hashed_details);
|
||||||
}
|
}
|
||||||
*errcode = CR_CONNECTION_ERROR;
|
errcode = CR_CONNECTION_ERROR;
|
||||||
|
SET_CLIENT_ERROR(*error_info, errcode? errcode:CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, errstr);
|
||||||
|
if (errstr) {
|
||||||
|
/* no mnd_ since we don't allocate it */
|
||||||
|
efree(errstr);
|
||||||
|
}
|
||||||
DBG_RETURN(FAIL);
|
DBG_RETURN(FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashed_details) {
|
if (hashed_details) {
|
||||||
/*
|
/*
|
||||||
If persistent, the streams register it in EG(persistent_list).
|
If persistent, the streams register it in EG(persistent_list).
|
||||||
|
@ -180,20 +207,30 @@ MYSQLND_METHOD(mysqlnd_net, connect)(MYSQLND_NET * net, const char * const schem
|
||||||
#endif
|
#endif
|
||||||
mnd_sprintf_free(hashed_details);
|
mnd_sprintf_free(hashed_details);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Streams are not meant for C extensions! Thus we need a hack. Every connected stream will
|
Streams are not meant for C extensions! Thus we need a hack. Every connected stream will
|
||||||
be registered as resource (in EG(regular_list). So far, so good. However, it won't be
|
be registered as resource (in EG(regular_list). So far, so good. However, it won't be
|
||||||
unregistered till the script ends. So, we need to take care of that.
|
unregistered yntil the script ends. So, we need to take care of that.
|
||||||
*/
|
*/
|
||||||
net->stream->in_free = 1;
|
net->stream->in_free = 1;
|
||||||
zend_hash_index_del(&EG(regular_list), net->stream->rsrc_id);
|
zend_hash_index_del(&EG(regular_list), net->stream->rsrc_id);
|
||||||
net->stream->in_free = 0;
|
net->stream->in_free = 0;
|
||||||
|
|
||||||
if (!net->options.timeout_read) {
|
DBG_RETURN(PASS);
|
||||||
/* should always happen because read_timeout cannot be set via API */
|
}
|
||||||
net->options.timeout_read = (unsigned int) MYSQLND_G(net_read_timeout);
|
/* }}} */
|
||||||
}
|
|
||||||
|
|
||||||
|
/* {{{ mysqlnd_net::connect_ex */
|
||||||
|
static void
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, post_connect_set_opt)(MYSQLND_NET * const net,
|
||||||
|
const char * const scheme, const size_t scheme_len,
|
||||||
|
MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
|
{
|
||||||
|
DBG_ENTER("mysqlnd_net::post_connect_set_opt");
|
||||||
if (net->options.timeout_read) {
|
if (net->options.timeout_read) {
|
||||||
|
struct timeval tv;
|
||||||
DBG_INF_FMT("setting %u as PHP_STREAM_OPTION_READ_TIMEOUT", net->options.timeout_read);
|
DBG_INF_FMT("setting %u as PHP_STREAM_OPTION_READ_TIMEOUT", net->options.timeout_read);
|
||||||
tv.tv_sec = net->options.timeout_read;
|
tv.tv_sec = net->options.timeout_read;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
@ -205,13 +242,33 @@ MYSQLND_METHOD(mysqlnd_net, connect)(MYSQLND_NET * net, const char * const schem
|
||||||
mysqlnd_set_sock_no_delay(net->stream TSRMLS_CC);
|
mysqlnd_set_sock_no_delay(net->stream TSRMLS_CC);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
DBG_VOID_RETURN;
|
||||||
unsigned int buf_size = MYSQLND_G(net_read_buffer_size); /* this is long, cast to unsigned int*/
|
}
|
||||||
net->m.set_client_option(net, MYSQLND_OPT_NET_READ_BUFFER_SIZE, (char *)&buf_size TSRMLS_CC);
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
|
/* {{{ mysqlnd_net::connect_ex */
|
||||||
|
static enum_func_status
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, connect_ex)(MYSQLND_NET * const net, const char * const scheme, const size_t scheme_len,
|
||||||
|
const zend_bool persistent,
|
||||||
|
MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
|
{
|
||||||
|
enum_func_status ret = FAIL;
|
||||||
|
func_mysqlnd_net__open_stream open_stream = NULL;
|
||||||
|
DBG_ENTER("mysqlnd_net::connect_ex");
|
||||||
|
|
||||||
|
net->packet_no = net->compressed_envelope_packet_no = 0;
|
||||||
|
|
||||||
|
net->m.close_stream(net, conn_stats, error_info TSRMLS_CC);
|
||||||
|
|
||||||
|
open_stream = (scheme_len > (sizeof("pipe://") - 1) && !memcmp(scheme, "pipe://", sizeof("pipe://") - 1))? net->m.open_pipe:
|
||||||
|
net->m.open_tcp_or_unix;
|
||||||
|
|
||||||
|
if (PASS == (ret = open_stream(net, scheme, scheme_len, persistent, conn_stats, error_info TSRMLS_CC))) {
|
||||||
|
net->m.post_connect_set_opt(net, scheme, scheme_len, conn_stats, error_info TSRMLS_CC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBG_RETURN(ret);
|
||||||
DBG_RETURN(PASS);
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -225,34 +282,32 @@ MYSQLND_METHOD(mysqlnd_net, connect)(MYSQLND_NET * net, const char * const schem
|
||||||
#define STORE_HEADER_SIZE(safe_storage, buffer) COPY_HEADER((safe_storage), (buffer))
|
#define STORE_HEADER_SIZE(safe_storage, buffer) COPY_HEADER((safe_storage), (buffer))
|
||||||
#define RESTORE_HEADER_SIZE(buffer, safe_storage) STORE_HEADER_SIZE((safe_storage), (buffer))
|
#define RESTORE_HEADER_SIZE(buffer, safe_storage) STORE_HEADER_SIZE((safe_storage), (buffer))
|
||||||
|
|
||||||
/* {{{ mysqlnd_net::send */
|
|
||||||
|
/* {{{ mysqlnd_net::send_ex */
|
||||||
/*
|
/*
|
||||||
IMPORTANT : It's expected that buf has place in the beginning for MYSQLND_HEADER_SIZE !!!!
|
IMPORTANT : It's expected that buffer has place in the beginning for MYSQLND_HEADER_SIZE !!!!
|
||||||
This is done for performance reasons in the caller of this function.
|
This is done for performance reasons in the caller of this function.
|
||||||
Otherwise we will have to do send two TCP packets, or do new alloc and memcpy.
|
Otherwise we will have to do send two TCP packets, or do new alloc and memcpy.
|
||||||
Neither are quick, thus the clients of this function are obligated to do
|
Neither are quick, thus the clients of this function are obligated to do
|
||||||
what they are asked for.
|
what they are asked for.
|
||||||
|
|
||||||
`count` is actually the length of the payload data. Thus :
|
`count` is actually the length of the payload data. Thus :
|
||||||
count + MYSQLND_HEADER_SIZE = sizeof(buf) (not the pointer but the actual buffer)
|
count + MYSQLND_HEADER_SIZE = sizeof(buffer) (not the pointer but the actual buffer)
|
||||||
*/
|
*/
|
||||||
size_t
|
static size_t
|
||||||
MYSQLND_METHOD(mysqlnd_net, send)(MYSQLND * const conn, zend_uchar * const buf, size_t count TSRMLS_DC)
|
MYSQLND_METHOD(mysqlnd_net, send_ex)(MYSQLND_NET * const net, zend_uchar * const buffer, const size_t count,
|
||||||
|
MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
{
|
{
|
||||||
zend_uchar safe_buf[((MYSQLND_HEADER_SIZE) + (sizeof(zend_uchar)) - 1) / (sizeof(zend_uchar))];
|
zend_uchar safe_buf[((MYSQLND_HEADER_SIZE) + (sizeof(zend_uchar)) - 1) / (sizeof(zend_uchar))];
|
||||||
zend_uchar *safe_storage = safe_buf;
|
zend_uchar * safe_storage = safe_buf;
|
||||||
MYSQLND_NET *net = conn->net;
|
size_t bytes_sent, packets_sent = 1;
|
||||||
size_t old_chunk_size = net->stream->chunk_size;
|
|
||||||
size_t ret, packets_sent = 1;
|
|
||||||
size_t left = count;
|
size_t left = count;
|
||||||
zend_uchar *p = (zend_uchar *) buf;
|
zend_uchar * p = (zend_uchar *) buffer;
|
||||||
zend_uchar * compress_buf = NULL;
|
zend_uchar * compress_buf = NULL;
|
||||||
size_t to_be_sent;
|
size_t to_be_sent;
|
||||||
|
|
||||||
DBG_ENTER("mysqlnd_net::send");
|
DBG_ENTER("mysqlnd_net::send_ex");
|
||||||
DBG_INF_FMT("conn=%llu count=" MYSQLND_SZ_T_SPEC " compression=%u", conn->thread_id, count, net->compressed);
|
DBG_INF_FMT("count=" MYSQLND_SZ_T_SPEC " compression=%u", count, net->compressed);
|
||||||
|
|
||||||
net->stream->chunk_size = MYSQLND_MAX_PACKET_SIZE;
|
|
||||||
|
|
||||||
if (net->compressed == TRUE) {
|
if (net->compressed == TRUE) {
|
||||||
size_t comp_buf_size = MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE + MYSQLND_HEADER_SIZE + MIN(left, MYSQLND_MAX_PACKET_SIZE);
|
size_t comp_buf_size = MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE + MYSQLND_HEADER_SIZE + MIN(left, MYSQLND_MAX_PACKET_SIZE);
|
||||||
|
@ -287,7 +342,8 @@ MYSQLND_METHOD(mysqlnd_net, send)(MYSQLND * const conn, zend_uchar * const buf,
|
||||||
int3store(compress_buf, payload_size);
|
int3store(compress_buf, payload_size);
|
||||||
int1store(compress_buf + 3, net->packet_no);
|
int1store(compress_buf + 3, net->packet_no);
|
||||||
DBG_INF_FMT("writing "MYSQLND_SZ_T_SPEC" bytes to the network", payload_size + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE);
|
DBG_INF_FMT("writing "MYSQLND_SZ_T_SPEC" bytes to the network", payload_size + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE);
|
||||||
ret = conn->net->m.network_write(conn, compress_buf, payload_size + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE TSRMLS_CC);
|
bytes_sent = net->m.network_write_ex(net, compress_buf, payload_size + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE,
|
||||||
|
conn_stats, error_info TSRMLS_CC);
|
||||||
net->compressed_envelope_packet_no++;
|
net->compressed_envelope_packet_no++;
|
||||||
#if WHEN_WE_NEED_TO_CHECK_WHETHER_COMPRESSION_WORKS_CORRECTLY
|
#if WHEN_WE_NEED_TO_CHECK_WHETHER_COMPRESSION_WORKS_CORRECTLY
|
||||||
if (res == Z_OK) {
|
if (res == Z_OK) {
|
||||||
|
@ -318,7 +374,7 @@ MYSQLND_METHOD(mysqlnd_net, send)(MYSQLND * const conn, zend_uchar * const buf,
|
||||||
STORE_HEADER_SIZE(safe_storage, p);
|
STORE_HEADER_SIZE(safe_storage, p);
|
||||||
int3store(p, to_be_sent);
|
int3store(p, to_be_sent);
|
||||||
int1store(p + 3, net->packet_no);
|
int1store(p + 3, net->packet_no);
|
||||||
ret = conn->net->m.network_write(conn, p, to_be_sent + MYSQLND_HEADER_SIZE TSRMLS_CC);
|
bytes_sent = net->m.network_write_ex(net, p, to_be_sent + MYSQLND_HEADER_SIZE, conn_stats, error_info TSRMLS_CC);
|
||||||
RESTORE_HEADER_SIZE(p, safe_storage);
|
RESTORE_HEADER_SIZE(p, safe_storage);
|
||||||
net->compressed_envelope_packet_no++;
|
net->compressed_envelope_packet_no++;
|
||||||
}
|
}
|
||||||
|
@ -334,26 +390,25 @@ MYSQLND_METHOD(mysqlnd_net, send)(MYSQLND * const conn, zend_uchar * const buf,
|
||||||
indeed it then loop once more, then to_be_sent will become 0, left will stay 0. Empty
|
indeed it then loop once more, then to_be_sent will become 0, left will stay 0. Empty
|
||||||
packet will be sent and this loop will end.
|
packet will be sent and this loop will end.
|
||||||
*/
|
*/
|
||||||
} while (ret && (left > 0 || to_be_sent == MYSQLND_MAX_PACKET_SIZE));
|
} while (bytes_sent && (left > 0 || to_be_sent == MYSQLND_MAX_PACKET_SIZE));
|
||||||
|
|
||||||
DBG_INF_FMT("packet_size="MYSQLND_SZ_T_SPEC" packet_no=%u", left, net->packet_no);
|
DBG_INF_FMT("packet_size="MYSQLND_SZ_T_SPEC" packet_no=%u", left, net->packet_no);
|
||||||
/* Even for zero size payload we have to send a packet */
|
|
||||||
if (!ret) {
|
|
||||||
DBG_ERR_FMT("Can't %u send bytes", count);
|
|
||||||
conn->state = CONN_QUIT_SENT;
|
|
||||||
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
|
|
||||||
}
|
|
||||||
|
|
||||||
MYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn->stats,
|
MYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn_stats,
|
||||||
STAT_BYTES_SENT, count + packets_sent * MYSQLND_HEADER_SIZE,
|
STAT_BYTES_SENT, count + packets_sent * MYSQLND_HEADER_SIZE,
|
||||||
STAT_PROTOCOL_OVERHEAD_OUT, packets_sent * MYSQLND_HEADER_SIZE,
|
STAT_PROTOCOL_OVERHEAD_OUT, packets_sent * MYSQLND_HEADER_SIZE,
|
||||||
STAT_PACKETS_SENT, packets_sent);
|
STAT_PACKETS_SENT, packets_sent);
|
||||||
|
|
||||||
net->stream->chunk_size = old_chunk_size;
|
|
||||||
if (compress_buf) {
|
if (compress_buf) {
|
||||||
mnd_efree(compress_buf);
|
mnd_efree(compress_buf);
|
||||||
}
|
}
|
||||||
DBG_RETURN(ret);
|
|
||||||
|
/* Even for zero size payload we have to send a packet */
|
||||||
|
if (!bytes_sent) {
|
||||||
|
DBG_ERR_FMT("Can't %u send bytes", count);
|
||||||
|
SET_CLIENT_ERROR(*error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
|
||||||
|
}
|
||||||
|
DBG_RETURN(bytes_sent);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -423,19 +478,19 @@ mysqlnd_create_read_buffer(size_t count TSRMLS_DC)
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer */
|
/* {{{ mysqlnd_net::read_compressed_packet_from_stream_and_fill_read_buffer */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer(MYSQLND * conn, size_t net_payload_size TSRMLS_DC)
|
MYSQLND_METHOD(mysqlnd_net, read_compressed_packet_from_stream_and_fill_read_buffer)
|
||||||
|
(MYSQLND_NET * net, size_t net_payload_size, MYSQLND_STATS * conn_stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_NET * net = conn->net;
|
|
||||||
size_t decompressed_size;
|
size_t decompressed_size;
|
||||||
enum_func_status ret = PASS;
|
enum_func_status ret = PASS;
|
||||||
zend_uchar * compressed_data = NULL;
|
zend_uchar * compressed_data = NULL;
|
||||||
zend_uchar comp_header[COMPRESSED_HEADER_SIZE];
|
zend_uchar comp_header[COMPRESSED_HEADER_SIZE];
|
||||||
DBG_ENTER("mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer");
|
DBG_ENTER("mysqlnd_net::read_compressed_packet_from_stream_and_fill_read_buffe");
|
||||||
|
|
||||||
/* Read the compressed header */
|
/* Read the compressed header */
|
||||||
if (FAIL == conn->net->m.network_read(conn, comp_header, COMPRESSED_HEADER_SIZE TSRMLS_CC)) {
|
if (FAIL == net->m.network_read_ex(net, comp_header, COMPRESSED_HEADER_SIZE, conn_stats, error_info TSRMLS_CC)) {
|
||||||
DBG_RETURN(FAIL);
|
DBG_RETURN(FAIL);
|
||||||
}
|
}
|
||||||
decompressed_size = uint3korr(comp_header);
|
decompressed_size = uint3korr(comp_header);
|
||||||
|
@ -445,7 +500,7 @@ mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer(MYSQLND * conn,
|
||||||
|
|
||||||
if (decompressed_size) {
|
if (decompressed_size) {
|
||||||
compressed_data = mnd_emalloc(net_payload_size);
|
compressed_data = mnd_emalloc(net_payload_size);
|
||||||
if (FAIL == conn->net->m.network_read(conn, compressed_data, net_payload_size TSRMLS_CC)) {
|
if (FAIL == net->m.network_read_ex(net, compressed_data, net_payload_size, conn_stats, error_info TSRMLS_CC)) {
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -457,7 +512,7 @@ mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer(MYSQLND * conn,
|
||||||
} else {
|
} else {
|
||||||
DBG_INF_FMT("The server decided not to compress the data. Our job is easy. Copying %u bytes", net_payload_size);
|
DBG_INF_FMT("The server decided not to compress the data. Our job is easy. Copying %u bytes", net_payload_size);
|
||||||
net->uncompressed_data = mysqlnd_create_read_buffer(net_payload_size TSRMLS_CC);
|
net->uncompressed_data = mysqlnd_create_read_buffer(net_payload_size TSRMLS_CC);
|
||||||
if (FAIL == conn->net->m.network_read(conn, net->uncompressed_data->data, net_payload_size TSRMLS_CC)) {
|
if (FAIL == net->m.network_read_ex(net, net->uncompressed_data->data, net_payload_size, conn_stats, error_info TSRMLS_CC)) {
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -474,8 +529,8 @@ end:
|
||||||
|
|
||||||
/* {{{ mysqlnd_net::decode */
|
/* {{{ mysqlnd_net::decode */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
MYSQLND_METHOD(mysqlnd_net, decode)(zend_uchar * uncompressed_data, size_t uncompressed_data_len,
|
MYSQLND_METHOD(mysqlnd_net, decode)(zend_uchar * uncompressed_data, const size_t uncompressed_data_len,
|
||||||
const zend_uchar * const compressed_data, size_t compressed_data_len TSRMLS_DC)
|
const zend_uchar * const compressed_data, const size_t compressed_data_len TSRMLS_DC)
|
||||||
{
|
{
|
||||||
#ifdef MYSQLND_COMPRESSION_ENABLED
|
#ifdef MYSQLND_COMPRESSION_ENABLED
|
||||||
int error;
|
int error;
|
||||||
|
@ -499,7 +554,7 @@ MYSQLND_METHOD(mysqlnd_net, decode)(zend_uchar * uncompressed_data, size_t uncom
|
||||||
/* {{{ mysqlnd_net::encode */
|
/* {{{ mysqlnd_net::encode */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
MYSQLND_METHOD(mysqlnd_net, encode)(zend_uchar * compress_buffer, size_t * compress_buffer_len,
|
MYSQLND_METHOD(mysqlnd_net, encode)(zend_uchar * compress_buffer, size_t * compress_buffer_len,
|
||||||
const zend_uchar * const uncompressed_data, size_t uncompressed_data_len TSRMLS_DC)
|
const zend_uchar * const uncompressed_data, const size_t uncompressed_data_len TSRMLS_DC)
|
||||||
{
|
{
|
||||||
#ifdef MYSQLND_COMPRESSION_ENABLED
|
#ifdef MYSQLND_COMPRESSION_ENABLED
|
||||||
int error;
|
int error;
|
||||||
|
@ -523,15 +578,15 @@ MYSQLND_METHOD(mysqlnd_net, encode)(zend_uchar * compress_buffer, size_t * compr
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ mysqlnd_net::receive */
|
/* {{{ mysqlnd_net::receive_ex */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
MYSQLND_METHOD(mysqlnd_net, receive)(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC)
|
MYSQLND_METHOD(mysqlnd_net, receive_ex)(MYSQLND_NET * const net, zend_uchar * const buffer, const size_t count,
|
||||||
|
MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
{
|
{
|
||||||
size_t to_read = count;
|
size_t to_read = count;
|
||||||
zend_uchar * p = buffer;
|
zend_uchar * p = buffer;
|
||||||
MYSQLND_NET * net = conn->net;
|
|
||||||
|
|
||||||
DBG_ENTER("mysqlnd_net::receive");
|
DBG_ENTER("mysqlnd_net::receive_ex");
|
||||||
#ifdef MYSQLND_COMPRESSION_ENABLED
|
#ifdef MYSQLND_COMPRESSION_ENABLED
|
||||||
if (net->compressed) {
|
if (net->compressed) {
|
||||||
if (net->uncompressed_data) {
|
if (net->uncompressed_data) {
|
||||||
|
@ -553,7 +608,7 @@ MYSQLND_METHOD(mysqlnd_net, receive)(MYSQLND * conn, zend_uchar * buffer, size_t
|
||||||
size_t net_payload_size;
|
size_t net_payload_size;
|
||||||
zend_uchar packet_no;
|
zend_uchar packet_no;
|
||||||
|
|
||||||
if (FAIL == net->m.network_read(conn, net_header, MYSQLND_HEADER_SIZE TSRMLS_CC)) {
|
if (FAIL == net->m.network_read_ex(net, net_header, MYSQLND_HEADER_SIZE, conn_stats, error_info TSRMLS_CC)) {
|
||||||
DBG_RETURN(FAIL);
|
DBG_RETURN(FAIL);
|
||||||
}
|
}
|
||||||
net_payload_size = uint3korr(net_header);
|
net_payload_size = uint3korr(net_header);
|
||||||
|
@ -571,7 +626,7 @@ MYSQLND_METHOD(mysqlnd_net, receive)(MYSQLND * conn, zend_uchar * buffer, size_t
|
||||||
DBG_INF_FMT("HEADER: hwd_packet_no=%u size=%3u", packet_no, (unsigned long) net_payload_size);
|
DBG_INF_FMT("HEADER: hwd_packet_no=%u size=%3u", packet_no, (unsigned long) net_payload_size);
|
||||||
#endif
|
#endif
|
||||||
/* Now let's read from the wire, decompress it and fill the read buffer */
|
/* Now let's read from the wire, decompress it and fill the read buffer */
|
||||||
mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer(conn, net_payload_size TSRMLS_CC);
|
net->m.read_compressed_packet_from_stream_and_fill_read_buffer(net, net_payload_size, conn_stats, error_info TSRMLS_CC);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Now a bit of recursion - read from the read buffer,
|
Now a bit of recursion - read from the read buffer,
|
||||||
|
@ -579,12 +634,12 @@ MYSQLND_METHOD(mysqlnd_net, receive)(MYSQLND * conn, zend_uchar * buffer, size_t
|
||||||
is not enough, then the recursive call will try to
|
is not enough, then the recursive call will try to
|
||||||
satisfy it until it is satisfied.
|
satisfy it until it is satisfied.
|
||||||
*/
|
*/
|
||||||
DBG_RETURN(net->m.receive(conn, p, to_read TSRMLS_CC));
|
DBG_RETURN(net->m.receive_ex(net, p, to_read, conn_stats, error_info TSRMLS_CC));
|
||||||
}
|
}
|
||||||
DBG_RETURN(PASS);
|
DBG_RETURN(PASS);
|
||||||
}
|
}
|
||||||
#endif /* MYSQLND_COMPRESSION_ENABLED */
|
#endif /* MYSQLND_COMPRESSION_ENABLED */
|
||||||
DBG_RETURN(net->m.network_read(conn, p, to_read TSRMLS_CC));
|
DBG_RETURN(net->m.network_read_ex(net, p, to_read, conn_stats, error_info TSRMLS_CC));
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -675,10 +730,10 @@ MYSQLND_METHOD(mysqlnd_net, set_client_option)(MYSQLND_NET * const net, enum mys
|
||||||
case MYSQL_OPT_SSL_VERIFY_SERVER_CERT:
|
case MYSQL_OPT_SSL_VERIFY_SERVER_CERT:
|
||||||
net->options.ssl_verify_peer = value? ((*(zend_bool *)value)? TRUE:FALSE): FALSE;
|
net->options.ssl_verify_peer = value? ((*(zend_bool *)value)? TRUE:FALSE): FALSE;
|
||||||
break;
|
break;
|
||||||
#ifdef WHEN_SUPPORTED_BY_MYSQLI
|
|
||||||
case MYSQL_OPT_READ_TIMEOUT:
|
case MYSQL_OPT_READ_TIMEOUT:
|
||||||
net->options.timeout_read = *(unsigned int*) value;
|
net->options.timeout_read = *(unsigned int*) value;
|
||||||
break;
|
break;
|
||||||
|
#ifdef WHEN_SUPPORTED_BY_MYSQLI
|
||||||
case MYSQL_OPT_WRITE_TIMEOUT:
|
case MYSQL_OPT_WRITE_TIMEOUT:
|
||||||
net->options.timeout_write = *(unsigned int*) value;
|
net->options.timeout_write = *(unsigned int*) value;
|
||||||
break;
|
break;
|
||||||
|
@ -837,7 +892,7 @@ MYSQLND_METHOD(mysqlnd_net, disable_ssl)(MYSQLND_NET * const net TSRMLS_DC)
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ mysqlnd_net::set_client_option */
|
/* {{{ mysqlnd_net::free_contents */
|
||||||
static void
|
static void
|
||||||
MYSQLND_METHOD(mysqlnd_net, free_contents)(MYSQLND_NET * net TSRMLS_DC)
|
MYSQLND_METHOD(mysqlnd_net, free_contents)(MYSQLND_NET * net TSRMLS_DC)
|
||||||
{
|
{
|
||||||
|
@ -874,26 +929,112 @@ MYSQLND_METHOD(mysqlnd_net, free_contents)(MYSQLND_NET * net TSRMLS_DC)
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
|
/* {{{ mysqlnd_net::close_stream */
|
||||||
|
static void
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, close_stream)(MYSQLND_NET * const net, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
|
{
|
||||||
|
DBG_ENTER("mysqlnd_net::close_stream");
|
||||||
|
if (net && net->stream) {
|
||||||
|
zend_bool pers = net->persistent;
|
||||||
|
DBG_INF_FMT("Freeing stream. abstract=%p", net->stream->abstract);
|
||||||
|
if (pers) {
|
||||||
|
if (EG(active)) {
|
||||||
|
php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
otherwise we will crash because the EG(persistent_list) has been freed already,
|
||||||
|
before the modules are shut down
|
||||||
|
*/
|
||||||
|
php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE);
|
||||||
|
}
|
||||||
|
net->stream = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
DBG_VOID_RETURN;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
|
/* {{{ mysqlnd_net::init */
|
||||||
|
static enum_func_status
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, init)(MYSQLND_NET * const net, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
|
{
|
||||||
|
unsigned int buf_size;
|
||||||
|
DBG_ENTER("mysqlnd_net::init");
|
||||||
|
|
||||||
|
buf_size = MYSQLND_G(net_cmd_buffer_size); /* this is long, cast to unsigned int*/
|
||||||
|
net->m.set_client_option(net, MYSQLND_OPT_NET_CMD_BUFFER_SIZE, (char *) &buf_size TSRMLS_CC);
|
||||||
|
|
||||||
|
buf_size = MYSQLND_G(net_read_buffer_size); /* this is long, cast to unsigned int*/
|
||||||
|
net->m.set_client_option(net, MYSQLND_OPT_NET_READ_BUFFER_SIZE, (char *)&buf_size TSRMLS_CC);
|
||||||
|
|
||||||
|
buf_size = MYSQLND_G(net_read_timeout); /* this is long, cast to unsigned int*/
|
||||||
|
net->m.set_client_option(net, MYSQL_OPT_READ_TIMEOUT, (char *)&buf_size TSRMLS_CC);
|
||||||
|
|
||||||
|
DBG_RETURN(PASS);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
|
/* {{{ mysqlnd_net::dtor */
|
||||||
|
static void
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, dtor)(MYSQLND_NET * const net, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC)
|
||||||
|
{
|
||||||
|
DBG_ENTER("mysqlnd_net::dtor");
|
||||||
|
if (net) {
|
||||||
|
zend_bool pers = net->persistent;
|
||||||
|
|
||||||
|
net->m.free_contents(net TSRMLS_CC);
|
||||||
|
net->m.close_stream(net, stats, error_info TSRMLS_CC);
|
||||||
|
if (net->cmd_buffer.buffer) {
|
||||||
|
DBG_INF("Freeing cmd buffer");
|
||||||
|
mnd_pefree(net->cmd_buffer.buffer, pers);
|
||||||
|
net->cmd_buffer.buffer = NULL;
|
||||||
|
}
|
||||||
|
mnd_pefree(net, pers);
|
||||||
|
}
|
||||||
|
DBG_VOID_RETURN;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
MYSQLND_CLASS_METHODS_START(mysqlnd_net)
|
MYSQLND_CLASS_METHODS_START(mysqlnd_net)
|
||||||
MYSQLND_METHOD(mysqlnd_net, connect),
|
MYSQLND_METHOD(mysqlnd_net, init),
|
||||||
MYSQLND_METHOD(mysqlnd_net, send),
|
MYSQLND_METHOD(mysqlnd_net, dtor),
|
||||||
MYSQLND_METHOD(mysqlnd_net, receive),
|
MYSQLND_METHOD(mysqlnd_net, connect_ex),
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, close_stream),
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, open_pipe),
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, open_tcp_or_unix),
|
||||||
|
NULL, /* unused 1 */
|
||||||
|
NULL, /* unused 2 */
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, post_connect_set_opt),
|
||||||
MYSQLND_METHOD(mysqlnd_net, set_client_option),
|
MYSQLND_METHOD(mysqlnd_net, set_client_option),
|
||||||
MYSQLND_METHOD(mysqlnd_net, network_read),
|
|
||||||
MYSQLND_METHOD(mysqlnd_net, network_write),
|
|
||||||
MYSQLND_METHOD(mysqlnd_net, decode),
|
MYSQLND_METHOD(mysqlnd_net, decode),
|
||||||
MYSQLND_METHOD(mysqlnd_net, encode),
|
MYSQLND_METHOD(mysqlnd_net, encode),
|
||||||
MYSQLND_METHOD(mysqlnd_net, consume_uneaten_data),
|
MYSQLND_METHOD(mysqlnd_net, consume_uneaten_data),
|
||||||
MYSQLND_METHOD(mysqlnd_net, free_contents),
|
MYSQLND_METHOD(mysqlnd_net, free_contents),
|
||||||
MYSQLND_METHOD(mysqlnd_net, enable_ssl),
|
MYSQLND_METHOD(mysqlnd_net, enable_ssl),
|
||||||
MYSQLND_METHOD(mysqlnd_net, disable_ssl)
|
MYSQLND_METHOD(mysqlnd_net, disable_ssl),
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, network_read_ex),
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, network_write_ex),
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, send_ex),
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, receive_ex),
|
||||||
|
#ifdef MYSQLND_COMPRESSION_ENABLED
|
||||||
|
MYSQLND_METHOD(mysqlnd_net, read_compressed_packet_from_stream_and_fill_read_buffer)
|
||||||
|
#else
|
||||||
|
NULL
|
||||||
|
#endif
|
||||||
MYSQLND_CLASS_METHODS_END;
|
MYSQLND_CLASS_METHODS_END;
|
||||||
|
|
||||||
|
|
||||||
/* {{{ mysqlnd_net_init */
|
/* {{{ mysqlnd_net_init */
|
||||||
PHPAPI MYSQLND_NET *
|
PHPAPI MYSQLND_NET *
|
||||||
mysqlnd_net_init(zend_bool persistent TSRMLS_DC)
|
mysqlnd_net_init(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC)
|
||||||
{
|
{
|
||||||
size_t alloc_size = sizeof(MYSQLND_NET) + mysqlnd_plugin_count() * sizeof(void *);
|
size_t alloc_size = sizeof(MYSQLND_NET) + mysqlnd_plugin_count() * sizeof(void *);
|
||||||
MYSQLND_NET * net = mnd_pecalloc(1, alloc_size, persistent);
|
MYSQLND_NET * net = mnd_pecalloc(1, alloc_size, persistent);
|
||||||
|
@ -904,9 +1045,9 @@ mysqlnd_net_init(zend_bool persistent TSRMLS_DC)
|
||||||
net->persistent = persistent;
|
net->persistent = persistent;
|
||||||
net->m = mysqlnd_mysqlnd_net_methods;
|
net->m = mysqlnd_mysqlnd_net_methods;
|
||||||
|
|
||||||
{
|
if (PASS != net->m.init(net, stats, error_info TSRMLS_CC)) {
|
||||||
unsigned int buf_size = MYSQLND_G(net_cmd_buffer_size); /* this is long, cast to unsigned int*/
|
net->m.dtor(net, stats, error_info TSRMLS_CC);
|
||||||
net->m.set_client_option(net, MYSQLND_OPT_NET_CMD_BUFFER_SIZE, (char *) &buf_size TSRMLS_CC);
|
net = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DBG_RETURN(net);
|
DBG_RETURN(net);
|
||||||
|
@ -916,37 +1057,11 @@ mysqlnd_net_init(zend_bool persistent TSRMLS_DC)
|
||||||
|
|
||||||
/* {{{ mysqlnd_net_free */
|
/* {{{ mysqlnd_net_free */
|
||||||
PHPAPI void
|
PHPAPI void
|
||||||
mysqlnd_net_free(MYSQLND_NET * const net TSRMLS_DC)
|
mysqlnd_net_free(MYSQLND_NET * const net, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC)
|
||||||
{
|
{
|
||||||
DBG_ENTER("mysqlnd_net_free");
|
DBG_ENTER("mysqlnd_net_free");
|
||||||
|
|
||||||
if (net) {
|
if (net) {
|
||||||
zend_bool pers = net->persistent;
|
net->m.dtor(net, stats, error_info TSRMLS_CC);
|
||||||
|
|
||||||
net->m.free_contents(net TSRMLS_CC);
|
|
||||||
if (net->cmd_buffer.buffer) {
|
|
||||||
DBG_INF("Freeing cmd buffer");
|
|
||||||
mnd_pefree(net->cmd_buffer.buffer, pers);
|
|
||||||
net->cmd_buffer.buffer = NULL;
|
|
||||||
}
|
|
||||||
if (net->stream) {
|
|
||||||
DBG_INF_FMT("Freeing stream. abstract=%p", net->stream->abstract);
|
|
||||||
if (pers) {
|
|
||||||
if (EG(active)) {
|
|
||||||
php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR);
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
otherwise we will crash because the EG(persistent_list) has been freed already,
|
|
||||||
before the modules are shut down
|
|
||||||
*/
|
|
||||||
php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE);
|
|
||||||
}
|
|
||||||
net->stream = NULL;
|
|
||||||
}
|
|
||||||
mnd_pefree(net, pers);
|
|
||||||
}
|
}
|
||||||
DBG_VOID_RETURN;
|
DBG_VOID_RETURN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
#ifndef MYSQLND_NET_H
|
#ifndef MYSQLND_NET_H
|
||||||
#define MYSQLND_NET_H
|
#define MYSQLND_NET_H
|
||||||
|
|
||||||
PHPAPI MYSQLND_NET * mysqlnd_net_init(zend_bool persistent TSRMLS_DC);
|
PHPAPI MYSQLND_NET * mysqlnd_net_init(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC);
|
||||||
PHPAPI void mysqlnd_net_free(MYSQLND_NET * const net TSRMLS_DC);
|
PHPAPI void mysqlnd_net_free(MYSQLND_NET * const net, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC);
|
||||||
|
|
||||||
PHPAPI struct st_mysqlnd_net_methods * mysqlnd_net_get_methods();
|
PHPAPI struct st_mysqlnd_net_methods * mysqlnd_net_get_methods();
|
||||||
|
|
||||||
|
|
|
@ -260,28 +260,39 @@ typedef struct st_mysqlnd_read_buffer {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum_func_status (*func_mysqlnd_net__connect)(MYSQLND_NET * net, const char * const scheme, size_t scheme_len, zend_bool persistent, char **errstr, int * errcode TSRMLS_DC);
|
|
||||||
typedef size_t (*func_mysqlnd_net__send)(MYSQLND * const conn, zend_uchar * const buf, size_t count TSRMLS_DC);
|
|
||||||
typedef enum_func_status (*func_mysqlnd_net__receive)(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC);
|
|
||||||
typedef enum_func_status (*func_mysqlnd_net__set_client_option)(MYSQLND_NET * const net, enum_mysqlnd_option option, const char * const value TSRMLS_DC);
|
typedef enum_func_status (*func_mysqlnd_net__set_client_option)(MYSQLND_NET * const net, enum_mysqlnd_option option, const char * const value TSRMLS_DC);
|
||||||
typedef enum_func_status (*func_mysqlnd_net__network_read)(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC);
|
typedef enum_func_status (*func_mysqlnd_net__decode)(zend_uchar * uncompressed_data, const size_t uncompressed_data_len, const zend_uchar * const compressed_data, const size_t compressed_data_len TSRMLS_DC);
|
||||||
typedef size_t (*func_mysqlnd_net__network_write)(MYSQLND * const conn, const zend_uchar * const buf, size_t count TSRMLS_DC);
|
typedef enum_func_status (*func_mysqlnd_net__encode)(zend_uchar * compress_buffer, size_t * compress_buffer_len, const zend_uchar * const uncompressed_data, const size_t uncompressed_data_len TSRMLS_DC);
|
||||||
typedef enum_func_status (*func_mysqlnd_net__decode)(zend_uchar * uncompressed_data, size_t uncompressed_data_len, const zend_uchar * const compressed_data, size_t compressed_data_len TSRMLS_DC);
|
|
||||||
typedef enum_func_status (*func_mysqlnd_net__encode)(zend_uchar * compress_buffer, size_t * compress_buffer_len, const zend_uchar * const uncompressed_data, size_t uncompressed_data_len TSRMLS_DC);
|
|
||||||
typedef size_t (*func_mysqlnd_net__consume_uneaten_data)(MYSQLND_NET * const net, enum php_mysqlnd_server_command cmd TSRMLS_DC);
|
typedef size_t (*func_mysqlnd_net__consume_uneaten_data)(MYSQLND_NET * const net, enum php_mysqlnd_server_command cmd TSRMLS_DC);
|
||||||
typedef void (*func_mysqlnd_net__free_contents)(MYSQLND_NET * net TSRMLS_DC);
|
typedef void (*func_mysqlnd_net__free_contents)(MYSQLND_NET * net TSRMLS_DC);
|
||||||
typedef enum_func_status (*func_mysqlnd_net__enable_ssl)(MYSQLND_NET * const net TSRMLS_DC);
|
typedef enum_func_status (*func_mysqlnd_net__enable_ssl)(MYSQLND_NET * const net TSRMLS_DC);
|
||||||
typedef enum_func_status (*func_mysqlnd_net__disable_ssl)(MYSQLND_NET * const net TSRMLS_DC);
|
typedef enum_func_status (*func_mysqlnd_net__disable_ssl)(MYSQLND_NET * const net TSRMLS_DC);
|
||||||
|
typedef enum_func_status (*func_mysqlnd_net__network_read_ex)(MYSQLND_NET * const net, zend_uchar * const buffer, const size_t count, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC);
|
||||||
|
typedef size_t (*func_mysqlnd_net__network_write_ex)(MYSQLND_NET * const net, const zend_uchar * const buf, const size_t count, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC);
|
||||||
|
typedef size_t (*func_mysqlnd_net__send_ex)(MYSQLND_NET * const net, zend_uchar * const buffer, const size_t count, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC);
|
||||||
|
typedef enum_func_status (*func_mysqlnd_net__receive_ex)(MYSQLND_NET * const net, zend_uchar * const buffer, const size_t count, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC);
|
||||||
|
typedef enum_func_status (*func_mysqlnd_net__init)(MYSQLND_NET * const net, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC);
|
||||||
|
typedef void (*func_mysqlnd_net__dtor)(MYSQLND_NET * const net, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC);
|
||||||
|
typedef enum_func_status (*func_mysqlnd_net__connect_ex)(MYSQLND_NET * const net, const char * const scheme, const size_t scheme_len, const zend_bool persistent, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC);
|
||||||
|
typedef void (*func_mysqlnd_net__close_stream)(MYSQLND_NET * const net, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC);
|
||||||
|
typedef enum_func_status (*func_mysqlnd_net__open_stream)(MYSQLND_NET * const net, const char * const scheme, const size_t scheme_len, const zend_bool persistent, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC);
|
||||||
|
typedef void (*func_mysqlnd_net__post_connect_set_opt)(MYSQLND_NET * const net, const char * const scheme, const size_t scheme_len, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info TSRMLS_DC);
|
||||||
|
typedef enum_func_status (*func_mysqlnd_net__read_compressed_packet_from_stream_and_fill_read_buffer)(MYSQLND_NET * net, size_t net_payload_size, MYSQLND_STATS * conn_stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC);
|
||||||
|
|
||||||
struct st_mysqlnd_net_methods
|
struct st_mysqlnd_net_methods
|
||||||
{
|
{
|
||||||
func_mysqlnd_net__connect connect;
|
func_mysqlnd_net__init init;
|
||||||
func_mysqlnd_net__send send;
|
func_mysqlnd_net__dtor dtor;
|
||||||
func_mysqlnd_net__receive receive;
|
func_mysqlnd_net__connect_ex connect_ex;
|
||||||
|
func_mysqlnd_net__close_stream close_stream;
|
||||||
|
func_mysqlnd_net__open_stream open_pipe;
|
||||||
|
func_mysqlnd_net__open_stream open_tcp_or_unix;
|
||||||
|
|
||||||
|
void * unused1;
|
||||||
|
void * unused2;
|
||||||
|
func_mysqlnd_net__post_connect_set_opt post_connect_set_opt;
|
||||||
|
|
||||||
func_mysqlnd_net__set_client_option set_client_option;
|
func_mysqlnd_net__set_client_option set_client_option;
|
||||||
func_mysqlnd_net__network_read network_read;
|
|
||||||
func_mysqlnd_net__network_write network_write;
|
|
||||||
func_mysqlnd_net__decode decode;
|
func_mysqlnd_net__decode decode;
|
||||||
func_mysqlnd_net__encode encode;
|
func_mysqlnd_net__encode encode;
|
||||||
func_mysqlnd_net__consume_uneaten_data consume_uneaten_data;
|
func_mysqlnd_net__consume_uneaten_data consume_uneaten_data;
|
||||||
|
@ -289,11 +300,18 @@ struct st_mysqlnd_net_methods
|
||||||
func_mysqlnd_net__enable_ssl enable_ssl;
|
func_mysqlnd_net__enable_ssl enable_ssl;
|
||||||
func_mysqlnd_net__disable_ssl disable_ssl;
|
func_mysqlnd_net__disable_ssl disable_ssl;
|
||||||
|
|
||||||
void * unused1;
|
func_mysqlnd_net__network_read_ex network_read_ex;
|
||||||
void * unused2;
|
func_mysqlnd_net__network_write_ex network_write_ex;
|
||||||
|
func_mysqlnd_net__send_ex send_ex;
|
||||||
|
func_mysqlnd_net__receive_ex receive_ex;
|
||||||
|
|
||||||
|
func_mysqlnd_net__read_compressed_packet_from_stream_and_fill_read_buffer read_compressed_packet_from_stream_and_fill_read_buffer;
|
||||||
|
|
||||||
void * unused3;
|
void * unused3;
|
||||||
void * unused4;
|
void * unused4;
|
||||||
void * unused5;
|
void * unused5;
|
||||||
|
void * unused6;
|
||||||
|
void * unused7;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -711,8 +729,6 @@ struct st_mysqlnd_stmt_methods
|
||||||
struct st_mysqlnd_net
|
struct st_mysqlnd_net
|
||||||
{
|
{
|
||||||
php_stream *stream;
|
php_stream *stream;
|
||||||
struct st_mysqlnd_net_methods m;
|
|
||||||
|
|
||||||
/* sequence for simple checking of correct packets */
|
/* sequence for simple checking of correct packets */
|
||||||
zend_uchar packet_no;
|
zend_uchar packet_no;
|
||||||
zend_bool compressed;
|
zend_bool compressed;
|
||||||
|
@ -729,6 +745,8 @@ struct st_mysqlnd_net
|
||||||
MYSQLND_NET_OPTIONS options;
|
MYSQLND_NET_OPTIONS options;
|
||||||
|
|
||||||
zend_bool persistent;
|
zend_bool persistent;
|
||||||
|
|
||||||
|
struct st_mysqlnd_net_methods m;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#define PACKET_READ_HEADER_AND_BODY(packet, conn, buf, buf_size, packet_type_as_text, packet_type) \
|
#define PACKET_READ_HEADER_AND_BODY(packet, conn, buf, buf_size, packet_type_as_text, packet_type) \
|
||||||
{ \
|
{ \
|
||||||
DBG_INF_FMT("buf=%p size=%u", (buf), (buf_size)); \
|
DBG_INF_FMT("buf=%p size=%u", (buf), (buf_size)); \
|
||||||
if (FAIL == mysqlnd_read_header((conn), &((packet)->header) TSRMLS_CC)) {\
|
if (FAIL == mysqlnd_read_header((conn)->net, &((packet)->header), (conn)->stats, &((conn)->error_info) TSRMLS_CC)) {\
|
||||||
CONN_SET_STATE(conn, CONN_QUIT_SENT); \
|
CONN_SET_STATE(conn, CONN_QUIT_SENT); \
|
||||||
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);\
|
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);\
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mysqlnd_server_gone); \
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mysqlnd_server_gone); \
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
(buf_size), (packet)->header.size, (packet)->header.size - (buf_size)); \
|
(buf_size), (packet)->header.size, (packet)->header.size - (buf_size)); \
|
||||||
DBG_RETURN(FAIL); \
|
DBG_RETURN(FAIL); \
|
||||||
}\
|
}\
|
||||||
if (FAIL == conn->net->m.receive((conn), (buf), (packet)->header.size TSRMLS_CC)) { \
|
if (FAIL == conn->net->m.receive_ex((conn)->net, (buf), (packet)->header.size, (conn)->stats, &((conn)->error_info) TSRMLS_CC)) { \
|
||||||
CONN_SET_STATE(conn, CONN_QUIT_SENT); \
|
CONN_SET_STATE(conn, CONN_QUIT_SENT); \
|
||||||
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);\
|
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);\
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mysqlnd_server_gone); \
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mysqlnd_server_gone); \
|
||||||
|
@ -256,14 +256,14 @@ end:
|
||||||
|
|
||||||
/* {{{ mysqlnd_read_header */
|
/* {{{ mysqlnd_read_header */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
mysqlnd_read_header(MYSQLND * conn, MYSQLND_PACKET_HEADER * header TSRMLS_DC)
|
mysqlnd_read_header(MYSQLND_NET * net, MYSQLND_PACKET_HEADER * header,
|
||||||
|
MYSQLND_STATS * conn_stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_NET * net = conn->net;
|
|
||||||
zend_uchar buffer[MYSQLND_HEADER_SIZE];
|
zend_uchar buffer[MYSQLND_HEADER_SIZE];
|
||||||
|
|
||||||
DBG_ENTER("mysqlnd_read_header_name");
|
DBG_ENTER(mysqlnd_read_header_name);
|
||||||
DBG_INF_FMT("compressed=%u conn_id=%u", net->compressed, conn->thread_id);
|
DBG_INF_FMT("compressed=%u", net->compressed);
|
||||||
if (FAIL == net->m.receive(conn, buffer, MYSQLND_HEADER_SIZE TSRMLS_CC)) {
|
if (FAIL == net->m.receive_ex(net, buffer, MYSQLND_HEADER_SIZE, conn_stats, error_info TSRMLS_CC)) {
|
||||||
DBG_RETURN(FAIL);
|
DBG_RETURN(FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ mysqlnd_read_header(MYSQLND * conn, MYSQLND_PACKET_HEADER * header TSRMLS_DC)
|
||||||
#ifdef MYSQLND_DUMP_HEADER_N_BODY
|
#ifdef MYSQLND_DUMP_HEADER_N_BODY
|
||||||
DBG_INF_FMT("HEADER: prot_packet_no=%u size=%3u", header->packet_no, header->size);
|
DBG_INF_FMT("HEADER: prot_packet_no=%u size=%3u", header->packet_no, header->size);
|
||||||
#endif
|
#endif
|
||||||
MYSQLND_INC_CONN_STATISTIC_W_VALUE2(conn->stats,
|
MYSQLND_INC_CONN_STATISTIC_W_VALUE2(conn_stats,
|
||||||
STAT_PROTOCOL_OVERHEAD_IN, MYSQLND_HEADER_SIZE,
|
STAT_PROTOCOL_OVERHEAD_IN, MYSQLND_HEADER_SIZE,
|
||||||
STAT_PACKETS_RECEIVED, 1);
|
STAT_PACKETS_RECEIVED, 1);
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ mysqlnd_read_header(MYSQLND * conn, MYSQLND_PACKET_HEADER * header TSRMLS_DC)
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_greet_read */
|
/* {{{ php_mysqlnd_greet_read */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_greet_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
php_mysqlnd_greet_read(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
zend_uchar buf[2048];
|
zend_uchar buf[2048];
|
||||||
zend_uchar *p = buf;
|
zend_uchar *p = buf;
|
||||||
|
@ -435,7 +435,7 @@ premature_end:
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_greet_free_mem */
|
/* {{{ php_mysqlnd_greet_free_mem */
|
||||||
static
|
static
|
||||||
void php_mysqlnd_greet_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
void php_mysqlnd_greet_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_GREET *p= (MYSQLND_PACKET_GREET *) _packet;
|
MYSQLND_PACKET_GREET *p= (MYSQLND_PACKET_GREET *) _packet;
|
||||||
if (p->server_version) {
|
if (p->server_version) {
|
||||||
|
@ -461,7 +461,7 @@ void php_mysqlnd_greet_free_mem(void *_packet, zend_bool stack_allocation TSRMLS
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_auth_write */
|
/* {{{ php_mysqlnd_auth_write */
|
||||||
static
|
static
|
||||||
size_t php_mysqlnd_auth_write(void *_packet, MYSQLND * conn TSRMLS_DC)
|
size_t php_mysqlnd_auth_write(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
zend_uchar buffer[AUTH_WRITE_BUFFER_LEN];
|
zend_uchar buffer[AUTH_WRITE_BUFFER_LEN];
|
||||||
zend_uchar *p = buffer + MYSQLND_HEADER_SIZE; /* start after the header */
|
zend_uchar *p = buffer + MYSQLND_HEADER_SIZE; /* start after the header */
|
||||||
|
@ -539,7 +539,11 @@ size_t php_mysqlnd_auth_write(void *_packet, MYSQLND * conn TSRMLS_DC)
|
||||||
}
|
}
|
||||||
DBG_RETURN(p - buffer - MYSQLND_HEADER_SIZE);
|
DBG_RETURN(p - buffer - MYSQLND_HEADER_SIZE);
|
||||||
} else {
|
} else {
|
||||||
DBG_RETURN(conn->net->m.send(conn, buffer, p - buffer - MYSQLND_HEADER_SIZE TSRMLS_CC));
|
size_t sent = conn->net->m.send_ex(conn->net, buffer, p - buffer - MYSQLND_HEADER_SIZE, conn->stats, &conn->error_info TSRMLS_CC);
|
||||||
|
if (!sent) {
|
||||||
|
CONN_SET_STATE(conn, CONN_QUIT_SENT);
|
||||||
|
}
|
||||||
|
DBG_RETURN(sent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -547,7 +551,7 @@ size_t php_mysqlnd_auth_write(void *_packet, MYSQLND * conn TSRMLS_DC)
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_auth_free_mem */
|
/* {{{ php_mysqlnd_auth_free_mem */
|
||||||
static
|
static
|
||||||
void php_mysqlnd_auth_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
void php_mysqlnd_auth_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
if (!stack_allocation) {
|
if (!stack_allocation) {
|
||||||
MYSQLND_PACKET_AUTH * p = (MYSQLND_PACKET_AUTH *) _packet;
|
MYSQLND_PACKET_AUTH * p = (MYSQLND_PACKET_AUTH *) _packet;
|
||||||
|
@ -561,7 +565,7 @@ void php_mysqlnd_auth_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_auth_response_read */
|
/* {{{ php_mysqlnd_auth_response_read */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_auth_response_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
php_mysqlnd_auth_response_read(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
zend_uchar local_buf[AUTH_RESP_BUFFER_SIZE];
|
zend_uchar local_buf[AUTH_RESP_BUFFER_SIZE];
|
||||||
size_t buf_len = conn->net->cmd_buffer.buffer? conn->net->cmd_buffer.length: AUTH_RESP_BUFFER_SIZE;
|
size_t buf_len = conn->net->cmd_buffer.buffer? conn->net->cmd_buffer.length: AUTH_RESP_BUFFER_SIZE;
|
||||||
|
@ -653,7 +657,7 @@ premature_end:
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_auth_response_free_mem */
|
/* {{{ php_mysqlnd_auth_response_free_mem */
|
||||||
static void
|
static void
|
||||||
php_mysqlnd_auth_response_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
php_mysqlnd_auth_response_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_AUTH_RESPONSE * p = (MYSQLND_PACKET_AUTH_RESPONSE *) _packet;
|
MYSQLND_PACKET_AUTH_RESPONSE * p = (MYSQLND_PACKET_AUTH_RESPONSE *) _packet;
|
||||||
if (p->message) {
|
if (p->message) {
|
||||||
|
@ -680,8 +684,8 @@ php_mysqlnd_auth_response_free_mem(void *_packet, zend_bool stack_allocation TSR
|
||||||
|
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_change_auth_response_write */
|
/* {{{ php_mysqlnd_change_auth_response_write */
|
||||||
static
|
static size_t
|
||||||
size_t php_mysqlnd_change_auth_response_write(void *_packet, MYSQLND * conn TSRMLS_DC)
|
php_mysqlnd_change_auth_response_write(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_CHANGE_AUTH_RESPONSE *packet= (MYSQLND_PACKET_CHANGE_AUTH_RESPONSE *) _packet;
|
MYSQLND_PACKET_CHANGE_AUTH_RESPONSE *packet= (MYSQLND_PACKET_CHANGE_AUTH_RESPONSE *) _packet;
|
||||||
zend_uchar * buffer = conn->net->cmd_buffer.length >= packet->auth_data_len? conn->net->cmd_buffer.buffer : mnd_emalloc(packet->auth_data_len);
|
zend_uchar * buffer = conn->net->cmd_buffer.length >= packet->auth_data_len? conn->net->cmd_buffer.buffer : mnd_emalloc(packet->auth_data_len);
|
||||||
|
@ -695,19 +699,22 @@ size_t php_mysqlnd_change_auth_response_write(void *_packet, MYSQLND * conn TSRM
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
size_t ret = conn->net->m.send(conn, buffer, p - buffer - MYSQLND_HEADER_SIZE TSRMLS_CC);
|
size_t sent = conn->net->m.send_ex(conn->net, buffer, p - buffer - MYSQLND_HEADER_SIZE, conn->stats, &conn->error_info TSRMLS_CC);
|
||||||
if (buffer != conn->net->cmd_buffer.buffer) {
|
if (buffer != conn->net->cmd_buffer.buffer) {
|
||||||
mnd_efree(buffer);
|
mnd_efree(buffer);
|
||||||
}
|
}
|
||||||
DBG_RETURN(ret);
|
if (!sent) {
|
||||||
|
CONN_SET_STATE(conn, CONN_QUIT_SENT);
|
||||||
|
}
|
||||||
|
DBG_RETURN(sent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_change_auth_response_free_mem */
|
/* {{{ php_mysqlnd_change_auth_response_free_mem */
|
||||||
static
|
static void
|
||||||
void php_mysqlnd_change_auth_response_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
php_mysqlnd_change_auth_response_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
if (!stack_allocation) {
|
if (!stack_allocation) {
|
||||||
MYSQLND_PACKET_CHANGE_AUTH_RESPONSE * p = (MYSQLND_PACKET_CHANGE_AUTH_RESPONSE *) _packet;
|
MYSQLND_PACKET_CHANGE_AUTH_RESPONSE * p = (MYSQLND_PACKET_CHANGE_AUTH_RESPONSE *) _packet;
|
||||||
|
@ -721,7 +728,7 @@ void php_mysqlnd_change_auth_response_free_mem(void *_packet, zend_bool stack_al
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_ok_read */
|
/* {{{ php_mysqlnd_ok_read */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_ok_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
php_mysqlnd_ok_read(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
zend_uchar local_buf[OK_BUFFER_SIZE];
|
zend_uchar local_buf[OK_BUFFER_SIZE];
|
||||||
size_t buf_len = conn->net->cmd_buffer.buffer? conn->net->cmd_buffer.length : OK_BUFFER_SIZE;
|
size_t buf_len = conn->net->cmd_buffer.buffer? conn->net->cmd_buffer.length : OK_BUFFER_SIZE;
|
||||||
|
@ -790,7 +797,7 @@ premature_end:
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_ok_free_mem */
|
/* {{{ php_mysqlnd_ok_free_mem */
|
||||||
static void
|
static void
|
||||||
php_mysqlnd_ok_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
php_mysqlnd_ok_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_OK *p= (MYSQLND_PACKET_OK *) _packet;
|
MYSQLND_PACKET_OK *p= (MYSQLND_PACKET_OK *) _packet;
|
||||||
if (p->message) {
|
if (p->message) {
|
||||||
|
@ -806,7 +813,7 @@ php_mysqlnd_ok_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_eof_read */
|
/* {{{ php_mysqlnd_eof_read */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_eof_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
php_mysqlnd_eof_read(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
EOF packet is since 4.1 five bytes long,
|
EOF packet is since 4.1 five bytes long,
|
||||||
|
@ -873,7 +880,7 @@ premature_end:
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_eof_free_mem */
|
/* {{{ php_mysqlnd_eof_free_mem */
|
||||||
static
|
static
|
||||||
void php_mysqlnd_eof_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
void php_mysqlnd_eof_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
if (!stack_allocation) {
|
if (!stack_allocation) {
|
||||||
mnd_pefree(_packet, ((MYSQLND_PACKET_EOF *)_packet)->header.persistent);
|
mnd_pefree(_packet, ((MYSQLND_PACKET_EOF *)_packet)->header.persistent);
|
||||||
|
@ -883,13 +890,13 @@ void php_mysqlnd_eof_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_D
|
||||||
|
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_cmd_write */
|
/* {{{ php_mysqlnd_cmd_write */
|
||||||
size_t php_mysqlnd_cmd_write(void *_packet, MYSQLND *conn TSRMLS_DC)
|
size_t php_mysqlnd_cmd_write(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
/* Let's have some space, which we can use, if not enough, we will allocate new buffer */
|
/* Let's have some space, which we can use, if not enough, we will allocate new buffer */
|
||||||
MYSQLND_PACKET_COMMAND *packet= (MYSQLND_PACKET_COMMAND *) _packet;
|
MYSQLND_PACKET_COMMAND * packet= (MYSQLND_PACKET_COMMAND *) _packet;
|
||||||
MYSQLND_NET *net = conn->net;
|
MYSQLND_NET * net = conn->net;
|
||||||
unsigned int error_reporting = EG(error_reporting);
|
unsigned int error_reporting = EG(error_reporting);
|
||||||
size_t written = 0;
|
size_t sent = 0;
|
||||||
|
|
||||||
DBG_ENTER("php_mysqlnd_cmd_write");
|
DBG_ENTER("php_mysqlnd_cmd_write");
|
||||||
/*
|
/*
|
||||||
|
@ -913,9 +920,9 @@ size_t php_mysqlnd_cmd_write(void *_packet, MYSQLND *conn TSRMLS_DC)
|
||||||
zend_uchar buffer[MYSQLND_HEADER_SIZE + 1];
|
zend_uchar buffer[MYSQLND_HEADER_SIZE + 1];
|
||||||
|
|
||||||
int1store(buffer + MYSQLND_HEADER_SIZE, packet->command);
|
int1store(buffer + MYSQLND_HEADER_SIZE, packet->command);
|
||||||
written = conn->net->m.send(conn, buffer, 1 TSRMLS_CC);
|
sent = net->m.send_ex(net, buffer, 1, conn->stats, &conn->error_info TSRMLS_CC);
|
||||||
} else {
|
} else {
|
||||||
size_t tmp_len = packet->arg_len + 1 + MYSQLND_HEADER_SIZE, ret;
|
size_t tmp_len = packet->arg_len + 1 + MYSQLND_HEADER_SIZE;
|
||||||
zend_uchar *tmp, *p;
|
zend_uchar *tmp, *p;
|
||||||
tmp = (tmp_len > net->cmd_buffer.length)? mnd_emalloc(tmp_len):net->cmd_buffer.buffer;
|
tmp = (tmp_len > net->cmd_buffer.length)? mnd_emalloc(tmp_len):net->cmd_buffer.buffer;
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
|
@ -928,26 +935,28 @@ size_t php_mysqlnd_cmd_write(void *_packet, MYSQLND *conn TSRMLS_DC)
|
||||||
|
|
||||||
memcpy(p, packet->argument, packet->arg_len);
|
memcpy(p, packet->argument, packet->arg_len);
|
||||||
|
|
||||||
ret = conn->net->m.send(conn, tmp, tmp_len - MYSQLND_HEADER_SIZE TSRMLS_CC);
|
sent = net->m.send_ex(net, tmp, tmp_len - MYSQLND_HEADER_SIZE, conn->stats, &conn->error_info TSRMLS_CC);
|
||||||
if (tmp != net->cmd_buffer.buffer) {
|
if (tmp != net->cmd_buffer.buffer) {
|
||||||
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_CMD_BUFFER_TOO_SMALL);
|
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_CMD_BUFFER_TOO_SMALL);
|
||||||
mnd_efree(tmp);
|
mnd_efree(tmp);
|
||||||
}
|
}
|
||||||
written = ret;
|
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
if (error_reporting) {
|
if (error_reporting) {
|
||||||
/* restore error reporting */
|
/* restore error reporting */
|
||||||
EG(error_reporting) = error_reporting;
|
EG(error_reporting) = error_reporting;
|
||||||
}
|
}
|
||||||
DBG_RETURN(written);
|
if (!sent) {
|
||||||
|
CONN_SET_STATE(conn, CONN_QUIT_SENT);
|
||||||
|
}
|
||||||
|
DBG_RETURN(sent);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_cmd_free_mem */
|
/* {{{ php_mysqlnd_cmd_free_mem */
|
||||||
static
|
static
|
||||||
void php_mysqlnd_cmd_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
void php_mysqlnd_cmd_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
if (!stack_allocation) {
|
if (!stack_allocation) {
|
||||||
MYSQLND_PACKET_COMMAND * p = (MYSQLND_PACKET_COMMAND *) _packet;
|
MYSQLND_PACKET_COMMAND * p = (MYSQLND_PACKET_COMMAND *) _packet;
|
||||||
|
@ -959,7 +968,7 @@ void php_mysqlnd_cmd_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_D
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_rset_header_read */
|
/* {{{ php_mysqlnd_rset_header_read */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_rset_header_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
php_mysqlnd_rset_header_read(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
enum_func_status ret = PASS;
|
enum_func_status ret = PASS;
|
||||||
size_t buf_len = conn->net->cmd_buffer.length;
|
size_t buf_len = conn->net->cmd_buffer.length;
|
||||||
|
@ -1063,7 +1072,7 @@ premature_end:
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_rset_header_free_mem */
|
/* {{{ php_mysqlnd_rset_header_free_mem */
|
||||||
static
|
static
|
||||||
void php_mysqlnd_rset_header_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
void php_mysqlnd_rset_header_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_RSET_HEADER *p= (MYSQLND_PACKET_RSET_HEADER *) _packet;
|
MYSQLND_PACKET_RSET_HEADER *p= (MYSQLND_PACKET_RSET_HEADER *) _packet;
|
||||||
DBG_ENTER("php_mysqlnd_rset_header_free_mem");
|
DBG_ENTER("php_mysqlnd_rset_header_free_mem");
|
||||||
|
@ -1097,7 +1106,7 @@ static size_t rset_field_offsets[] =
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_rset_field_read */
|
/* {{{ php_mysqlnd_rset_field_read */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_rset_field_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
php_mysqlnd_rset_field_read(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
/* Should be enough for the metadata of a single row */
|
/* Should be enough for the metadata of a single row */
|
||||||
MYSQLND_PACKET_RES_FIELD *packet= (MYSQLND_PACKET_RES_FIELD *) _packet;
|
MYSQLND_PACKET_RES_FIELD *packet= (MYSQLND_PACKET_RES_FIELD *) _packet;
|
||||||
|
@ -1290,7 +1299,7 @@ premature_end:
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_rset_field_free_mem */
|
/* {{{ php_mysqlnd_rset_field_free_mem */
|
||||||
static
|
static
|
||||||
void php_mysqlnd_rset_field_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
void php_mysqlnd_rset_field_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_RES_FIELD *p= (MYSQLND_PACKET_RES_FIELD *) _packet;
|
MYSQLND_PACKET_RES_FIELD *p= (MYSQLND_PACKET_RES_FIELD *) _packet;
|
||||||
/* p->metadata was passed to us as temporal buffer */
|
/* p->metadata was passed to us as temporal buffer */
|
||||||
|
@ -1304,13 +1313,13 @@ void php_mysqlnd_rset_field_free_mem(void *_packet, zend_bool stack_allocation T
|
||||||
/* {{{ php_mysqlnd_read_row_ex */
|
/* {{{ php_mysqlnd_read_row_ex */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_read_row_ex(MYSQLND * conn, MYSQLND_MEMORY_POOL * result_set_memory_pool,
|
php_mysqlnd_read_row_ex(MYSQLND * conn, MYSQLND_MEMORY_POOL * result_set_memory_pool,
|
||||||
MYSQLND_MEMORY_POOL_CHUNK **buffer,
|
MYSQLND_MEMORY_POOL_CHUNK ** buffer,
|
||||||
size_t *data_size, zend_bool persistent_alloc,
|
size_t * data_size, zend_bool persistent_alloc,
|
||||||
unsigned int prealloc_more_bytes TSRMLS_DC)
|
unsigned int prealloc_more_bytes TSRMLS_DC)
|
||||||
{
|
{
|
||||||
enum_func_status ret = PASS;
|
enum_func_status ret = PASS;
|
||||||
MYSQLND_PACKET_HEADER header;
|
MYSQLND_PACKET_HEADER header;
|
||||||
zend_uchar *p = NULL;
|
zend_uchar * p = NULL;
|
||||||
zend_bool first_iteration = TRUE;
|
zend_bool first_iteration = TRUE;
|
||||||
|
|
||||||
DBG_ENTER("php_mysqlnd_read_row_ex");
|
DBG_ENTER("php_mysqlnd_read_row_ex");
|
||||||
|
@ -1325,7 +1334,7 @@ php_mysqlnd_read_row_ex(MYSQLND * conn, MYSQLND_MEMORY_POOL * result_set_memory_
|
||||||
|
|
||||||
*data_size = prealloc_more_bytes;
|
*data_size = prealloc_more_bytes;
|
||||||
while (1) {
|
while (1) {
|
||||||
if (FAIL == mysqlnd_read_header(conn , &header TSRMLS_CC)) {
|
if (FAIL == mysqlnd_read_header(conn->net, &header, conn->stats, &conn->error_info TSRMLS_CC)) {
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1365,7 +1374,7 @@ php_mysqlnd_read_row_ex(MYSQLND * conn, MYSQLND_MEMORY_POOL * result_set_memory_
|
||||||
p = (*buffer)->ptr + (*data_size - header.size);
|
p = (*buffer)->ptr + (*data_size - header.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PASS != (ret = conn->net->m.receive(conn, p, header.size TSRMLS_CC))) {
|
if (PASS != (ret = conn->net->m.receive_ex(conn->net, p, header.size, conn->stats, &conn->error_info TSRMLS_CC))) {
|
||||||
DBG_ERR("Empty row packet body");
|
DBG_ERR("Empty row packet body");
|
||||||
php_error(E_WARNING, "Empty row packet body");
|
php_error(E_WARNING, "Empty row packet body");
|
||||||
break;
|
break;
|
||||||
|
@ -1393,8 +1402,8 @@ php_mysqlnd_rowp_read_binary_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zv
|
||||||
MYSQLND_STATS * stats TSRMLS_DC)
|
MYSQLND_STATS * stats TSRMLS_DC)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
zend_uchar *p = row_buffer->ptr;
|
zend_uchar * p = row_buffer->ptr;
|
||||||
zend_uchar *null_ptr, bit;
|
zend_uchar * null_ptr, bit;
|
||||||
zval **current_field, **end_field, **start_field;
|
zval **current_field, **end_field, **start_field;
|
||||||
|
|
||||||
DBG_ENTER("php_mysqlnd_rowp_read_binary_protocol");
|
DBG_ENTER("php_mysqlnd_rowp_read_binary_protocol");
|
||||||
|
@ -1494,9 +1503,9 @@ php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
zend_bool last_field_was_string = FALSE;
|
zend_bool last_field_was_string = FALSE;
|
||||||
zval **current_field, **end_field, **start_field;
|
zval **current_field, **end_field, **start_field;
|
||||||
zend_uchar *p = row_buffer->ptr;
|
zend_uchar * p = row_buffer->ptr;
|
||||||
size_t data_size = row_buffer->app;
|
size_t data_size = row_buffer->app;
|
||||||
zend_uchar *bit_area = (zend_uchar*) row_buffer->ptr + data_size + 1; /* we allocate from here */
|
zend_uchar * bit_area = (zend_uchar*) row_buffer->ptr + data_size + 1; /* we allocate from here */
|
||||||
|
|
||||||
DBG_ENTER("php_mysqlnd_rowp_read_text_protocol");
|
DBG_ENTER("php_mysqlnd_rowp_read_text_protocol");
|
||||||
|
|
||||||
|
@ -1719,9 +1728,9 @@ php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval
|
||||||
if PS => packet->fields is passed from outside
|
if PS => packet->fields is passed from outside
|
||||||
*/
|
*/
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_rowp_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
php_mysqlnd_rowp_read(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_NET *net = conn->net;
|
MYSQLND_NET * net = conn->net;
|
||||||
zend_uchar *p;
|
zend_uchar *p;
|
||||||
enum_func_status ret = PASS;
|
enum_func_status ret = PASS;
|
||||||
size_t old_chunk_size = net->stream->chunk_size;
|
size_t old_chunk_size = net->stream->chunk_size;
|
||||||
|
@ -1814,7 +1823,7 @@ end:
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_rowp_free_mem */
|
/* {{{ php_mysqlnd_rowp_free_mem */
|
||||||
static void
|
static void
|
||||||
php_mysqlnd_rowp_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
php_mysqlnd_rowp_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_ROW *p;
|
MYSQLND_PACKET_ROW *p;
|
||||||
|
|
||||||
|
@ -1842,7 +1851,7 @@ php_mysqlnd_rowp_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_stats_read */
|
/* {{{ php_mysqlnd_stats_read */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_stats_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
php_mysqlnd_stats_read(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_STATS *packet= (MYSQLND_PACKET_STATS *) _packet;
|
MYSQLND_PACKET_STATS *packet= (MYSQLND_PACKET_STATS *) _packet;
|
||||||
size_t buf_len = conn->net->cmd_buffer.length;
|
size_t buf_len = conn->net->cmd_buffer.length;
|
||||||
|
@ -1864,7 +1873,7 @@ php_mysqlnd_stats_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_stats_free_mem */
|
/* {{{ php_mysqlnd_stats_free_mem */
|
||||||
static
|
static
|
||||||
void php_mysqlnd_stats_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
void php_mysqlnd_stats_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_STATS *p= (MYSQLND_PACKET_STATS *) _packet;
|
MYSQLND_PACKET_STATS *p= (MYSQLND_PACKET_STATS *) _packet;
|
||||||
if (p->message) {
|
if (p->message) {
|
||||||
|
@ -1884,7 +1893,7 @@ void php_mysqlnd_stats_free_mem(void *_packet, zend_bool stack_allocation TSRMLS
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_prepare_read */
|
/* {{{ php_mysqlnd_prepare_read */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_prepare_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
php_mysqlnd_prepare_read(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
/* In case of an error, we should have place to put it */
|
/* In case of an error, we should have place to put it */
|
||||||
size_t buf_len = conn->net->cmd_buffer.length;
|
size_t buf_len = conn->net->cmd_buffer.length;
|
||||||
|
@ -1960,7 +1969,7 @@ premature_end:
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_prepare_free_mem */
|
/* {{{ php_mysqlnd_prepare_free_mem */
|
||||||
static void
|
static void
|
||||||
php_mysqlnd_prepare_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
php_mysqlnd_prepare_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_PREPARE_RESPONSE *p= (MYSQLND_PACKET_PREPARE_RESPONSE *) _packet;
|
MYSQLND_PACKET_PREPARE_RESPONSE *p= (MYSQLND_PACKET_PREPARE_RESPONSE *) _packet;
|
||||||
if (!stack_allocation) {
|
if (!stack_allocation) {
|
||||||
|
@ -1972,7 +1981,7 @@ php_mysqlnd_prepare_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_chg_user_read */
|
/* {{{ php_mysqlnd_chg_user_read */
|
||||||
static enum_func_status
|
static enum_func_status
|
||||||
php_mysqlnd_chg_user_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
php_mysqlnd_chg_user_read(void * _packet, MYSQLND * conn TSRMLS_DC)
|
||||||
{
|
{
|
||||||
/* There could be an error message */
|
/* There could be an error message */
|
||||||
size_t buf_len = conn->net->cmd_buffer.length;
|
size_t buf_len = conn->net->cmd_buffer.length;
|
||||||
|
@ -2035,7 +2044,7 @@ premature_end:
|
||||||
|
|
||||||
/* {{{ php_mysqlnd_chg_user_free_mem */
|
/* {{{ php_mysqlnd_chg_user_free_mem */
|
||||||
static void
|
static void
|
||||||
php_mysqlnd_chg_user_free_mem(void *_packet, zend_bool stack_allocation TSRMLS_DC)
|
php_mysqlnd_chg_user_free_mem(void * _packet, zend_bool stack_allocation TSRMLS_DC)
|
||||||
{
|
{
|
||||||
MYSQLND_PACKET_CHG_USER_RESPONSE * p = (MYSQLND_PACKET_CHG_USER_RESPONSE *) _packet;
|
MYSQLND_PACKET_CHG_USER_RESPONSE * p = (MYSQLND_PACKET_CHG_USER_RESPONSE *) _packet;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue