mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-26 20:14:47 +01:00
add tcp bind test
This commit is contained in:
parent
506f06a33e
commit
d3d245d4fc
3
php_uv.c
3
php_uv.c
@ -2147,8 +2147,7 @@ PHP_FUNCTION(uv_tcp_bind)
|
||||
|
||||
ZEND_FETCH_RESOURCE(uv, php_uv_t *, &resource, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle);
|
||||
ZEND_FETCH_RESOURCE(addr, php_uv_sockaddr_t *, &address, -1, PHP_UV_SOCKADDR_RESOURCE_NAME, uv_sockaddr_handle);
|
||||
Z_ADDREF_P(resource);
|
||||
|
||||
\
|
||||
r = uv_tcp_bind((uv_tcp_t*)&uv->uv.tcp, addr->addr.ipv4);
|
||||
if (r) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "bind failed");
|
||||
|
32
tests/400-tcp_bind.phpt
Normal file
32
tests/400-tcp_bind.phpt
Normal file
@ -0,0 +1,32 @@
|
||||
--TEST--
|
||||
Check for tcp bind
|
||||
--FILE--
|
||||
<?php
|
||||
$tcp = uv_tcp_init();
|
||||
uv_tcp_bind($tcp, uv_ip4_addr('0.0.0.0',0));
|
||||
uv_listen($tcp,100, function($server){
|
||||
$client = uv_tcp_init();
|
||||
uv_accept($server, $client);
|
||||
uv_read_start($client, function($socket, $nread, $buffer) use ($server){
|
||||
echo $buffer . PHP_EOL;
|
||||
uv_close($socket);
|
||||
uv_close($server,function() use ($server){
|
||||
uv_unref($server);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$addrinfo = uv_tcp_getsockname($tcp);
|
||||
|
||||
$c = uv_tcp_init();
|
||||
uv_tcp_connect($c, uv_ip4_addr($addrinfo['address'],$addrinfo['port']), function($client, $stat){
|
||||
if ($stat == 0) {
|
||||
uv_write($client,"Hello",function($socket, $stat){
|
||||
uv_close($socket,function(){});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
uv_run();
|
||||
--EXPECT--
|
||||
Hello
|
Loading…
Reference in New Issue
Block a user