Skip to content

Commit 150ebfd

Browse files
committed
Suppress bogus [-Wlogical-op] warning from GCC
See GCC bug 69602: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602 which emits the warning for (errno == EWOULDBLOCK || errno == EAGAIN) which is the correct way of handling errors as the value of EWOULDBLOCK and EAGAIN is implementation defined. Therefore introduce a new macro function PHP_IS_TRANSIENT_ERROR() which handles the case when EWOULDBLOCK and EAGAIN are identical. Thanks to @twose for the idea.
1 parent f211f15 commit 150ebfd

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

ext/sockets/sockets.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,11 +1045,7 @@ PHP_FUNCTION(socket_read)
10451045
if (retval == -1) {
10461046
/* if the socket is in non-blocking mode and there's no data to read,
10471047
don't output any error, as this is a normal situation, and not an error */
1048-
if (errno == EAGAIN
1049-
#ifdef EWOULDBLOCK
1050-
|| errno == EWOULDBLOCK
1051-
#endif
1052-
) {
1048+
if (PHP_IS_TRANSIENT_ERROR(errno)) {
10531049
php_sock->error = errno;
10541050
SOCKETS_G(last_error) = errno;
10551051
} else {

main/php_network.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
# define EWOULDBLOCK EAGAIN
5050
#endif
5151

52+
/* This is a work around for GCC bug 69602: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602 */
53+
#if EAGAIN != EWOULDBLOCK
54+
# define PHP_IS_TRANSIENT_ERROR(err) (err == EAGAIN || err == EWOULDBLOCK)
55+
#else
56+
# define PHP_IS_TRANSIENT_ERROR(err) (err == EAGAIN)
57+
#endif
58+
5259
#ifdef PHP_WIN32
5360
#define php_socket_errno() WSAGetLastError()
5461
#else

main/streams/plain_wrapper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
351351
ssize_t bytes_written = write(data->fd, buf, count);
352352
#endif
353353
if (bytes_written < 0) {
354-
if (errno == EWOULDBLOCK || errno == EAGAIN) {
354+
if (PHP_IS_TRANSIENT_ERROR(errno)) {
355355
return 0;
356356
}
357357
if (errno == EINTR) {
@@ -420,7 +420,7 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
420420
}
421421

422422
if (ret < 0) {
423-
if (errno == EWOULDBLOCK || errno == EAGAIN) {
423+
if (PHP_IS_TRANSIENT_ERROR(errno)) {
424424
/* Not an error. */
425425
ret = 0;
426426
} else if (errno == EINTR) {

main/streams/xp_socket.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ static ssize_t php_sockop_write(php_stream *stream, const char *buf, size_t coun
7575
if (didwrite <= 0) {
7676
char *estr;
7777
int err = php_socket_errno();
78-
if (err == EWOULDBLOCK || err == EAGAIN) {
78+
79+
if (PHP_IS_TRANSIENT_ERROR(err)) {
7980
if (sock->is_blocked) {
8081
int retval;
8182

@@ -166,7 +167,7 @@ static ssize_t php_sockop_read(php_stream *stream, char *buf, size_t count)
166167
err = php_socket_errno();
167168

168169
if (nr_bytes < 0) {
169-
if (err == EAGAIN || err == EWOULDBLOCK) {
170+
if (PHP_IS_TRANSIENT_ERROR(err)) {
170171
nr_bytes = 0;
171172
} else {
172173
stream->eof = 1;

sapi/fpm/fpm/fpm_stdio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <errno.h>
1111

1212
#include "php_syslog.h"
13+
#include "php_network.h"
1314

1415
#include "fpm.h"
1516
#include "fpm_children.h"
@@ -166,7 +167,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
166167
stdio_read:
167168
in_buf = read(fd, buf, max_buf_size - 1);
168169
if (in_buf <= 0) { /* no data */
169-
if (in_buf == 0 || (errno != EAGAIN && errno != EWOULDBLOCK)) {
170+
if (in_buf == 0 || !PHP_IS_TRANSIENT_ERROR(errno)) {
170171
/* pipe is closed or error */
171172
read_fail = (in_buf < 0) ? in_buf : 1;
172173
}

0 commit comments

Comments
 (0)