* 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:
nobu 2002-10-02 14:13:58 +00:00
parent ab6b478615
commit 71c41cf5a5
5 changed files with 90 additions and 66 deletions

View file

@ -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;
@ -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 */
@ -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++) {
@ -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;
@ -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;

View file

@ -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),
@ -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)");
@ -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)");
@ -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);
@ -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;
}
}