Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uv_fs_read() $offset param allowing seeking on open handles #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand All @@ -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*
Expand Down
10 changes: 6 additions & 4 deletions php_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,12 +950,13 @@ static void php_uv_fs_common(uv_fs_type fs_type, INTERNAL_FUNCTION_PARAMETERS)
zval *zstream = NULL;
unsigned long fd;
unsigned long length;

PHP_UV_FS_PARSE_PARAMETERS("zzlf", &zloop, &zstream, &length, &fci, &fcc);
unsigned long offset;

PHP_UV_FS_PARSE_PARAMETERS("zzllf", &zloop, &zstream, &offset, &length, &fci, &fcc);
memset(uv_fs_read_buf, 0, length);
PHP_UV_FS_SETUP()
PHP_UV_ZVAL_TO_FD(fd, zstream);
PHP_UV_FS_ASYNC(loop, read, fd, uv_fs_read_buf, length, -1);
PHP_UV_FS_ASYNC(loop, read, fd, uv_fs_read_buf, length, offset);
break;
}
case UV_FS_SENDFILE:
Expand Down Expand Up @@ -3023,6 +3024,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()
Expand Down Expand Up @@ -5713,7 +5715,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)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/300-fs.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down