change uv_read_start signature.

This commit is contained in:
Shuhei Tanuma 2012-06-30 22:15:29 +09:00
parent 5f7d8610a0
commit f633aa788c
7 changed files with 66 additions and 17 deletions

View File

@ -18,7 +18,7 @@ function pad($str)
uv_listen($tcp,100, function($server) use ($users){
$client = uv_tcp_init();
uv_accept($server, $client);
uv_read_start($client, function($buffer, $socket) use ($users){
uv_read_start($client, function($socket, $buffer, $nread) use ($users){
$buffer = str_replace("/W","",$buffer);
if ($buffer == "\r\n") {
$data = "";

View File

@ -4,7 +4,7 @@ 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){
uv_read_start($pipe,function($p, $b, $nread) use ($pipe){
var_dump($b);
var_dump($p);
echo "'no2x'";

View File

@ -25,7 +25,7 @@ $process = uv_spawn(uv_default_loop(), "php", array('-r','var_dump($_ENV);'), ar
});
});
uv_read_start($out, function($buffer,$stat) use ($out){
uv_read_start($out, function($out, $buffer,$stat){
echo "read_start";
var_dump($out);
var_dump($stat);

View File

@ -8,7 +8,7 @@ uv_listen($tcp,100, function($server){
uv_accept($server, $client);
var_dump(uv_tcp_getsockname($server));
uv_read_start($client, function($buffer, $socket){
uv_read_start($client, function($socket, $buffer, $nread){
var_dump($buffer);
uv_close($socket);
});

26
examples/tcp_bind6.php Normal file
View File

@ -0,0 +1,26 @@
<?php
$tcp = uv_tcp_init();
uv_tcp_bind6($tcp, uv_ip6_addr('::1',9999));
uv_listen($tcp,100, function($server){
$client = uv_tcp_init();
uv_accept($server, $client);
var_dump(uv_tcp_getsockname($server));
uv_read_start($client, function($socket, $buffer, $nread){
echo $buffer;
uv_close($socket);
});
});
$c = uv_tcp_init();
uv_tcp_connect6($c, uv_ip6_addr('::1',9999), function($stat, $client){
if ($stat == 0) {
uv_write($client,"Hello",function($stat,$socket){
uv_close($socket);
});
}
});
uv_run();

18
examples/timer.php Normal file
View File

@ -0,0 +1,18 @@
<?php
$loop = uv_default_loop();
$timer = uv_timer_init();
$i = 0;
uv_timer_start($timer, 10, 1000, function($stat) use (&$i, $timer, $loop){
echo "count: {$i}" . PHP_EOL;
$i++;
if ($i > 3) {
uv_timer_stop($timer);
uv_unref($timer);
}
});
uv_run();
echo "finished";

View File

@ -21,7 +21,7 @@
#include "ext/standard/info.h"
#ifndef PHP_UV_DEBUG
#define PHP_UV_DEBUG 0
#define PHP_UV_DEBUG 1
#endif
#define PHP_UV_INIT_UV(uv, uv_type) \
@ -615,6 +615,9 @@ static void php_uv_close_cb2(uv_handle_t *handle)
PHP_UV_DEBUG_PRINT("uv_close_cb2:\n");
zend_list_delete(uv->resource_id);
// maybe we can't call efree at here.
//efree(handle);
}
static void php_uv_shutdown_cb(uv_shutdown_t* req, int status)
@ -625,10 +628,8 @@ static void php_uv_shutdown_cb(uv_shutdown_t* req, int status)
static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
{
zval *retval_ptr = NULL;
zval **params[2];
zval *buffer;
zval *rsc;
zval *rsc, *buffer, *err, *retval_ptr = NULL;
zval **params[3];
php_uv_t *uv = (php_uv_t*)handle->data;
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
@ -636,19 +637,18 @@ static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
if (nread < 0) {
/* does this should be in user-land ? */
//uv_shutdown_t* req;
uv_shutdown_t* req;
/* Error or EOF */
assert(uv_last_error(uv_default_loop()).code == UV_EOF);
//zend_list_delete(uv->resource_id);
if (buf.base) {
efree(buf.base);
}
//req = (uv_shutdown_t*) emalloc(sizeof *req);
req = (uv_shutdown_t*) emalloc(sizeof *req);
PHP_UV_DEBUG_PRINT("uv_read_cb: read close\n");
uv_close((uv_handle_t *)handle, php_uv_close_cb2);
uv_shutdown(req, (uv_handle_t *)handle, php_uv_shutdown_cb);
return;
}
@ -665,14 +665,19 @@ static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
MAKE_STD_ZVAL(rsc);
ZVAL_RESOURCE(rsc, uv->resource_id);
//zend_list_addref(uv->resource_id);
params[0] = &buffer;
params[1] = &rsc;
php_uv_do_callback(&retval_ptr, uv->read_cb, params, 2 TSRMLS_CC);
MAKE_STD_ZVAL(err)
ZVAL_LONG(err, nread);
params[0] = &rsc;
params[1] = &buffer;
params[2] = &err;
php_uv_do_callback(&retval_ptr, uv->read_cb, params, 3 TSRMLS_CC);
zval_ptr_dtor(&buffer);
zval_ptr_dtor(&rsc);
zval_ptr_dtor(&err);
zval_ptr_dtor(&retval_ptr);
if (buf.base) {