main: pack _php_netstream_data_t and use bool instead of int type (#19331)

Fix use sites at the same time
This commit is contained in:
Gina Peter Banyard 2025-07-31 19:56:38 +01:00 committed by GitHub
parent 0591defd6f
commit dad28a30f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 24 deletions

View file

@ -237,7 +237,7 @@ static int php_openssl_handle_ssl_error(php_stream *stream, int nr_bytes, bool i
char esbuf[512]; char esbuf[512];
smart_str ebuf = {0}; smart_str ebuf = {0};
unsigned long ecode; unsigned long ecode;
int retry = 1; bool retry = true;
switch(err) { switch(err) {
case SSL_ERROR_ZERO_RETURN: case SSL_ERROR_ZERO_RETURN:
@ -249,7 +249,7 @@ static int php_openssl_handle_ssl_error(php_stream *stream, int nr_bytes, bool i
/* re-negotiation, or perhaps the SSL layer needs more /* re-negotiation, or perhaps the SSL layer needs more
* packets: retry in next iteration */ * packets: retry in next iteration */
errno = EAGAIN; errno = EAGAIN;
retry = is_init ? 1 : sslsock->s.is_blocked; retry = is_init ? true : sslsock->s.is_blocked;
break; break;
case SSL_ERROR_SYSCALL: case SSL_ERROR_SYSCALL:
if (ERR_peek_error() == 0) { if (ERR_peek_error() == 0) {
@ -1806,7 +1806,7 @@ static int php_openssl_enable_crypto(php_stream *stream,
if (cparam->inputs.activate && !sslsock->ssl_active) { if (cparam->inputs.activate && !sslsock->ssl_active) {
struct timeval start_time, *timeout; struct timeval start_time, *timeout;
int blocked = sslsock->s.is_blocked, has_timeout = 0; bool blocked = sslsock->s.is_blocked, has_timeout = false;
#ifdef HAVE_TLS_SNI #ifdef HAVE_TLS_SNI
if (sslsock->is_client) { if (sslsock->is_client) {
@ -1946,8 +1946,8 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
int retry = 1; int retry = 1;
struct timeval start_time; struct timeval start_time;
struct timeval *timeout = NULL; struct timeval *timeout = NULL;
int began_blocked = sslsock->s.is_blocked; bool began_blocked = sslsock->s.is_blocked;
int has_timeout = 0; bool has_timeout = false;
int nr_bytes = 0; int nr_bytes = 0;
/* prevent overflow in openssl */ /* prevent overflow in openssl */
@ -1965,7 +1965,7 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
} }
if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) { if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) {
has_timeout = 1; has_timeout = true;
/* gettimeofday is not monotonic; using it here is not strictly correct */ /* gettimeofday is not monotonic; using it here is not strictly correct */
gettimeofday(&start_time, NULL); gettimeofday(&start_time, NULL);
} }
@ -1987,7 +1987,7 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
if (began_blocked) { if (began_blocked) {
php_openssl_set_blocking(sslsock, 1); php_openssl_set_blocking(sslsock, 1);
} }
sslsock->s.timeout_event = 1; sslsock->s.timeout_event = true;
return -1; return -1;
} }
} }
@ -2248,7 +2248,7 @@ static inline int php_openssl_tcp_sockop_accept(php_stream *stream, php_openssl_
clisockdata->s.socket = clisock; clisockdata->s.socket = clisock;
#ifdef __linux__ #ifdef __linux__
/* O_NONBLOCK is not inherited on Linux */ /* O_NONBLOCK is not inherited on Linux */
clisockdata->s.is_blocked = 1; clisockdata->s.is_blocked = true;
#endif #endif
xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+"); xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+");
@ -2379,8 +2379,8 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
int retry = 1; int retry = 1;
struct timeval start_time; struct timeval start_time;
struct timeval *timeout = NULL; struct timeval *timeout = NULL;
int began_blocked = sslsock->s.is_blocked; bool began_blocked = sslsock->s.is_blocked;
int has_timeout = 0; bool has_timeout = false;
/* never use a timeout with non-blocking sockets */ /* never use a timeout with non-blocking sockets */
if (began_blocked) { if (began_blocked) {
@ -2392,7 +2392,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
} }
if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) { if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) {
has_timeout = 1; has_timeout = true;
/* gettimeofday is not monotonic; using it here is not strictly correct */ /* gettimeofday is not monotonic; using it here is not strictly correct */
gettimeofday(&start_time, NULL); gettimeofday(&start_time, NULL);
} }
@ -2414,7 +2414,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
if (began_blocked) { if (began_blocked) {
php_openssl_set_blocking(sslsock, 1); php_openssl_set_blocking(sslsock, 1);
} }
sslsock->s.timeout_event = 1; sslsock->s.timeout_event = true;
return PHP_STREAM_OPTION_RETURN_ERR; return PHP_STREAM_OPTION_RETURN_ERR;
} }
} }
@ -2438,7 +2438,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
} }
/* Don't loop indefinitely in non-blocking mode if no data is available */ /* Don't loop indefinitely in non-blocking mode if no data is available */
if (began_blocked == 0 || !has_timeout) { if (!began_blocked || !has_timeout) {
alive = retry; alive = retry;
break; break;
} }
@ -2668,7 +2668,7 @@ php_stream *php_openssl_ssl_socket_factory(const char *proto, size_t protolen,
sslsock = pemalloc(sizeof(php_openssl_netstream_data_t), persistent_id ? 1 : 0); sslsock = pemalloc(sizeof(php_openssl_netstream_data_t), persistent_id ? 1 : 0);
memset(sslsock, 0, sizeof(*sslsock)); memset(sslsock, 0, sizeof(*sslsock));
sslsock->s.is_blocked = 1; sslsock->s.is_blocked = true;
/* this timeout is used by standard stream funcs, therefore it should use the default value */ /* this timeout is used by standard stream funcs, therefore it should use the default value */
#ifdef _WIN32 #ifdef _WIN32
sslsock->s.timeout.tv_sec = (long)FG(default_socket_timeout); sslsock->s.timeout.tv_sec = (long)FG(default_socket_timeout);

View file

@ -1109,7 +1109,7 @@ PHPAPI php_stream *_php_stream_sock_open_from_socket(php_socket_t socket, const
sock = pemalloc(sizeof(php_netstream_data_t), persistent_id ? 1 : 0); sock = pemalloc(sizeof(php_netstream_data_t), persistent_id ? 1 : 0);
memset(sock, 0, sizeof(php_netstream_data_t)); memset(sock, 0, sizeof(php_netstream_data_t));
sock->is_blocked = 1; sock->is_blocked = true;
sock->timeout.tv_sec = FG(default_socket_timeout); sock->timeout.tv_sec = FG(default_socket_timeout);
sock->timeout.tv_usec = 0; sock->timeout.tv_usec = 0;
sock->socket = socket; sock->socket = socket;

View file

@ -313,9 +313,9 @@ END_EXTERN_C()
struct _php_netstream_data_t { struct _php_netstream_data_t {
php_socket_t socket; php_socket_t socket;
char is_blocked; bool is_blocked;
bool timeout_event;
struct timeval timeout; struct timeval timeout;
char timeout_event;
size_t ownsize; size_t ownsize;
}; };
typedef struct _php_netstream_data_t php_netstream_data_t; typedef struct _php_netstream_data_t php_netstream_data_t;

View file

@ -80,13 +80,13 @@ retry:
if (sock->is_blocked) { if (sock->is_blocked) {
int retval; int retval;
sock->timeout_event = 0; sock->timeout_event = false;
do { do {
retval = php_pollfd_for(sock->socket, POLLOUT, ptimeout); retval = php_pollfd_for(sock->socket, POLLOUT, ptimeout);
if (retval == 0) { if (retval == 0) {
sock->timeout_event = 1; sock->timeout_event = true;
break; break;
} }
@ -129,7 +129,7 @@ static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data
return; return;
} }
sock->timeout_event = 0; sock->timeout_event = false;
if (has_buffered_data) { if (has_buffered_data) {
/* If there is already buffered data, use no timeout. */ /* If there is already buffered data, use no timeout. */
@ -146,7 +146,7 @@ static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data
retval = php_pollfd_for(sock->socket, PHP_POLLREADABLE, ptimeout); retval = php_pollfd_for(sock->socket, PHP_POLLREADABLE, ptimeout);
if (retval == 0) if (retval == 0)
sock->timeout_event = 1; sock->timeout_event = true;
if (retval >= 0) if (retval >= 0)
break; break;
@ -399,7 +399,7 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
case PHP_STREAM_OPTION_READ_TIMEOUT: case PHP_STREAM_OPTION_READ_TIMEOUT:
sock->timeout = *(struct timeval*)ptrparam; sock->timeout = *(struct timeval*)ptrparam;
sock->timeout_event = 0; sock->timeout_event = false;
return PHP_STREAM_OPTION_RETURN_OK; return PHP_STREAM_OPTION_RETURN_OK;
case PHP_STREAM_OPTION_META_DATA_API: case PHP_STREAM_OPTION_META_DATA_API:
@ -885,7 +885,7 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t
clisockdata->socket = clisock; clisockdata->socket = clisock;
#ifdef __linux__ #ifdef __linux__
/* O_NONBLOCK is not inherited on Linux */ /* O_NONBLOCK is not inherited on Linux */
clisockdata->is_blocked = 1; clisockdata->is_blocked = true;
#endif #endif
xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+"); xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+");
@ -963,7 +963,7 @@ PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, size_t p
sock = pemalloc(sizeof(php_netstream_data_t), persistent_id ? 1 : 0); sock = pemalloc(sizeof(php_netstream_data_t), persistent_id ? 1 : 0);
memset(sock, 0, sizeof(php_netstream_data_t)); memset(sock, 0, sizeof(php_netstream_data_t));
sock->is_blocked = 1; sock->is_blocked = true;
sock->timeout.tv_sec = FG(default_socket_timeout); sock->timeout.tv_sec = FG(default_socket_timeout);
sock->timeout.tv_usec = 0; sock->timeout.tv_usec = 0;