andrey                                   Mon, 21 Dec 2009 16:52:10 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=292423

Log:
Move this function to MYSQLND_NET as it works on the
php stream

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_structs.h
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.h
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.h

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c	2009-12-21 16:36:23 UTC (rev 292422)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c	2009-12-21 16:52:10 UTC (rev 292423)
@@ -591,7 +591,56 @@
 }
 /* }}} */

+/* {{{ 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
 MYSQLND_METHOD(mysqlnd_net, free_contents)(MYSQLND_NET * net TSRMLS_DC)
@@ -626,6 +675,7 @@
 	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);

 	{

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c	2009-12-21 16:36:23 UTC (rev 292422)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c	2009-12-21 16:52:10 UTC (rev 292423)
@@ -1225,7 +1225,7 @@
 #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 "

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_structs.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_structs.h	2009-12-21 16:36:23 UTC (rev 292422)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_structs.h	2009-12-21 16:52:10 UTC (rev 292423)
@@ -238,6 +238,7 @@
 	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);
 };


Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c	2009-12-21 16:36:23 UTC (rev 292422)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c	2009-12-21 16:52:10 UTC (rev 292423)
@@ -204,54 +204,6 @@
 /* }}} */


-/* {{{ 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 @@
 	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) {

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.h	2009-12-21 16:36:23 UTC (rev 292422)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.h	2009-12-21 16:52:10 UTC (rev 292423)
@@ -264,10 +264,6 @@

 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);

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c	2009-12-21 16:36:23 UTC (rev 292422)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c	2009-12-21 16:52:10 UTC (rev 292423)
@@ -591,7 +591,56 @@
 }
 /* }}} */

+/* {{{ 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
 MYSQLND_METHOD(mysqlnd_net, free_contents)(MYSQLND_NET * net TSRMLS_DC)
@@ -626,6 +675,7 @@
 	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);

 	{

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c	2009-12-21 16:36:23 UTC (rev 292422)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c	2009-12-21 16:52:10 UTC (rev 292423)
@@ -1225,7 +1225,7 @@
 #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 "

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h	2009-12-21 16:36:23 UTC (rev 292422)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h	2009-12-21 16:52:10 UTC (rev 292423)
@@ -238,6 +238,7 @@
 	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);
 };


Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c	2009-12-21 16:36:23 UTC (rev 292422)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c	2009-12-21 16:52:10 UTC (rev 292423)
@@ -204,54 +204,6 @@
 /* }}} */


-/* {{{ 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 @@
 	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) {

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.h
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.h	2009-12-21 16:36:23 UTC (rev 292422)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.h	2009-12-21 16:52:10 UTC (rev 292423)
@@ -264,10 +264,6 @@

 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);
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to