Skip to content

Commit dad28a3

Browse files
authored
main: pack _php_netstream_data_t and use bool instead of int type (#19331)
Fix use sites at the same time
1 parent 0591def commit dad28a3

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

ext/openssl/xp_ssl.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static int php_openssl_handle_ssl_error(php_stream *stream, int nr_bytes, bool i
237237
char esbuf[512];
238238
smart_str ebuf = {0};
239239
unsigned long ecode;
240-
int retry = 1;
240+
bool retry = true;
241241

242242
switch(err) {
243243
case SSL_ERROR_ZERO_RETURN:
@@ -249,7 +249,7 @@ static int php_openssl_handle_ssl_error(php_stream *stream, int nr_bytes, bool i
249249
/* re-negotiation, or perhaps the SSL layer needs more
250250
* packets: retry in next iteration */
251251
errno = EAGAIN;
252-
retry = is_init ? 1 : sslsock->s.is_blocked;
252+
retry = is_init ? true : sslsock->s.is_blocked;
253253
break;
254254
case SSL_ERROR_SYSCALL:
255255
if (ERR_peek_error() == 0) {
@@ -1806,7 +1806,7 @@ static int php_openssl_enable_crypto(php_stream *stream,
18061806

18071807
if (cparam->inputs.activate && !sslsock->ssl_active) {
18081808
struct timeval start_time, *timeout;
1809-
int blocked = sslsock->s.is_blocked, has_timeout = 0;
1809+
bool blocked = sslsock->s.is_blocked, has_timeout = false;
18101810

18111811
#ifdef HAVE_TLS_SNI
18121812
if (sslsock->is_client) {
@@ -1946,8 +1946,8 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
19461946
int retry = 1;
19471947
struct timeval start_time;
19481948
struct timeval *timeout = NULL;
1949-
int began_blocked = sslsock->s.is_blocked;
1950-
int has_timeout = 0;
1949+
bool began_blocked = sslsock->s.is_blocked;
1950+
bool has_timeout = false;
19511951
int nr_bytes = 0;
19521952

19531953
/* prevent overflow in openssl */
@@ -1965,7 +1965,7 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
19651965
}
19661966

19671967
if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) {
1968-
has_timeout = 1;
1968+
has_timeout = true;
19691969
/* gettimeofday is not monotonic; using it here is not strictly correct */
19701970
gettimeofday(&start_time, NULL);
19711971
}
@@ -1987,7 +1987,7 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
19871987
if (began_blocked) {
19881988
php_openssl_set_blocking(sslsock, 1);
19891989
}
1990-
sslsock->s.timeout_event = 1;
1990+
sslsock->s.timeout_event = true;
19911991
return -1;
19921992
}
19931993
}
@@ -2248,7 +2248,7 @@ static inline int php_openssl_tcp_sockop_accept(php_stream *stream, php_openssl_
22482248
clisockdata->s.socket = clisock;
22492249
#ifdef __linux__
22502250
/* O_NONBLOCK is not inherited on Linux */
2251-
clisockdata->s.is_blocked = 1;
2251+
clisockdata->s.is_blocked = true;
22522252
#endif
22532253

22542254
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
23792379
int retry = 1;
23802380
struct timeval start_time;
23812381
struct timeval *timeout = NULL;
2382-
int began_blocked = sslsock->s.is_blocked;
2383-
int has_timeout = 0;
2382+
bool began_blocked = sslsock->s.is_blocked;
2383+
bool has_timeout = false;
23842384

23852385
/* never use a timeout with non-blocking sockets */
23862386
if (began_blocked) {
@@ -2392,7 +2392,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
23922392
}
23932393

23942394
if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) {
2395-
has_timeout = 1;
2395+
has_timeout = true;
23962396
/* gettimeofday is not monotonic; using it here is not strictly correct */
23972397
gettimeofday(&start_time, NULL);
23982398
}
@@ -2414,7 +2414,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
24142414
if (began_blocked) {
24152415
php_openssl_set_blocking(sslsock, 1);
24162416
}
2417-
sslsock->s.timeout_event = 1;
2417+
sslsock->s.timeout_event = true;
24182418
return PHP_STREAM_OPTION_RETURN_ERR;
24192419
}
24202420
}
@@ -2438,7 +2438,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
24382438
}
24392439

24402440
/* Don't loop indefinitely in non-blocking mode if no data is available */
2441-
if (began_blocked == 0 || !has_timeout) {
2441+
if (!began_blocked || !has_timeout) {
24422442
alive = retry;
24432443
break;
24442444
}
@@ -2668,7 +2668,7 @@ php_stream *php_openssl_ssl_socket_factory(const char *proto, size_t protolen,
26682668
sslsock = pemalloc(sizeof(php_openssl_netstream_data_t), persistent_id ? 1 : 0);
26692669
memset(sslsock, 0, sizeof(*sslsock));
26702670

2671-
sslsock->s.is_blocked = 1;
2671+
sslsock->s.is_blocked = true;
26722672
/* this timeout is used by standard stream funcs, therefore it should use the default value */
26732673
#ifdef _WIN32
26742674
sslsock->s.timeout.tv_sec = (long)FG(default_socket_timeout);

main/network.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ PHPAPI php_stream *_php_stream_sock_open_from_socket(php_socket_t socket, const
11091109
sock = pemalloc(sizeof(php_netstream_data_t), persistent_id ? 1 : 0);
11101110
memset(sock, 0, sizeof(php_netstream_data_t));
11111111

1112-
sock->is_blocked = 1;
1112+
sock->is_blocked = true;
11131113
sock->timeout.tv_sec = FG(default_socket_timeout);
11141114
sock->timeout.tv_usec = 0;
11151115
sock->socket = socket;

main/php_network.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ END_EXTERN_C()
313313

314314
struct _php_netstream_data_t {
315315
php_socket_t socket;
316-
char is_blocked;
316+
bool is_blocked;
317+
bool timeout_event;
317318
struct timeval timeout;
318-
char timeout_event;
319319
size_t ownsize;
320320
};
321321
typedef struct _php_netstream_data_t php_netstream_data_t;

main/streams/xp_socket.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ static ssize_t php_sockop_write(php_stream *stream, const char *buf, size_t coun
8080
if (sock->is_blocked) {
8181
int retval;
8282

83-
sock->timeout_event = 0;
83+
sock->timeout_event = false;
8484

8585
do {
8686
retval = php_pollfd_for(sock->socket, POLLOUT, ptimeout);
8787

8888
if (retval == 0) {
89-
sock->timeout_event = 1;
89+
sock->timeout_event = true;
9090
break;
9191
}
9292

@@ -129,7 +129,7 @@ static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data
129129
return;
130130
}
131131

132-
sock->timeout_event = 0;
132+
sock->timeout_event = false;
133133

134134
if (has_buffered_data) {
135135
/* 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
146146
retval = php_pollfd_for(sock->socket, PHP_POLLREADABLE, ptimeout);
147147

148148
if (retval == 0)
149-
sock->timeout_event = 1;
149+
sock->timeout_event = true;
150150

151151
if (retval >= 0)
152152
break;
@@ -399,7 +399,7 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
399399

400400
case PHP_STREAM_OPTION_READ_TIMEOUT:
401401
sock->timeout = *(struct timeval*)ptrparam;
402-
sock->timeout_event = 0;
402+
sock->timeout_event = false;
403403
return PHP_STREAM_OPTION_RETURN_OK;
404404

405405
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
885885
clisockdata->socket = clisock;
886886
#ifdef __linux__
887887
/* O_NONBLOCK is not inherited on Linux */
888-
clisockdata->is_blocked = 1;
888+
clisockdata->is_blocked = true;
889889
#endif
890890

891891
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
963963
sock = pemalloc(sizeof(php_netstream_data_t), persistent_id ? 1 : 0);
964964
memset(sock, 0, sizeof(php_netstream_data_t));
965965

966-
sock->is_blocked = 1;
966+
sock->is_blocked = true;
967967
sock->timeout.tv_sec = FG(default_socket_timeout);
968968
sock->timeout.tv_usec = 0;
969969

0 commit comments

Comments
 (0)