mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-30 04:29:01 +01:00
add pipe_bind test case
This commit is contained in:
parent
2edefe2d55
commit
1733e1e404
@ -1,27 +1,28 @@
|
||||
<?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($p, $nread, $b) use ($pipe){
|
||||
var_dump($b);
|
||||
var_dump($p);
|
||||
echo "'no2x'";
|
||||
uv_close($p);
|
||||
<?php
|
||||
define("PIPE_PATH", dirname(__FILE__) . "/pipe_test.sock");
|
||||
@unlink(PIPE_PATH);
|
||||
$a = uv_pipe_init(uv_default_loop(), 0);
|
||||
$ret = uv_pipe_bind($a,PIPE_PATH);
|
||||
|
||||
uv_listen($a, 8192, function($stream){
|
||||
$pipe = uv_pipe_init(uv_default_loop(),0);
|
||||
uv_accept($stream,$pipe);
|
||||
uv_read_start($pipe,function($pipe, $nread, $buffer) use ($stream){
|
||||
echo $buffer;
|
||||
uv_read_stop($pipe);
|
||||
uv_close($stream, function(){
|
||||
@unlink(PIPE_PATH);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$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);
|
||||
$b = uv_pipe_init(uv_default_loop(), 0);
|
||||
uv_pipe_connect($b, PIPE_PATH, function($a,$b){
|
||||
uv_write($b,"Hello", function($stream,$stat){
|
||||
uv_close($stream);
|
||||
});
|
||||
});
|
||||
|
||||
uv_run();
|
||||
exit;
|
||||
/*
|
||||
$ares = uv_ares_init_options($loop,array('servers'=>array(), 'tcp_port', 'flags'), $mask)
|
||||
*/
|
||||
exit
|
8
php_uv.c
8
php_uv.c
@ -3227,14 +3227,18 @@ PHP_FUNCTION(uv_pipe_bind)
|
||||
php_uv_t *uv;
|
||||
zval *handle;
|
||||
char *name;
|
||||
int name_len = 0;
|
||||
int error, name_len = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
||||
"zs",&handle, &name, &name_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
ZEND_FETCH_RESOURCE(uv, php_uv_t *, &handle, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle);
|
||||
uv_pipe_bind(&uv->uv.pipe, name);
|
||||
error = uv_pipe_bind(&uv->uv.pipe, name);
|
||||
if (error) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", uv_strerror(uv_last_error(uv_default_loop())));
|
||||
}
|
||||
RETURN_LONG(error);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
32
tests/600-pipe_bind.phpt
Normal file
32
tests/600-pipe_bind.phpt
Normal file
@ -0,0 +1,32 @@
|
||||
--TEST--
|
||||
Check for pipe bind
|
||||
--FILE--
|
||||
<?php
|
||||
define("PIPE_PATH", dirname(__FILE__) . "/pipe_test.sock");
|
||||
@unlink(PIPE_PATH);
|
||||
$a = uv_pipe_init(uv_default_loop(), 0);
|
||||
$ret = uv_pipe_bind($a,PIPE_PATH);
|
||||
|
||||
uv_listen($a, 8192, function($stream){
|
||||
$pipe = uv_pipe_init(uv_default_loop(),0);
|
||||
uv_accept($stream,$pipe);
|
||||
uv_read_start($pipe,function($pipe, $nread, $buffer) use ($stream){
|
||||
echo $buffer;
|
||||
uv_read_stop($pipe);
|
||||
uv_close($stream, function(){
|
||||
@unlink(PIPE_PATH);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$b = uv_pipe_init(uv_default_loop(), 0);
|
||||
uv_pipe_connect($b, PIPE_PATH, function($a,$b){
|
||||
uv_write($b,"Hello", function($stream,$stat){
|
||||
uv_close($stream);
|
||||
});
|
||||
});
|
||||
|
||||
uv_run();
|
||||
exit;
|
||||
--EXPECT--
|
||||
Hello
|
Loading…
Reference in New Issue
Block a user