summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-10-02 14:13:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-10-02 14:13:58 +0000
commit71c41cf5a5a72e2f7f1f7b7ac1a14213f1fb52cc (patch)
tree8ecc76cc309c3201a4501b047be7223bf3b2a587 /io.c
parentab6b4786152b663215f05841f7d131d1a7f43db7 (diff)
* io.c (rb_io_wait_readable): handle retryable errors.
* io.c (rb_io_wait_writable): ditto. * ext/socket/socket.c (bsock_send): ditto. * ext/socket/socket.c (s_recvfrom): ditto. * ext/socket/socket.c (s_accept): ditto. * ext/socket/socket.c (udp_send): ditto. * ext/socket/getaddrinfo.c (afdl): made private structures constant. * rubyio.h: prototype; rb_io_wait_readable(), rb_io_wait_writable(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c105
1 files changed, 57 insertions, 48 deletions
diff --git a/io.c b/io.c
index a10ff06..bad70da 100644
--- a/io.c
+++ b/io.c
@@ -250,24 +250,60 @@ io_fflush(f, fptr)
fptr->mode &= ~FMODE_WBUF;
}
-void
+int
rb_io_wait_readable(f)
int f;
{
fd_set rfds;
- FD_ZERO(&rfds);
- FD_SET(f, &rfds);
- rb_thread_select(f + 1, &rfds, NULL, NULL, NULL);
+
+ switch (errno) {
+ case EINTR:
+#if defined(ERESTART)
+ case ERESTART:
+#endif
+ rb_thread_wait_fd(f);
+ return Qtrue;
+
+ case EAGAIN:
+#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
+ case EWOULDBLOCK:
+#endif
+ FD_ZERO(&rfds);
+ FD_SET(f, &rfds);
+ rb_thread_select(f + 1, &rfds, NULL, NULL, NULL);
+ return Qtrue;
+
+ default:
+ return Qfalse;
+ }
}
-void
+int
rb_io_wait_writable(f)
int f;
{
fd_set wfds;
- FD_ZERO(&wfds);
- FD_SET(f, &wfds);
- rb_thread_select(f + 1, NULL, &wfds, NULL, NULL);
+
+ switch (errno) {
+ case EINTR:
+#if defined(ERESTART)
+ case ERESTART:
+#endif
+ rb_thread_fd_writable(f);
+ return Qtrue;
+
+ case EAGAIN:
+#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
+ case EWOULDBLOCK:
+#endif
+ FD_ZERO(&wfds);
+ FD_SET(f, &wfds);
+ rb_thread_select(f + 1, NULL, &wfds, NULL, NULL);
+ return Qtrue;
+
+ default:
+ return Qfalse;
+ }
}
/* writing functions */
@@ -308,20 +344,9 @@ io_write(io, str)
ptr += r;
n -= r;
if (ferror(f)) {
- switch (errno) {
- case EINTR:
-#if defined(ERESTART)
- case ERESTART:
-#endif
+ if (rb_io_wait_writable(fileno(f))) {
clearerr(f);
continue;
- case EAGAIN:
-#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- clearerr(f);
- rb_io_wait_writable(fileno(f));
- continue;
}
rb_sys_fail(fptr->path);
}
@@ -571,31 +596,6 @@ rb_io_to_io(io)
}
/* reading functions */
-static void
-io_read_retryable(f, path)
- FILE *f;
- const char *path;
-{
- switch (errno) {
- case EINTR:
-#if defined(ERESTART)
- case ERESTART:
-#endif
- clearerr(f);
- break;
- case EAGAIN:
-#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- clearerr(f);
- rb_io_wait_readable(fileno(f));
- break;
- default:
- rb_sys_fail(path);
- break;
- }
-}
-
long
rb_io_fread(ptr, len, f)
char *ptr;
@@ -636,6 +636,9 @@ rb_io_fread(ptr, len, f)
if (ferror(f)) {
switch (errno) {
case EINTR:
+#if defined(ERESTART)
+ case ERESTART:
+#endif
clearerr(f);
continue;
case EAGAIN:
@@ -820,7 +823,9 @@ appendline(fptr, delim, strp)
TRAP_END;
if (c == EOF) {
if (ferror(f)) {
- io_read_retryable(f, fptr->path);
+ if (!rb_io_wait_readable(fileno(f)))
+ rb_sys_fail(fptr->path);
+ clearerr(f);
continue;
}
return c;
@@ -1133,7 +1138,9 @@ rb_io_each_byte(io)
TRAP_END;
if (c == EOF) {
if (ferror(f)) {
- io_read_retryable(f, fptr->path);
+ if (!rb_io_wait_readable(fileno(f)))
+ rb_sys_fail(fptr->path);
+ clearerr(f);
continue;
}
break;
@@ -1164,7 +1171,9 @@ rb_io_getc(io)
if (c == EOF) {
if (ferror(f)) {
- io_read_retryable(f, fptr->path);
+ if (!rb_io_wait_readable(fileno(f)))
+ rb_sys_fail(fptr->path);
+ clearerr(f);
goto retry;
}
return Qnil;