]> granicus.if.org Git - php/commitdiff
Move this function to MYSQLND_NET as it works on the
authorAndrey Hristov <andrey@php.net>
Mon, 21 Dec 2009 16:52:10 +0000 (16:52 +0000)
committerAndrey Hristov <andrey@php.net>
Mon, 21 Dec 2009 16:52:10 +0000 (16:52 +0000)
php stream

ext/mysqlnd/mysqlnd_net.c
ext/mysqlnd/mysqlnd_ps.c
ext/mysqlnd/mysqlnd_structs.h
ext/mysqlnd/mysqlnd_wireprotocol.c
ext/mysqlnd/mysqlnd_wireprotocol.h

index f7c14a54b63e4fce3d9592f309bf7d5d8fb57bd6..820855eaf72881449c94a50d8f59aaa365ee9825 100644 (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);
 
        {
index 41e192b71b0bda77f37169d7897d1f487df5690d..d57320d6c4fc2925ee8f377b1b8ffdf6fa727f88 100644 (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 "
index b8ce0bd89d40e1e45dbe3d8a9f5fd85ff13f88b1..96f46324ea0716125702667176cf485e85cc4bdf 100644 (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);
 };
 
index fa2c73027f28586cd4aabaa61f01385b4bf0d49d..af597d35172185c8a5940f4f88dda5a223ab1eaa 100644 (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) {
index 78adc237252269cbdedfed9b8804b840d6b37f28..b3f0ab63d87094619e81ba8c7d34d03c99c8d326 100644 (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);