From: nobu.nokada@... Date: 2002-04-04T02:34:30+09:00 Subject: Re: TCPSocket::new in ruby 1.7 Hi, At Thu, 4 Apr 2002 01:02:29 +0900, nobu.nokada@softhome.net wrote: > Following patch may fix it? Sorry, I'm so stupid to forget the important thing. --- ext/socket/socket.c~ Thu Apr 4 01:01:50 2002 +++ ext/socket/socket.c Thu Apr 4 02:31:55 2002 @@ -854,4 +854,5 @@ struct inetsock_arg } remote, local; int type; + int fd; }; @@ -868,4 +869,11 @@ inetsock_freeaddrinfo(arg) arg->local.res = 0; } + if (arg->fd >= 0) { +#if defined(HAVE_CLOSESOCKET) + closesocket(arg->fd); +#else + close(arg->fd); +#endif + } return Qnil; } @@ -891,5 +899,5 @@ init_inetsock_internal(arg) } - fd = -1; + arg->fd = fd = -1; for (res = arg->remote.res; res; res = res->ai_next) { status = ruby_socket(res->ai_family,res->ai_socktype,res->ai_protocol); @@ -899,4 +907,5 @@ init_inetsock_internal(arg) continue; } + arg->fd = fd; if (type == INET_SERVER) { #ifndef NT @@ -922,4 +931,5 @@ init_inetsock_internal(arg) if (status < 0) { + arg->fd = -1; #if defined(HAVE_CLOSESOCKET) closesocket(fd); @@ -933,13 +943,9 @@ init_inetsock_internal(arg) } if (status < 0) { - if (fd >= 0) -#if defined(HAVE_CLOSESOCKET) - closesocket(fd); -#else - close(fd); -#endif rb_sys_fail(syscall); } + arg->fd = -1; + if (type == INET_SERVER) listen(fd, 5); @@ -963,4 +969,5 @@ init_inetsock(sock, remote_host, remote_ arg.local.res = 0; arg.type = type; + arg.fd = -1; return rb_ensure(init_inetsock_internal, (VALUE)&arg, inetsock_freeaddrinfo, (VALUE)&arg); -- Nobu Nakada