mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c: add rb_read_internal() as blocking function.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2a2e4bbbc3
commit
c4c151bed8
2 changed files with 33 additions and 11 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Fri Nov 23 17:34:24 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* io.c: add rb_read_internal() as blocking function.
|
||||||
|
|
||||||
Fri Nov 23 17:33:39 2007 Koichi Sasada <ko1@atdot.net>
|
Fri Nov 23 17:33:39 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* vm.c: fix comment.
|
* vm.c: fix comment.
|
||||||
|
|
40
io.c
40
io.c
|
@ -902,6 +902,27 @@ rb_io_rewind(VALUE io)
|
||||||
return INT2FIX(0);
|
return INT2FIX(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct read_struct {
|
||||||
|
int fd;
|
||||||
|
void *buf;
|
||||||
|
size_t capa;
|
||||||
|
};
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
read_func(void *ptr)
|
||||||
|
{
|
||||||
|
struct read_struct *rs = (struct read_struct*)ptr;
|
||||||
|
return read(rs->fd, rs->buf, rs->capa);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
rb_read_internal(int fd, void *buf, size_t count)
|
||||||
|
{
|
||||||
|
struct read_struct rs = {fd, buf, count};
|
||||||
|
return rb_thread_blocking_region(read_func, &rs, RB_UBF_DFL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
io_fillbuf(rb_io_t *fptr)
|
io_fillbuf(rb_io_t *fptr)
|
||||||
{
|
{
|
||||||
|
@ -915,9 +936,9 @@ io_fillbuf(rb_io_t *fptr)
|
||||||
}
|
}
|
||||||
if (fptr->rbuf_len == 0) {
|
if (fptr->rbuf_len == 0) {
|
||||||
retry:
|
retry:
|
||||||
TRAP_BEG;
|
{
|
||||||
r = read(fptr->fd, fptr->rbuf, fptr->rbuf_capa);
|
r = rb_read_internal(fptr->fd, fptr->rbuf, fptr->rbuf_capa);
|
||||||
TRAP_END; /* xxx: signal handler may modify rbuf */
|
}
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
if (rb_io_wait_readable(fptr->fd))
|
if (rb_io_wait_readable(fptr->fd))
|
||||||
goto retry;
|
goto retry;
|
||||||
|
@ -1329,13 +1350,11 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
|
||||||
if (RSTRING_LEN(str) != len) goto modified;
|
if (RSTRING_LEN(str) != len) goto modified;
|
||||||
if (nonblock) {
|
if (nonblock) {
|
||||||
rb_io_set_nonblock(fptr);
|
rb_io_set_nonblock(fptr);
|
||||||
n = read(fptr->fd, RSTRING_PTR(str), len);
|
n = rb_read_internal(fptr->fd, RSTRING_PTR(str), len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
TRAP_BEG;
|
n = rb_read_internal(fptr->fd, RSTRING_PTR(str), len);
|
||||||
n = read(fptr->fd, RSTRING_PTR(str), len);
|
}
|
||||||
TRAP_END;
|
|
||||||
}
|
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (!nonblock && rb_io_wait_readable(fptr->fd))
|
if (!nonblock && rb_io_wait_readable(fptr->fd))
|
||||||
goto again;
|
goto again;
|
||||||
|
@ -2791,9 +2810,8 @@ rb_io_sysread(int argc, VALUE *argv, VALUE io)
|
||||||
if (RSTRING_LEN(str) != ilen) {
|
if (RSTRING_LEN(str) != ilen) {
|
||||||
rb_raise(rb_eRuntimeError, "buffer string modified");
|
rb_raise(rb_eRuntimeError, "buffer string modified");
|
||||||
}
|
}
|
||||||
TRAP_BEG;
|
|
||||||
n = read(fptr->fd, RSTRING_PTR(str), ilen);
|
n = rb_read_internal(fptr->fd, RSTRING_PTR(str), ilen);
|
||||||
TRAP_END;
|
|
||||||
|
|
||||||
if (n == -1) {
|
if (n == -1) {
|
||||||
rb_sys_fail(fptr->path);
|
rb_sys_fail(fptr->path);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue