mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-30 04:29:01 +01:00
uv_listen callback is not destroyed by gc anymore
This commit is contained in:
parent
3815766985
commit
1f8fde011b
3
php_uv.c
3
php_uv.c
@ -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(¶ms[0]);
|
||||
PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_listen_cb, uv->resource_id);
|
||||
|
||||
zval_ptr_dtor(¶ms[1]);
|
||||
zval_ptr_dtor(&retval);
|
||||
}
|
||||
|
68
tests/005-uv_listen_cb-not-destroyed.phpt
Normal file
68
tests/005-uv_listen_cb-not-destroyed.phpt
Normal 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
|
Loading…
Reference in New Issue
Block a user