merging offset changes from PR #60

This commit is contained in:
Steve Rhoades 2014-11-23 18:02:03 +00:00
commit 605a20a568
4 changed files with 32 additions and 8 deletions

View File

@ -2180,7 +2180,7 @@ uv_run();
### void uv_fs_read(resource $loop, zval $fd, long $length, callable $callback)
### void uv_fs_read(resource $loop, zval $fd, long $offset, long $length, callable $callback)
##### *Description*
@ -2192,6 +2192,10 @@ async read.
*zval $fd*: this expects long $fd, resource $php_stream or resource $php_socket.
*long $offset*: the offset position in the file at which reading should commence.
*long $length*: the length in bytes that should be read starting at position *$offset*.
*resource $callback*: this callback parameter expects (zval $fd, long $nread, string $buffer).
##### *Return Value*

View File

@ -1015,14 +1015,15 @@ static void php_uv_fs_common(uv_fs_type fs_type, INTERNAL_FUNCTION_PARAMETERS)
zval *zstream = NULL;
unsigned long fd;
unsigned long length;
unsigned long offset;
PHP_UV_FS_PARSE_PARAMETERS("zzlf", &zloop, &zstream, &length, &fci, &fcc);
PHP_UV_FS_PARSE_PARAMETERS("zzllf", &zloop, &zstream, &offset, &length, &fci, &fcc);
memset(uv_fs_read_buf, 0, length);
uv_fs_read_buf_t = uv_buf_init(uv_fs_read_buf, length);
PHP_UV_FS_SETUP()
PHP_UV_ZVAL_TO_FD(fd, zstream);
PHP_UV_FS_ASYNC(loop, read, fd, &uv_fs_read_buf_t, 1, -1);
PHP_UV_FS_ASYNC(loop, read, fd, &uv_fs_read_buf_t, 1, offset);
break;
}
case UV_FS_SENDFILE:
@ -3095,6 +3096,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_fs_read, 0, 0, 3)
ZEND_ARG_INFO(0, loop)
ZEND_ARG_INFO(0, fd)
ZEND_ARG_INFO(0, offset)
ZEND_ARG_INFO(0, size)
ZEND_ARG_INFO(0, callback)
ZEND_END_ARG_INFO()
@ -5839,7 +5841,7 @@ PHP_FUNCTION(uv_fs_open)
/* }}} */
/* {{{ proto void uv_fs_read(resoruce $loop, zval $fd, callable $callback)
/* {{{ proto void uv_fs_read(resoruce $loop, zval $fd, long $offset, long $length, callable $callback)
*/
PHP_FUNCTION(uv_fs_read)
{

View File

@ -5,7 +5,7 @@ Check for fs read and close
define("FIXTURE_PATH", dirname(__FILE__) . "/fixtures/hello.data");
uv_fs_open(uv_default_loop(),FIXTURE_PATH, UV::O_RDONLY, 0, function($r){
uv_fs_read(uv_default_loop(),$r,32,function($stream, $nread, $data) {
uv_fs_read(uv_default_loop(),$r, $offset=0, $len=32,function($stream, $nread, $data) {
if ($nread <= 0) {
if ($nread < 0) {
throw new Exception("read error");
@ -19,6 +19,24 @@ uv_fs_open(uv_default_loop(),FIXTURE_PATH, UV::O_RDONLY, 0, function($r){
});
});
// test offset
uv_fs_open(uv_default_loop(),FIXTURE_PATH, UV::O_RDONLY, 0, function($r){
uv_fs_read(uv_default_loop(),$r, $offset=1, $len=32,function($stream, $nread, $data) {
if ($nread <= 0) {
if ($nread < 0) {
throw new Exception("read error");
}
uv_fs_close(uv_default_loop(), $stream, function(){
});
} else {
echo $data;
}
});
});
uv_run();
--EXPECT--
Hello
ello

View File

@ -5,7 +5,7 @@ Check for fs read and close
define("FIXTURE_PATH", dirname(__FILE__) . "/fixtures/hello.data");
uv_fs_open(uv_default_loop(),FIXTURE_PATH, UV::O_RDONLY, 0, function($r){
uv_fs_read(uv_default_loop(),$r,32,function($stream, $nread, $data) {
uv_fs_read(uv_default_loop(),$r,0, 32,function($stream, $nread, $data) {
uv_fs_close(uv_default_loop(), 42, function($result) {
if($result != 42) {
echo "OK";