Skip to content

Commit 6507d8b

Browse files
committed
Merge branch 'PHP-8.6'
* PHP-8.6: sapi/cli: Fix built-in server truncating responses after a partial write
2 parents d2f40b9 + 31db39c commit 6507d8b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎sapi/cli/php_cli_server.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,8 @@ static void php_cli_server_content_sender_ctor(php_cli_server_content_sender *se
10491049
static int php_cli_server_content_sender_send(php_cli_server_content_sender *sender, php_socket_t fd, size_t *nbytes_sent_total) /* {{{ */
10501050
{
10511051
php_cli_server_chunk *chunk, *next;
1052-
size_t _nbytes_sent_total = 0;
1052+
1053+
*nbytes_sent_total = 0;
10531054

10541055
for (chunk = sender->buffer.first; chunk; chunk = next) {
10551056
#ifdef PHP_WIN32
@@ -1067,7 +1068,6 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen
10671068
nbytes_sent = send(fd, chunk->data.heap.p, chunk->data.heap.len, 0);
10681069
#endif
10691070
if (nbytes_sent < 0) {
1070-
*nbytes_sent_total = _nbytes_sent_total;
10711071
return php_socket_errno();
10721072
#ifdef PHP_WIN32
10731073
} else if (nbytes_sent == chunk->data.heap.len) {
@@ -1083,8 +1083,10 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen
10831083
} else {
10841084
chunk->data.heap.p += nbytes_sent;
10851085
chunk->data.heap.len -= nbytes_sent;
1086+
*nbytes_sent_total += nbytes_sent;
1087+
return 0;
10861088
}
1087-
_nbytes_sent_total += nbytes_sent;
1089+
*nbytes_sent_total += nbytes_sent;
10881090
break;
10891091

10901092
case PHP_CLI_SERVER_CHUNK_IMMORTAL:
@@ -1094,7 +1096,6 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen
10941096
nbytes_sent = send(fd, chunk->data.immortal.p, chunk->data.immortal.len, 0);
10951097
#endif
10961098
if (nbytes_sent < 0) {
1097-
*nbytes_sent_total = _nbytes_sent_total;
10981099
return php_socket_errno();
10991100
#ifdef PHP_WIN32
11001101
} else if (nbytes_sent == chunk->data.immortal.len) {
@@ -1110,12 +1111,13 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen
11101111
} else {
11111112
chunk->data.immortal.p += nbytes_sent;
11121113
chunk->data.immortal.len -= nbytes_sent;
1114+
*nbytes_sent_total += nbytes_sent;
1115+
return 0;
11131116
}
1114-
_nbytes_sent_total += nbytes_sent;
1117+
*nbytes_sent_total += nbytes_sent;
11151118
break;
11161119
}
11171120
}
1118-
*nbytes_sent_total = _nbytes_sent_total;
11191121
return 0;
11201122
} /* }}} */
11211123

0 commit comments

Comments
 (0)