[php-src] master: Avoid call to php_socket_errno() if possible (#13909)
| From: | Niels Dossche via GitHub | Date: | Mon, 08 Apr 2024 17:53:06 +0000 |
| Subject: | [php-src] master: Avoid call to php_socket_errno() if possible (#13909) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127988@lists.php.net to get a copy of this message | ||
Author: Niels Dossche (nielsdos)
Committer: GitHub (web-flow)
Pusher: nielsdos
Date: 2024-04-08T19:53:01+02:00
Commit: https://github.com/php/php-src/commit/ae5220aed66c4aad71209b6fe2f0bda4970ec3b3
Raw diff: https://github.com/php/php-src/commit/ae5220aed66c4aad71209b6fe2f0bda4970ec3b3.diff
Avoid call to php_socket_errno() if possible (#13909)
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).
Changed paths:
M ext/openssl/xp_ssl.c
M main/streams/xp_socket.c
Diff:
diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c
index 1ed32563a7c5..8a83455590f6 100644
--- a/ext/openssl/xp_ssl.c
+++ b/ext/openssl/xp_ssl.c
@@ -2577,13 +2577,17 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int
val
#else
ssize_t ret;
#endif
- int err;
ret = recv(sslsock->s.socket, &buf, sizeof(buf), MSG_PEEK|MSG_DONTWAIT);
- err = php_socket_errno();
- if (0 == ret || /* the counterpart did properly shutdown */
- (0 > ret && err != EWOULDBLOCK && err != EAGAIN && err !=
EMSGSIZE)) { /* there was an unrecoverable error */
+ if (0 == ret) {
+ /* the counterpart did properly shutdown */
alive = 0;
+ } else if (0 > ret) {
+ int err = php_socket_errno();
+ if (err != EWOULDBLOCK && err != EMSGSIZE && err != EAGAIN) {
+ /* there was an unrecoverable error */
+ alive = 0;
+ }
}
}
}
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index 9a36a7098da4..3bc375c40f4c 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -373,13 +373,17 @@ static int php_sockop_set_option(php_stream *stream, int option, int value,
void
#else
ssize_t ret;
#endif
- int err;
ret = recv(sock->socket, &buf, sizeof(buf), MSG_PEEK|MSG_DONTWAIT);
- err = php_socket_errno();
- if (0 == ret || /* the counterpart did properly shutdown*/
- (0 > ret && err != EWOULDBLOCK && err != EAGAIN && err !=
EMSGSIZE)) { /* there was an unrecoverable error */
+ if (0 == ret) {
+ /* the counterpart did properly shutdown */
alive = 0;
+ } else if (0 > ret) {
+ int err = php_socket_errno();
+ if (err != EWOULDBLOCK && err != EMSGSIZE && err != EAGAIN) {
+ /* there was an unrecoverable error */
+ alive = 0;
+ }
}
}
return alive ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;