add several fs api

This commit is contained in:
Shuhei Tanuma 2012-06-23 01:45:00 +09:00
parent 1cfb785928
commit cd9f1b959e
6 changed files with 125 additions and 11 deletions

11
TODO.md
View File

@ -39,25 +39,14 @@
* UV_EXTERN uv_err_t uv_resident_set_memory(size_t* rss);
* UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
* UV_EXTERN int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file,uv_fs_cb cb);
* UV_EXTERN int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path,int flags, int mode, uv_fs_cb 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);
* UV_EXTERN int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file,void* buf, size_t length, off_t offset, uv_fs_cb cb);
* UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file out_fd,uv_file in_fd, off_t in_offset, size_t length, uv_fs_cb cb);
* UV_EXTERN int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file,uv_fs_cb cb);
* UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file,uv_fs_cb cb);
* UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file,off_t offset, uv_fs_cb cb);
* UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path,int mode, uv_fs_cb cb);
* UV_EXTERN int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req,const char* path, int flags, uv_fs_cb cb);
* UV_EXTERN int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path,const char* new_path, uv_fs_cb cb);
* UV_EXTERN int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path,uv_fs_cb cb);
* UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path,uv_fs_cb cb);
* UV_EXTERN int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path,uv_fs_cb cb);
* UV_EXTERN int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file,uv_fs_cb cb);
* UV_EXTERN int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path,uv_fs_cb cb);

7
examples/mkdir.php Normal file
View File

@ -0,0 +1,7 @@
<?php
uv_fs_mkdir(uv_default_loop(), "hoge", 0644, function($result){
var_dump($result);
});
uv_run();

19
examples/queue.php Normal file
View File

@ -0,0 +1,19 @@
<?php
$prepare = uv_prepare_init();
uv_prepare_start($prepare,function(){
$loop = uv_default_loop();
$a = function(){
var_dump("[queue]");
};
$b = function(){
echo "[finished]";
};
$queue = uv_queue_work($loop, $a, $b);
$queue2 = uv_queue_work($loop, $a, $b);
});
uv_run();

7
examples/rmdir.php Normal file
View File

@ -0,0 +1,7 @@
<?php
uv_fs_rmdir(uv_default_loop(), "hoge", function($result){
var_dump($result);
});
uv_run();

7
examples/unlink.php Normal file
View File

@ -0,0 +1,7 @@
<?php
uv_fs_unlink(uv_default_loop(), "moe", function($result){
var_dump($result);
});
uv_run();

View File

@ -749,6 +749,9 @@ static void php_uv_fs_cb(uv_fs_t* req)
params[0] = &result;
switch (uv->uv.fs.fs_type) {
case UV_FS_UNLINK:
case UV_FS_RMDIR:
case UV_FS_MKDIR:
case UV_FS_FTRUNCATE:
case UV_FS_FDATASYNC:
case UV_FS_FSYNC:
@ -3790,6 +3793,85 @@ PHP_FUNCTION(uv_fs_ftruncate)
}
/* }}} */
/* {{{ */
PHP_FUNCTION(uv_fs_mkdir)
{
int error;
zval *callback, *tmp, *zloop = NULL;
uv_loop_t *loop;
php_uv_t *uv;
char *path;
int path_len = 0;
long mode = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"zslz", &zloop, &path, &path_len, &mode, &callback) == FAILURE) {
return;
}
PHP_UV_INIT_UV(uv, IS_UV_FS);
PHP_UV_FETCH_UV_DEFAULT_LOOP(loop, zloop);
uv->fs_cb = callback;
Z_ADDREF_P(callback);
uv->uv.fs.data = uv;
PHP_UV_FS_ASYNC(loop, mkdir, path, mode);
}
/* }}} */
/* {{{ */
PHP_FUNCTION(uv_fs_rmdir)
{
int error;
zval *callback, *tmp, *zloop = NULL;
uv_loop_t *loop;
php_uv_t *uv;
char *path;
int path_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"zsz", &zloop, &path, &path_len, &callback) == FAILURE) {
return;
}
PHP_UV_INIT_UV(uv, IS_UV_FS);
PHP_UV_FETCH_UV_DEFAULT_LOOP(loop, zloop);
uv->fs_cb = callback;
Z_ADDREF_P(callback);
uv->uv.fs.data = uv;
PHP_UV_FS_ASYNC(loop, rmdir, path);
}
/* }}} */
/* {{{ */
PHP_FUNCTION(uv_fs_unlink)
{
int error;
zval *callback, *tmp, *zloop = NULL;
uv_loop_t *loop;
php_uv_t *uv;
char *path;
int path_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"zsz", &zloop, &path, &path_len, &callback) == FAILURE) {
return;
}
PHP_UV_INIT_UV(uv, IS_UV_FS);
PHP_UV_FETCH_UV_DEFAULT_LOOP(loop, zloop);
uv->fs_cb = callback;
Z_ADDREF_P(callback);
uv->uv.fs.data = uv;
PHP_UV_FS_ASYNC(loop, unlink, path);
}
/* }}} */
static zend_function_entry uv_functions[] = {
/* general */
@ -3888,6 +3970,9 @@ static zend_function_entry uv_functions[] = {
PHP_FE(uv_fs_fsync, NULL)
PHP_FE(uv_fs_fdatasync, NULL)
PHP_FE(uv_fs_ftruncate, NULL)
PHP_FE(uv_fs_mkdir, NULL)
PHP_FE(uv_fs_rmdir, NULL)
PHP_FE(uv_fs_unlink, NULL)
/* info */
PHP_FE(uv_loadavg, NULL)
PHP_FE(uv_uptime, NULL)