Skip to content

Commit

Permalink
* io.c (rb_io_wait_readable): handle retryable errors.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Oct 2, 2002
1 parent ab6b478 commit 71c41cf
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 66 deletions.
18 changes: 18 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Wed Oct 2 23:09:20 2002 Nobuyoshi Nakada <[email protected]>

* 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().

Wed Oct 2 13:03:58 2002 WATANABE Hirofumi <[email protected]>

* configure.in: set ac_cv_func_setitimer to "no" on Cygwin.
Expand Down
12 changes: 6 additions & 6 deletions ext/socket/getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct sockinet {
u_short si_port;
};

static struct afd {
static const struct afd {
int a_af;
int a_addrlen;
int a_socklen;
Expand Down Expand Up @@ -136,14 +136,14 @@ static struct afd {
#define PTON_MAX 4
#endif

static int get_name __P((const char *, struct afd *,
static int get_name __P((const char *, const struct afd *,
struct addrinfo **, char *, struct addrinfo *,
int));
static int get_addr __P((const char *, int, struct addrinfo **,
struct addrinfo *, int));
static int str_isnumber __P((const char *));

static const char *ai_errlist[] = {
static const char *const ai_errlist[] = {
"success.",
"address family for hostname not supported.", /* EAI_ADDRFAMILY */
"temporary failure in name resolution.", /* EAI_AGAIN */
Expand Down Expand Up @@ -418,7 +418,7 @@ getaddrinfo(hostname, servname, hints, res)
* non-passive socket -> localhost (127.0.0.1 or ::1)
*/
if (hostname == NULL) {
struct afd *afd;
const struct afd *afd;
int s;

for (afd = &afdl[0]; afd->a_af; afd++) {
Expand Down Expand Up @@ -533,7 +533,7 @@ getaddrinfo(hostname, servname, hints, res)
static int
get_name(addr, afd, res, numaddr, pai, port0)
const char *addr;
struct afd *afd;
const struct afd *afd;
struct addrinfo **res;
char *numaddr;
struct addrinfo *pai;
Expand Down Expand Up @@ -588,7 +588,7 @@ get_addr(hostname, af, res, pai, port0)
struct addrinfo sentinel;
struct hostent *hp;
struct addrinfo *top, *cur;
struct afd *afd;
const struct afd *afd;
int i, error = 0, h_error;
char *ap;

Expand Down
19 changes: 7 additions & 12 deletions ext/socket/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ bsock_send(argc, argv, sock)
GetOpenFile(sock, fptr);
f = GetWriteFile(fptr);
fd = fileno(f);
retry:
rb_thread_fd_writable(fd);
StringValue(mesg);
retry:
if (!NIL_P(to)) {
StringValue(to);
n = sendto(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
Expand All @@ -380,9 +380,7 @@ bsock_send(argc, argv, sock)
n = send(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags));
}
if (n < 0) {
switch (errno) {
case EINTR:
rb_thread_schedule();
if (rb_io_wait_writable(fd)) {
goto retry;
}
rb_sys_fail("send(2)");
Expand Down Expand Up @@ -438,9 +436,7 @@ s_recvfrom(sock, argc, argv, from)
TRAP_END;

if (slen < 0) {
switch (errno) {
case EINTR:
rb_thread_schedule();
if (rb_io_wait_readable(fd)) {
goto retry;
}
rb_sys_fail("recvfrom(2)");
Expand Down Expand Up @@ -1166,8 +1162,9 @@ s_accept(klass, fd, sockaddr, len)
rb_gc();
retry = 1;
goto retry;
case EINTR:
rb_thread_schedule();
default:
if (!rb_io_wait_readable(fd)) break;
retry = 0;
goto retry;
}
rb_sys_fail(0);
Expand Down Expand Up @@ -1431,9 +1428,7 @@ udp_send(argc, argv, sock)
freeaddrinfo(res0);
return INT2FIX(n);
}
switch (errno) {
case EINTR:
rb_thread_schedule();
if (rb_io_wait_writable(fileno(f))) {
goto retry;
}
}
Expand Down
105 changes: 57 additions & 48 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions rubyio.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void rb_io_check_readable _((OpenFile*));
void rb_io_fptr_finalize _((OpenFile*));
void rb_io_synchronized _((OpenFile*));
void rb_io_check_closed _((OpenFile*));
int rb_io_wait_readable _((int));
int rb_io_wait_writable _((int));

VALUE rb_io_taint_check _((VALUE));
void rb_eof_error _((void));
Expand Down

0 comments on commit 71c41cf

Please sign in to comment.