Skip to content

Commit

Permalink
Fix bug #5104
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman committed Jul 29, 2023
1 parent 76e3251 commit 6668dc0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
24 changes: 20 additions & 4 deletions ext-src/swoole_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1819,17 +1819,33 @@ 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_LONG_EX(sec, secnull, 1, 0)
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)
Z_PARAM_LONG_OR_NULL(sec, secnull)
Z_PARAM_OPTIONAL
#if PHP_VERSION_ID >= 80100
Z_PARAM_LONG_OR_NULL(usec, usecnull)
#else
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
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 6668dc0

Please sign in to comment.