mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-26 20:14:47 +01:00
adjust uv_tcp_bind signature
This commit is contained in:
parent
789ce066a5
commit
e7b0c7b4d6
12
examples/pipe.php
Normal file
12
examples/pipe.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
$pipe = uv_pipe_init(1,1);
|
||||
uv_pipe_open($pipe, 1);
|
||||
//uv_pipe_bind($pipe,"/tmp/hoge.sock");
|
||||
|
||||
uv_write($pipe, "Hello",function($s,$b){
|
||||
echo 1;
|
||||
uv_close($b);
|
||||
});
|
||||
|
||||
uv_run();
|
27
examples/pipe_bind_connect.php
Normal file
27
examples/pipe_bind_connect.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
$a = uv_pipe_init(0,0);
|
||||
uv_pipe_bind($a,"/tmp/test.sock");
|
||||
uv_listen($a,8192,function($a){
|
||||
$pipe = uv_pipe_init(0,0);
|
||||
uv_accept($a,$pipe);
|
||||
uv_read_start($pipe,function($b,$p) use ($pipe){
|
||||
var_dump($b);
|
||||
var_dump($p);
|
||||
echo "'no2x'";
|
||||
uv_close($p);
|
||||
uv_read_stop($pipe);
|
||||
});
|
||||
});
|
||||
|
||||
$b = uv_pipe_init(0,0);
|
||||
uv_pipe_connect($b, "/tmp/test.sock", function($a,$b){
|
||||
uv_write($b,"Hello", function($b,$c){
|
||||
uv_close($c);
|
||||
});
|
||||
});
|
||||
|
||||
uv_run();
|
||||
exit;
|
||||
/*
|
||||
$ares = uv_ares_init_options($loop,array('servers'=>array(), 'tcp_port', 'flags'), $mask)
|
||||
*/
|
24
examples/tcp_bind.php
Normal file
24
examples/tcp_bind.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
$tcp = uv_tcp_init();
|
||||
|
||||
uv_tcp_bind($tcp, uv_ip4_addr('0.0.0.0',9999));
|
||||
|
||||
uv_listen($tcp,100, function($server){
|
||||
$client = uv_tcp_init();
|
||||
uv_accept($server, $client);
|
||||
uv_read_start($client, function($buffer, $socket){
|
||||
var_dump($buffer);
|
||||
uv_close($socket);
|
||||
});
|
||||
});
|
||||
|
||||
$c = uv_tcp_init();
|
||||
uv_tcp_connect($c, uv_ip4_addr('0.0.0.0',9999), function($stat, $client){
|
||||
if ($stat == 0) {
|
||||
uv_write($client,"Hello",function($stat,$socket){
|
||||
uv_close($socket);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
uv_run();
|
@ -2,7 +2,7 @@
|
||||
$udp = uv_udp_init();
|
||||
var_dump($udp);
|
||||
|
||||
uv_udp_bind($udp, '0.0.0.0',10000);
|
||||
uv_udp_bind($udp, uv_ip4_addr('0.0.0.0',10000));
|
||||
|
||||
uv_udp_recv_start($udp,function($buffer,$udp){
|
||||
echo "recv:" . $buffer;
|
||||
|
28
php_uv.c
28
php_uv.c
@ -802,7 +802,6 @@ ZEND_END_ARG_INFO()
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_udp_bind, 0, 0, 3)
|
||||
ZEND_ARG_INFO(0, resource)
|
||||
ZEND_ARG_INFO(0, address)
|
||||
ZEND_ARG_INFO(0, port)
|
||||
ZEND_ARG_INFO(0, flags)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
@ -1061,23 +1060,21 @@ PHP_FUNCTION(uv_now)
|
||||
/* {{{ */
|
||||
PHP_FUNCTION(uv_tcp_bind)
|
||||
{
|
||||
zval *resource;
|
||||
char *address;
|
||||
int address_len;
|
||||
long port = 8080;
|
||||
struct sockaddr_in addr;
|
||||
zval *resource, *address;
|
||||
php_uv_sockaddr_t *addr;
|
||||
php_uv_t *uv;
|
||||
int r;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
||||
"zsl",&resource, &address, &address_len, &port) == FAILURE) {
|
||||
"zz",&resource, &address) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ZEND_FETCH_RESOURCE(uv, php_uv_t *, &resource, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle);
|
||||
addr = uv_ip4_addr(address, port);
|
||||
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);
|
||||
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");
|
||||
}
|
||||
@ -1631,24 +1628,21 @@ PHP_FUNCTION(uv_udp_init)
|
||||
/* {{{ */
|
||||
PHP_FUNCTION(uv_udp_bind)
|
||||
{
|
||||
zval *resource;
|
||||
char *address;
|
||||
int address_len;
|
||||
long port = 0;
|
||||
zval *resource, *address;
|
||||
long flags = 0;
|
||||
struct sockaddr_in addr;
|
||||
php_uv_sockaddr_t *addr;
|
||||
php_uv_t *uv;
|
||||
int r;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
||||
"zsl|l",&resource, &address, &address_len, &port, &flags) == FAILURE) {
|
||||
"zz|l",&resource, &address, &flags) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ZEND_FETCH_RESOURCE(uv, php_uv_t *, &resource, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle);
|
||||
addr = uv_ip4_addr(address, port);
|
||||
ZEND_FETCH_RESOURCE(addr, php_uv_sockaddr_t *, &address, -1, PHP_UV_SOCKADDR_RESOURCE_NAME, uv_sockaddr_handle);
|
||||
|
||||
r = uv_udp_bind((uv_udp_t*)&uv->uv.udp, addr, flags);
|
||||
r = uv_udp_bind((uv_udp_t*)&uv->uv.udp, addr->addr.ipv4, flags);
|
||||
if (r) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_udp_bind failed");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user