Class: IO
- Inherits:
-
Object
- Object
- IO
- Defined in:
- (unknown)
Instance Method Summary collapse
-
#sendfile(*args) ⇒ Object
writeIO.sendfile( readIO, offset=0, count=nil) => integer.
-
#sendfile_nonblock(*args) ⇒ Object
writeIO.sendfile_nonblock(readIO, offset=0, count=nil) => integer.
-
#trysendfile(*args) ⇒ Object
writeIO.trysendfile(readIO, offset=0, count=nil) => integer, nil, or :wait_writable.
Instance Method Details
#sendfile(*args) ⇒ Object
writeIO.sendfile( readIO, offset=0, count=nil) => integer
Transfers count bytes starting at offset from readIO directly to writeIO without copying (i.e. invoking the kernel to do it for you).
If offset is omitted, transfer starts at the beginning of the file.
If count is omitted, the full length of the file will be sent.
Returns the number of bytes sent on success. Will throw system error exception on error. (check man sendfile(2) on your platform for information on what errors could result and how to handle them)
290 291 292 293 294 295 296 297 298 |
# File 'ext/sendfile.c', line 290
static VALUE rb_io_sendfile(int argc, VALUE *argv, VALUE self)
{
struct sendfile_args args;
convert_args(argc, argv, self, &args);
/* now send the file */
return OFFT2NUM(sendfile_full(&args));
}
|
#sendfile_nonblock(*args) ⇒ Object
writeIO.sendfile_nonblock(readIO, offset=0, count=nil) => integer
Transfers count bytes starting at offset from readIO directly to writeIO without copying (i.e. invoking the kernel to do it for you).
Unlike IO#sendfile, this will set the O_NONBLOCK flag on writeIO before calling sendfile(2) and will raise Errno::EAGAIN instead of blocking. This method is intended for use with non-blocking event frameworks, including those that rely on Fibers.
If offset is omitted, transfer starts at the beginning of the file.
If count is omitted, the full length of the file will be sent.
Returns the number of bytes sent on success. Will throw system error exception on error. (check man sendfile(2) on your platform for information on what errors could result and how to handle them)
319 320 321 322 323 324 325 326 |
# File 'ext/sendfile.c', line 319
static VALUE rb_io_sendfile_nonblock(int argc, VALUE *argv, VALUE self)
{
struct sendfile_args args;
convert_args(argc, argv, self, &args);
return sendfile_nonblock(&args, 0);
}
|
#trysendfile(*args) ⇒ Object
writeIO.trysendfile(readIO, offset=0, count=nil) => integer, nil, or :wait_writable
Transfers count bytes starting at offset from readIO directly to writeIO without copying (i.e. invoking the kernel to do it for you).
Unlike IO#sendfile, this will set the O_NONBLOCK flag on writeIO before calling sendfile(2) and will return :wait_writable instead of blocking. This method is intended for use with non-blocking event frameworks, including those that rely on Fibers.
If offset is omitted, transfer starts at the beginning of the file.
If count is omitted, the full length of the file will be sent.
Returns the number of bytes sent on success, nil on EOF, and :wait_writable on EAGAIN. Will throw system error exception on error. (check man sendfile(2) on your platform for information on what errors could result and how to handle them)
This method is a faster alternative to sendfile_nonblock as it does not raise exceptions on common EAGAIN errors.
352 353 354 355 356 357 358 359 |
# File 'ext/sendfile.c', line 352
static VALUE rb_io_trysendfile(int argc, VALUE *argv, VALUE self)
{
struct sendfile_args args;
convert_args(argc, argv, self, &args);
return sendfile_nonblock(&args, 1);
}
|