Skip to content

Commit

Permalink
[4.8]Fix bug #5104 (#5113)
Browse files Browse the repository at this point in the history
* Fix assert failed

* Fix bug #5104

* Fix bug #5104

* Fix test
  • Loading branch information
NathanFreeman authored Jul 31, 2023
1 parent 6e1fd74 commit 8eabd1e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
30 changes: 27 additions & 3 deletions ext-src/swoole_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1819,17 +1819,41 @@ static PHP_FUNCTION(swoole_stream_select) {
zval *r_array, *w_array, *e_array;
zend_long sec, usec = 0;
zend_bool secnull;
#if PHP_VERSION_ID >= 80100
bool usecnull = 1;
#endif
int retval = 0;

ZEND_PARSE_PARAMETERS_START(4, 5)
Z_PARAM_ARRAY_EX(r_array, 1, 1)
Z_PARAM_ARRAY_EX(w_array, 1, 1)
Z_PARAM_ARRAY_EX(e_array, 1, 1)
Z_PARAM_ARRAY_EX2(r_array, 1, 1, 0)
Z_PARAM_ARRAY_EX2(w_array, 1, 1, 0)
Z_PARAM_ARRAY_EX2(e_array, 1, 1, 0)
#if PHP_VERSION_ID >= 80100
Z_PARAM_LONG_OR_NULL(sec, secnull)
Z_PARAM_OPTIONAL
Z_PARAM_LONG_OR_NULL(usec, usecnull)
#else

#if PHP_VERSION_ID >= 80000
Z_PARAM_LONG_OR_NULL(sec, secnull)
#else
Z_PARAM_LONG_EX(sec, secnull, 1, 0)
#endif

Z_PARAM_OPTIONAL
Z_PARAM_LONG(usec)
#endif
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

#if PHP_VERSION_ID >= 80100
if (secnull && !usecnull) {
if (usec != 0) {
zend_argument_value_error(5, "must be null when argument #4 ($seconds) is null");
RETURN_THROWS();
}
}
#endif

double timeout = -1;
if (!secnull) {
if (sec < 0) {
Expand Down
6 changes: 3 additions & 3 deletions tests/include/api/curl_multi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ function swoole_test_curl_multi_ex($mh, $options = []) {
$ch2 = curl_init();

// 设置URL和相应的选项
curl_setopt($ch1, CURLOPT_URL, "http://www.baidu.com/");
curl_setopt($ch1, CURLOPT_URL, "https://www.baidu.com/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch2, CURLOPT_URL, "http://www.gov.cn/");
curl_setopt($ch2, CURLOPT_URL, "https://www.zhihu.com/");
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);

Expand Down Expand Up @@ -61,7 +61,7 @@ function swoole_test_curl_multi_ex($mh, $options = []) {
Assert::eq($info3, false);

Assert::contains(curl_multi_getcontent($ch1), 'baidu.com');
Assert::contains(curl_multi_getcontent($ch2), '中央人民政府门户网站');
Assert::contains(curl_multi_getcontent($ch2), 'zhihu');

curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
Expand Down
39 changes: 39 additions & 0 deletions tests/swoole_runtime/bug_5104.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
swoole_runtime: Github#5104 https://github.com/swoole/swoole-src/issues/5104
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
?>
--FILE--
<?php
use function Co\run;

run(function () {
$socket1 = stream_socket_server("tcp://0.0.0.0:8000");
$socket2 = stream_socket_client("tcp://example.com:80");

stream_set_blocking($socket1, 0);
stream_set_blocking($socket2, 0);

$read = [$socket1, $socket2];
$write = [$socket2];
$except = null;
$timeout = null;
stream_select($read, $write, $except, $timeout, null);

if (in_array($socket1, $read)) {
$client = stream_socket_accept($socket1);
fwrite($client, "Hello world!\n");
fclose($client);
}
if (in_array($socket2, $read)) {
$response = fread($socket2, 1024);
}
if (in_array($socket2, $write)) {
fwrite($socket2, "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n");
}
echo 'DONE';
});
?>
--EXPECT--
DONE

0 comments on commit 8eabd1e

Please sign in to comment.