add uv_fs_close

This commit is contained in:
Shuhei Tanuma 2012-06-22 12:13:11 +09:00
parent 64deffda15
commit 83e9daf1cc
2 changed files with 59 additions and 0 deletions

View File

@ -10,6 +10,9 @@ function r($rs,$data)
uv_fs_read(uv_default_loop(),$x,"r");
} else {
var_dump($buf);
uv_fs_close(uv_default_loop(), $x,function(){
echo "# closed\n";
});
}
}

View File

@ -3548,6 +3548,61 @@ PHP_FUNCTION(uv_fs_read)
/* }}} */
//* UV_EXTERN int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file,uv_fs_cb cb);
/* {{{ */
PHP_FUNCTION(uv_fs_close)
{
int r;
zval *tmp, *zloop = NULL;
zval *callback;
uv_loop_t *loop;
php_uv_t *uv;
unsigned long fd;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"zlz", &zloop, &fd, &callback) == FAILURE) {
return;
}
uv = (php_uv_t *)emalloc(sizeof(php_uv_t));
if (!uv) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_queue_work emalloc failed");
return;
}
if (zloop != NULL) {
ZEND_FETCH_RESOURCE(loop, uv_loop_t*, &zloop, -1, PHP_UV_LOOP_RESOURCE_NAME, uv_loop_handle);
} else {
loop = uv_default_loop();
}
uv->type = IS_UV_FS;
PHP_UV_INIT_ZVALS(uv)
uv->fs_cb = callback;
Z_ADDREF_P(callback);
uv->uv.fs.data = uv;
//uv_fs_read($loop, int $fd, Closure $cb)
//UV_EXTERN int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offset, uv_fs_cb cb);
memset(uv_fs_read_buf, 0, sizeof(uv_fs_read_buf));
r = uv_fs_close(loop, (uv_fs_t*)&uv->uv.fs, fd, php_uv_fs_cb);
if (r) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_fs_close failed");
return;
}
TSRMLS_SET_CTX(uv->thread_ctx);
MAKE_STD_ZVAL(tmp);
ZEND_REGISTER_RESOURCE(tmp, uv, uv_resource_handle);
uv->resource_id = Z_LVAL_P(tmp);
Z_TYPE_P(tmp) = IS_NULL;
zval_ptr_dtor(&tmp);
}
/* }}} */
static zend_function_entry uv_functions[] = {
/* general */
PHP_FE(uv_update_time, arginfo_uv_update_time)
@ -3640,6 +3695,7 @@ static zend_function_entry uv_functions[] = {
/* fs */
PHP_FE(uv_fs_open, NULL)
PHP_FE(uv_fs_read, NULL)
PHP_FE(uv_fs_close, NULL)
/* info */
PHP_FE(uv_loadavg, NULL)
PHP_FE(uv_uptime, NULL)