Skip to content

Commit 75b8114

Browse files
committed
Avoid call to php_socket_errno() if possible
This call is only necessary if ret < 0. Note that I also had to reoder the checks for EWOULDBLOCK, EMSGSIZE, EAGAIN to avoid a false positive GCC warning about a duplicate condition (EAGAIN == EWOULDBLOCK on my system).
1 parent 0f1e979 commit 75b8114

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

ext/openssl/xp_ssl.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,13 +2577,17 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
25772577
#else
25782578
ssize_t ret;
25792579
#endif
2580-
int err;
25812580

25822581
ret = recv(sslsock->s.socket, &buf, sizeof(buf), MSG_PEEK|MSG_DONTWAIT);
2583-
err = php_socket_errno();
2584-
if (0 == ret || /* the counterpart did properly shutdown */
2585-
(0 > ret && err != EWOULDBLOCK && err != EAGAIN && err != EMSGSIZE)) { /* there was an unrecoverable error */
2582+
if (0 == ret) {
2583+
/* the counterpart did properly shutdown */
25862584
alive = 0;
2585+
} else if (0 > ret) {
2586+
int err = php_socket_errno();
2587+
if (err != EWOULDBLOCK && err != EMSGSIZE && err != EAGAIN) {
2588+
/* there was an unrecoverable error */
2589+
alive = 0;
2590+
}
25872591
}
25882592
}
25892593
}

main/streams/xp_socket.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,17 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
373373
#else
374374
ssize_t ret;
375375
#endif
376-
int err;
377376

378377
ret = recv(sock->socket, &buf, sizeof(buf), MSG_PEEK|MSG_DONTWAIT);
379-
err = php_socket_errno();
380-
if (0 == ret || /* the counterpart did properly shutdown*/
381-
(0 > ret && err != EWOULDBLOCK && err != EAGAIN && err != EMSGSIZE)) { /* there was an unrecoverable error */
378+
if (0 == ret) {
379+
/* the counterpart did properly shutdown */
382380
alive = 0;
381+
} else if (0 > ret) {
382+
int err = php_socket_errno();
383+
if (err != EWOULDBLOCK && err != EMSGSIZE && err != EAGAIN) {
384+
/* there was an unrecoverable error */
385+
alive = 0;
386+
}
383387
}
384388
}
385389
return alive ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;

0 commit comments

Comments
 (0)