add tcp bind test

This commit is contained in:
Shuhei Tanuma 2012-07-02 13:32:19 +09:00
parent 506f06a33e
commit d3d245d4fc
3 changed files with 33 additions and 2 deletions

View File

@ -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
View 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