diff options
Diffstat (limited to 'ext/mysqlnd/mysqlnd_vio.c')
| -rw-r--r-- | ext/mysqlnd/mysqlnd_vio.c | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/ext/mysqlnd/mysqlnd_vio.c b/ext/mysqlnd/mysqlnd_vio.c index 50db782be6..a5685e6707 100644 --- a/ext/mysqlnd/mysqlnd_vio.c +++ b/ext/mysqlnd/mysqlnd_vio.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 2006-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -79,14 +79,15 @@ MYSQLND_METHOD(mysqlnd_vio, network_read)(MYSQLND_VIO * const vio, zend_uchar * { enum_func_status return_value = PASS; php_stream * net_stream = vio->data->m.get_stream(vio); - size_t to_read = count, ret; + size_t to_read = count; zend_uchar * p = buffer; DBG_ENTER("mysqlnd_vio::network_read"); DBG_INF_FMT("count="MYSQLND_SZ_T_SPEC, count); while (to_read) { - if (!(ret = php_stream_read(net_stream, (char *) p, to_read))) { + ssize_t ret = php_stream_read(net_stream, (char *) p, to_read); + if (ret <= 0) { DBG_ERR_FMT("Error while reading header from socket"); return_value = FAIL; break; @@ -101,11 +102,11 @@ MYSQLND_METHOD(mysqlnd_vio, network_read)(MYSQLND_VIO * const vio, zend_uchar * /* {{{ mysqlnd_vio::network_write */ -static size_t +static ssize_t MYSQLND_METHOD(mysqlnd_vio, network_write)(MYSQLND_VIO * const vio, const zend_uchar * const buffer, const size_t count, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info) { - size_t ret; + ssize_t ret; DBG_ENTER("mysqlnd_vio::network_write"); DBG_INF_FMT("sending %u bytes", count); ret = php_stream_write(vio->data->m.get_stream(vio), (char *)buffer, count); @@ -451,10 +452,14 @@ MYSQLND_METHOD(mysqlnd_vio, consume_uneaten_data)(MYSQLND_VIO * const net, enum if (PHP_STREAM_OPTION_RETURN_ERR != was_blocked) { /* Do a read of 1 byte */ - int bytes_consumed; + ssize_t bytes_consumed; do { - skipped_bytes += (bytes_consumed = php_stream_read(net_stream, tmp_buf, sizeof(tmp_buf))); + bytes_consumed = php_stream_read(net_stream, tmp_buf, sizeof(tmp_buf)); + if (bytes_consumed <= 0) { + break; + } + skipped_bytes += bytes_consumed; } while (bytes_consumed == sizeof(tmp_buf)); if (was_blocked) { @@ -644,18 +649,17 @@ MYSQLND_METHOD(mysqlnd_vio, close_stream)(MYSQLND_VIO * const net, MYSQLND_STATS if (net && (net_stream = net->data->m.get_stream(net))) { 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); - } + /* We removed the resource from the stream, so pass FREE_RSRC_DTOR now to force + * destruction to occur during shutdown, because it won't happen through the resource. */ + /* TODO: The EG(active) check here is dead -- check IN_SHUTDOWN? */ + if (pers && EG(active)) { + 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); + /* + 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); } net->data->m.set_stream(net, NULL); } @@ -789,13 +793,3 @@ mysqlnd_vio_free(MYSQLND_VIO * const vio, MYSQLND_STATS * stats, MYSQLND_ERROR_I DBG_VOID_RETURN; } /* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ |
