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)
284 285 286 287 288 289 290 291 292 |
# File 'ext/sendfile.c', line 284 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)
313 314 315 316 317 318 319 320 |
# File 'ext/sendfile.c', line 313 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.
346 347 348 349 350 351 352 353 |
# File 'ext/sendfile.c', line 346 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); } |