Move this function to MYSQLND_NET as it works on the

php stream
This commit is contained in:
Andrey Hristov 2009-12-21 16:52:10 +00:00
parent 3e3d0e0d88
commit a3e5d1852a
5 changed files with 53 additions and 54 deletions

View File

@ -591,6 +591,55 @@ MYSQLND_METHOD(mysqlnd_net, set_client_option)(MYSQLND_NET * const net, enum mys
}
/* }}} */
/* {{{ mysqlnd_net::consume_uneaten_data */
size_t
MYSQLND_METHOD(mysqlnd_net, consume_uneaten_data)(MYSQLND_NET * const net, enum php_mysqlnd_server_command cmd TSRMLS_DC)
{
#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
/*
Switch to non-blocking mode and try to consume something from
the line, if possible, then continue. This saves us from looking for
the actuall place where out-of-order packets have been sent.
If someone is completely sure that everything is fine, he can switch it
off.
*/
char tmp_buf[256];
size_t skipped_bytes = 0;
int opt = PHP_STREAM_OPTION_BLOCKING;
int was_blocked = net->stream->ops->set_option(net->stream, opt, 0, NULL TSRMLS_CC);
DBG_ENTER("mysqlnd_net::consume_uneaten_data");
if (PHP_STREAM_OPTION_RETURN_ERR != was_blocked) {
/* Do a read of 1 byte */
int bytes_consumed;
do {
skipped_bytes += (bytes_consumed = php_stream_read(net->stream, tmp_buf, sizeof(tmp_buf)));
} while (bytes_consumed == sizeof(tmp_buf));
if (was_blocked) {
net->stream->ops->set_option(net->stream, opt, 1, NULL TSRMLS_CC);
}
if (bytes_consumed) {
DBG_ERR_FMT("Skipped %u bytes. Last command %s hasn't consumed all the output from the server",
bytes_consumed, mysqlnd_command_to_text[net->last_command]);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Skipped %u bytes. Last command %s hasn't "
"consumed all the output from the server",
bytes_consumed, mysqlnd_command_to_text[net->last_command]);
}
}
net->last_command = cmd;
DBG_RETURN(skipped_bytes);
#else
return 0;
#endif
}
/* }}} */
/* {{{ mysqlnd_net::set_client_option */
static void
@ -626,6 +675,7 @@ mysqlnd_net_init(zend_bool persistent TSRMLS_DC)
net->m.network_write = MYSQLND_METHOD(mysqlnd_net, network_write);
net->m.decode = MYSQLND_METHOD(mysqlnd_net, decode);
net->m.encode = MYSQLND_METHOD(mysqlnd_net, encode);
net->m.consume_uneaten_data = MYSQLND_METHOD(mysqlnd_net, consume_uneaten_data);
net->m.free_contents = MYSQLND_METHOD(mysqlnd_net, free_contents);
{

View File

@ -1225,7 +1225,7 @@ MYSQLND_METHOD(mysqlnd_stmt, send_long_data)(MYSQLND_STMT * const stmt, unsigned
#if HAVE_USLEEP && !defined(PHP_WIN32)
usleep(120000);
#endif
if ((packet_len = php_mysqlnd_consume_uneaten_data(conn, cmd TSRMLS_CC))) {
if ((packet_len = conn->net->m.consume_uneaten_data(conn->net, cmd TSRMLS_CC))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "There was an error "
"while sending long data. Probably max_allowed_packet_size "
"is smaller than the data. You have to increase it or send "

View File

@ -238,6 +238,7 @@ struct st_mysqlnd_net_methods
size_t (*network_write)(MYSQLND * const conn, const zend_uchar * const buf, size_t count TSRMLS_DC);
enum_func_status (*decode)(zend_uchar * uncompressed_data, size_t uncompressed_data_len, const zend_uchar * const compressed_data, size_t compressed_data_len TSRMLS_DC);
enum_func_status (*encode)(zend_uchar * compress_buffer, size_t compress_buffer_len, const zend_uchar * const uncompressed_data, size_t uncompressed_data_len TSRMLS_DC);
size_t (*consume_uneaten_data)(MYSQLND_NET * const net, enum php_mysqlnd_server_command cmd TSRMLS_DC);
void (*free_contents)(MYSQLND_NET * net TSRMLS_DC);
};

View File

@ -204,54 +204,6 @@ zend_uchar *php_mysqlnd_net_store_length(zend_uchar *packet, uint64_t length)
/* }}} */
/* {{{ php_mysqlnd_consume_uneaten_data */
#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
size_t php_mysqlnd_consume_uneaten_data(MYSQLND * const conn, enum php_mysqlnd_server_command cmd TSRMLS_DC)
{
/*
Switch to non-blocking mode and try to consume something from
the line, if possible, then continue. This saves us from looking for
the actuall place where out-of-order packets have been sent.
If someone is completely sure that everything is fine, he can switch it
off.
*/
char tmp_buf[256];
MYSQLND_NET *net = conn->net;
size_t skipped_bytes = 0;
int opt = PHP_STREAM_OPTION_BLOCKING;
int was_blocked = net->stream->ops->set_option(net->stream, opt, 0, NULL TSRMLS_CC);
DBG_ENTER("php_mysqlnd_consume_uneaten_data");
if (PHP_STREAM_OPTION_RETURN_ERR != was_blocked) {
/* Do a read of 1 byte */
int bytes_consumed;
do {
skipped_bytes += (bytes_consumed = php_stream_read(net->stream, tmp_buf, sizeof(tmp_buf)));
} while (bytes_consumed == sizeof(tmp_buf));
if (was_blocked) {
net->stream->ops->set_option(net->stream, opt, 1, NULL TSRMLS_CC);
}
if (bytes_consumed) {
DBG_ERR_FMT("Skipped %u bytes. Last command %s hasn't consumed all the output from the server",
bytes_consumed, mysqlnd_command_to_text[net->last_command]);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Skipped %u bytes. Last command %s hasn't "
"consumed all the output from the server",
bytes_consumed, mysqlnd_command_to_text[net->last_command]);
}
}
net->last_command = cmd;
DBG_RETURN(skipped_bytes);
}
#endif
/* }}} */
/* {{{ php_mysqlnd_read_error_from_line */
static enum_func_status
php_mysqlnd_read_error_from_line(zend_uchar *buf, size_t buf_len,
@ -723,7 +675,7 @@ size_t php_mysqlnd_cmd_write(void *_packet, MYSQLND *conn TSRMLS_DC)
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_PACKETS_SENT_CMD);
#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
php_mysqlnd_consume_uneaten_data(conn, packet->command TSRMLS_CC);
net->m.consume_uneaten_data(net, packet->command TSRMLS_CC);
#endif
if (!packet->argument || !packet->arg_len) {

View File

@ -264,10 +264,6 @@ typedef struct st_php_mysql_packet_chg_user_resp {
size_t mysqlnd_stream_write_w_header(MYSQLND * const conn, char * const buf, size_t count TSRMLS_DC);
#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
size_t php_mysqlnd_consume_uneaten_data(MYSQLND * const conn, enum php_mysqlnd_server_command cmd TSRMLS_DC);
#endif
void php_mysqlnd_scramble(zend_uchar * const buffer, const zend_uchar * const scramble, const zend_uchar * const pass);
unsigned long php_mysqlnd_net_field_length(zend_uchar **packet);