uv_listen callback is not destroyed by gc anymore

This commit is contained in:
Andrey Kostylev 2017-02-24 14:57:58 +03:00
parent 3815766985
commit 1f8fde011b
2 changed files with 70 additions and 1 deletions

View File

@ -1585,7 +1585,8 @@ static void php_uv_listen_cb(uv_stream_t* server, int status)
php_uv_do_callback2(&retval, uv, params, 2, PHP_UV_LISTEN_CB TSRMLS_CC);
zval_ptr_dtor(&params[0]);
PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_listen_cb, uv->resource_id);
zval_ptr_dtor(&params[1]);
zval_ptr_dtor(&retval);
}

View File

@ -0,0 +1,68 @@
--TEST--
Check for uv_listen callback is not destroyed by gc
--FILE--
<?php
class TcpServer
{
private $loop;
private $tcp;
public function __construct($loop)
{
$this->loop = $loop;
$this->tcp = uv_tcp_init($loop);
}
public function bind(string $address, int $port)
{
uv_tcp_bind($this->tcp, uv_ip4_addr($address, $port));
}
public function listen()
{
uv_listen($this->tcp, 100, function ($server, $status) {
$client = uv_tcp_init($this->loop);
uv_accept($server, $client);
uv_read_start($client, function ($socket, $nread, $buffer) {
echo 'OK', PHP_EOL;
uv_close($socket);
});
});
}
public function close()
{
if (get_resource_type($this->tcp) === 'uv') {
uv_close($this->tcp);
}
}
}
$loop = uv_loop_new();
$tcpServer = new TcpServer($loop);
$tcpServer->bind('0.0.0.0', 9876);
$tcpServer->listen();
$closed = 0;
for ($i = 0; $i < 4; $i++) {
$c = uv_tcp_init($loop);
uv_tcp_connect($c, uv_ip4_addr('0.0.0.0', 9876), function ($stream, $stat) use (&$closed, $tcpServer) {
$closed++;
uv_close($stream);
if ($closed === 4) {
$tcpServer->close();
}
});
}
uv_run($loop, UV::RUN_DEFAULT);
--EXPECTF--
OK
OK
OK
OK