mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
ab6b478615
commit
71c41cf5a5
5 changed files with 90 additions and 66 deletions
18
ChangeLog
18
ChangeLog
|
@ -1,3 +1,21 @@
|
||||||
|
Wed Oct 2 23:09:20 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* 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 <eban@ruby-lang.org>
|
Wed Oct 2 13:03:58 2002 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* configure.in: set ac_cv_func_setitimer to "no" on Cygwin.
|
* configure.in: set ac_cv_func_setitimer to "no" on Cygwin.
|
||||||
|
|
|
@ -105,7 +105,7 @@ struct sockinet {
|
||||||
u_short si_port;
|
u_short si_port;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct afd {
|
static const struct afd {
|
||||||
int a_af;
|
int a_af;
|
||||||
int a_addrlen;
|
int a_addrlen;
|
||||||
int a_socklen;
|
int a_socklen;
|
||||||
|
@ -136,14 +136,14 @@ static struct afd {
|
||||||
#define PTON_MAX 4
|
#define PTON_MAX 4
|
||||||
#endif
|
#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 *,
|
struct addrinfo **, char *, struct addrinfo *,
|
||||||
int));
|
int));
|
||||||
static int get_addr __P((const char *, int, struct addrinfo **,
|
static int get_addr __P((const char *, int, struct addrinfo **,
|
||||||
struct addrinfo *, int));
|
struct addrinfo *, int));
|
||||||
static int str_isnumber __P((const char *));
|
static int str_isnumber __P((const char *));
|
||||||
|
|
||||||
static const char *ai_errlist[] = {
|
static const char *const ai_errlist[] = {
|
||||||
"success.",
|
"success.",
|
||||||
"address family for hostname not supported.", /* EAI_ADDRFAMILY */
|
"address family for hostname not supported.", /* EAI_ADDRFAMILY */
|
||||||
"temporary failure in name resolution.", /* EAI_AGAIN */
|
"temporary failure in name resolution.", /* EAI_AGAIN */
|
||||||
|
@ -418,7 +418,7 @@ getaddrinfo(hostname, servname, hints, res)
|
||||||
* non-passive socket -> localhost (127.0.0.1 or ::1)
|
* non-passive socket -> localhost (127.0.0.1 or ::1)
|
||||||
*/
|
*/
|
||||||
if (hostname == NULL) {
|
if (hostname == NULL) {
|
||||||
struct afd *afd;
|
const struct afd *afd;
|
||||||
int s;
|
int s;
|
||||||
|
|
||||||
for (afd = &afdl[0]; afd->a_af; afd++) {
|
for (afd = &afdl[0]; afd->a_af; afd++) {
|
||||||
|
@ -533,7 +533,7 @@ getaddrinfo(hostname, servname, hints, res)
|
||||||
static int
|
static int
|
||||||
get_name(addr, afd, res, numaddr, pai, port0)
|
get_name(addr, afd, res, numaddr, pai, port0)
|
||||||
const char *addr;
|
const char *addr;
|
||||||
struct afd *afd;
|
const struct afd *afd;
|
||||||
struct addrinfo **res;
|
struct addrinfo **res;
|
||||||
char *numaddr;
|
char *numaddr;
|
||||||
struct addrinfo *pai;
|
struct addrinfo *pai;
|
||||||
|
@ -588,7 +588,7 @@ get_addr(hostname, af, res, pai, port0)
|
||||||
struct addrinfo sentinel;
|
struct addrinfo sentinel;
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
struct addrinfo *top, *cur;
|
struct addrinfo *top, *cur;
|
||||||
struct afd *afd;
|
const struct afd *afd;
|
||||||
int i, error = 0, h_error;
|
int i, error = 0, h_error;
|
||||||
char *ap;
|
char *ap;
|
||||||
|
|
||||||
|
|
|
@ -368,9 +368,9 @@ bsock_send(argc, argv, sock)
|
||||||
GetOpenFile(sock, fptr);
|
GetOpenFile(sock, fptr);
|
||||||
f = GetWriteFile(fptr);
|
f = GetWriteFile(fptr);
|
||||||
fd = fileno(f);
|
fd = fileno(f);
|
||||||
retry:
|
|
||||||
rb_thread_fd_writable(fd);
|
rb_thread_fd_writable(fd);
|
||||||
StringValue(mesg);
|
StringValue(mesg);
|
||||||
|
retry:
|
||||||
if (!NIL_P(to)) {
|
if (!NIL_P(to)) {
|
||||||
StringValue(to);
|
StringValue(to);
|
||||||
n = sendto(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
|
n = sendto(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
|
||||||
|
@ -380,9 +380,7 @@ bsock_send(argc, argv, sock)
|
||||||
n = send(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags));
|
n = send(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags));
|
||||||
}
|
}
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
switch (errno) {
|
if (rb_io_wait_writable(fd)) {
|
||||||
case EINTR:
|
|
||||||
rb_thread_schedule();
|
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
rb_sys_fail("send(2)");
|
rb_sys_fail("send(2)");
|
||||||
|
@ -438,9 +436,7 @@ s_recvfrom(sock, argc, argv, from)
|
||||||
TRAP_END;
|
TRAP_END;
|
||||||
|
|
||||||
if (slen < 0) {
|
if (slen < 0) {
|
||||||
switch (errno) {
|
if (rb_io_wait_readable(fd)) {
|
||||||
case EINTR:
|
|
||||||
rb_thread_schedule();
|
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
rb_sys_fail("recvfrom(2)");
|
rb_sys_fail("recvfrom(2)");
|
||||||
|
@ -1166,8 +1162,9 @@ s_accept(klass, fd, sockaddr, len)
|
||||||
rb_gc();
|
rb_gc();
|
||||||
retry = 1;
|
retry = 1;
|
||||||
goto retry;
|
goto retry;
|
||||||
case EINTR:
|
default:
|
||||||
rb_thread_schedule();
|
if (!rb_io_wait_readable(fd)) break;
|
||||||
|
retry = 0;
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
|
@ -1431,9 +1428,7 @@ udp_send(argc, argv, sock)
|
||||||
freeaddrinfo(res0);
|
freeaddrinfo(res0);
|
||||||
return INT2FIX(n);
|
return INT2FIX(n);
|
||||||
}
|
}
|
||||||
switch (errno) {
|
if (rb_io_wait_writable(fileno(f))) {
|
||||||
case EINTR:
|
|
||||||
rb_thread_schedule();
|
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
105
io.c
105
io.c
|
@ -250,24 +250,60 @@ io_fflush(f, fptr)
|
||||||
fptr->mode &= ~FMODE_WBUF;
|
fptr->mode &= ~FMODE_WBUF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
rb_io_wait_readable(f)
|
rb_io_wait_readable(f)
|
||||||
int f;
|
int f;
|
||||||
{
|
{
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
FD_ZERO(&rfds);
|
|
||||||
FD_SET(f, &rfds);
|
switch (errno) {
|
||||||
rb_thread_select(f + 1, &rfds, NULL, NULL, NULL);
|
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)
|
rb_io_wait_writable(f)
|
||||||
int f;
|
int f;
|
||||||
{
|
{
|
||||||
fd_set wfds;
|
fd_set wfds;
|
||||||
FD_ZERO(&wfds);
|
|
||||||
FD_SET(f, &wfds);
|
switch (errno) {
|
||||||
rb_thread_select(f + 1, NULL, &wfds, NULL, NULL);
|
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 */
|
/* writing functions */
|
||||||
|
@ -308,20 +344,9 @@ io_write(io, str)
|
||||||
ptr += r;
|
ptr += r;
|
||||||
n -= r;
|
n -= r;
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
switch (errno) {
|
if (rb_io_wait_writable(fileno(f))) {
|
||||||
case EINTR:
|
|
||||||
#if defined(ERESTART)
|
|
||||||
case ERESTART:
|
|
||||||
#endif
|
|
||||||
clearerr(f);
|
clearerr(f);
|
||||||
continue;
|
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);
|
rb_sys_fail(fptr->path);
|
||||||
}
|
}
|
||||||
|
@ -571,31 +596,6 @@ rb_io_to_io(io)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reading functions */
|
/* 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
|
long
|
||||||
rb_io_fread(ptr, len, f)
|
rb_io_fread(ptr, len, f)
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
@ -636,6 +636,9 @@ rb_io_fread(ptr, len, f)
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case EINTR:
|
case EINTR:
|
||||||
|
#if defined(ERESTART)
|
||||||
|
case ERESTART:
|
||||||
|
#endif
|
||||||
clearerr(f);
|
clearerr(f);
|
||||||
continue;
|
continue;
|
||||||
case EAGAIN:
|
case EAGAIN:
|
||||||
|
@ -820,7 +823,9 @@ appendline(fptr, delim, strp)
|
||||||
TRAP_END;
|
TRAP_END;
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
io_read_retryable(f, fptr->path);
|
if (!rb_io_wait_readable(fileno(f)))
|
||||||
|
rb_sys_fail(fptr->path);
|
||||||
|
clearerr(f);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
|
@ -1133,7 +1138,9 @@ rb_io_each_byte(io)
|
||||||
TRAP_END;
|
TRAP_END;
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
io_read_retryable(f, fptr->path);
|
if (!rb_io_wait_readable(fileno(f)))
|
||||||
|
rb_sys_fail(fptr->path);
|
||||||
|
clearerr(f);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1164,7 +1171,9 @@ rb_io_getc(io)
|
||||||
|
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
if (ferror(f)) {
|
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;
|
goto retry;
|
||||||
}
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
|
2
rubyio.h
2
rubyio.h
|
@ -64,6 +64,8 @@ void rb_io_check_readable _((OpenFile*));
|
||||||
void rb_io_fptr_finalize _((OpenFile*));
|
void rb_io_fptr_finalize _((OpenFile*));
|
||||||
void rb_io_synchronized _((OpenFile*));
|
void rb_io_synchronized _((OpenFile*));
|
||||||
void rb_io_check_closed _((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));
|
VALUE rb_io_taint_check _((VALUE));
|
||||||
void rb_eof_error _((void));
|
void rb_eof_error _((void));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue