mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Report errors from stream read and write operations
The php_stream_read() and php_stream_write() functions now return an ssize_t value, with negative results indicating failure. Functions like fread() and fwrite() will return false in that case. As a special case, EWOULDBLOCK and EAGAIN on non-blocking streams should not be regarded as error conditions, and be reported as successful zero-length reads/writes instead. The handling of EINTR remains unclear and is internally inconsistent (e.g. some code-paths will automatically retry on EINTR, while some won't). I'm landing this now to make sure the stream wrapper ops API changes make it into 7.4 -- however, if the user-facing changes turn out to be problematic we have the option of clamping negative returns to zero in php_stream_read() and php_stream_write() to restore the old behavior in a relatively non-intrusive manner.
This commit is contained in:
parent
c817b8020c
commit
d59aac58b3
73 changed files with 648 additions and 377 deletions
|
@ -68,11 +68,12 @@ MYSQLND_METHOD(mysqlnd_pfc, send)(MYSQLND_PFC * const pfc, MYSQLND_VIO * const v
|
|||
{
|
||||
zend_uchar safe_buf[((MYSQLND_HEADER_SIZE) + (sizeof(zend_uchar)) - 1) / (sizeof(zend_uchar))];
|
||||
zend_uchar * safe_storage = safe_buf;
|
||||
size_t bytes_sent, packets_sent = 1;
|
||||
size_t packets_sent = 1;
|
||||
size_t left = count;
|
||||
zend_uchar * p = (zend_uchar *) buffer;
|
||||
zend_uchar * compress_buf = NULL;
|
||||
size_t to_be_sent;
|
||||
ssize_t bytes_sent;
|
||||
|
||||
DBG_ENTER("mysqlnd_pfc::send");
|
||||
DBG_INF_FMT("count=" MYSQLND_SZ_T_SPEC " compression=%u", count, pfc->data->compressed);
|
||||
|
@ -161,7 +162,7 @@ MYSQLND_METHOD(mysqlnd_pfc, send)(MYSQLND_PFC * const pfc, MYSQLND_VIO * const v
|
|||
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.
|
||||
*/
|
||||
} while (bytes_sent && (left > 0 || to_be_sent == MYSQLND_MAX_PACKET_SIZE));
|
||||
} while (bytes_sent > 0 && (left > 0 || to_be_sent == MYSQLND_MAX_PACKET_SIZE));
|
||||
|
||||
DBG_INF_FMT("packet_size="MYSQLND_SZ_T_SPEC" packet_no=%u", left, pfc->data->packet_no);
|
||||
|
||||
|
@ -175,7 +176,7 @@ MYSQLND_METHOD(mysqlnd_pfc, send)(MYSQLND_PFC * const pfc, MYSQLND_VIO * const v
|
|||
}
|
||||
|
||||
/* Even for zero size payload we have to send a packet */
|
||||
if (!bytes_sent) {
|
||||
if (bytes_sent <= 0) {
|
||||
DBG_ERR_FMT("Can't %u send bytes", count);
|
||||
SET_CLIENT_ERROR(error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue