[#1094] Re: [ruby-cvs] ruby, ruby/lib: * eval.c (ev_const_defined, ev_const_get), variable.c — Dave Thomas <dave@...>

> * eval.c (rb_mod_autoload, rb_mod_autoload_p): new method;

12 messages 2003/05/29
[#1095] Re: [ruby-cvs] ruby, ruby/lib: * eval.c (ev_const_defined, ev_const_get), variable.c — nobu.nokada@... 2003/05/29

Hi,

Fwd: ping.rb

From: "J.Herre" <jlst@...>
Date: 2003-05-16 01:47:12 UTC
List: ruby-core #1057
On Thursday, May 15, 2003, at 04:48 PM, nobu.nokada@softhome.net wrote:

> Hi,
>
> At Fri, 16 May 2003 01:10:54 +0900,
> Dave Thomas wrote:
>>>> I just tried using the Cygwin code under OSX, and it doesn't seem to
>>>> fix it: I just get EINVAL back 10 times in a row.
>>> Mmmm, how do other programs (telnet, ping ...) handle that
>>> condition?
>>
>> I'm guessing the problem is caused by the socket being opened in
>> nowait mode. I'm trying to find some source that also does that.
>
> Although it's ad hoc, what about treating EINVAL preceded by
> EINPROGRESS as ECONNREFUSED?
>

__MACOSX__ does not seem to be set but __APPLE__ is.

Checking via getsockopt() seems to work. (Depending on how you read the
man page for connect() this may or may not be required.)

Does someone else want to test this and see if it screws up anything 
else?

-J


Index: ext/socket/socket.c
===================================================================
RCS file: /src/ruby/ext/socket/socket.c,v
retrieving revision 1.92
diff -u -r1.92 socket.c
--- ext/socket/socket.c 7 Apr 2003 06:58:31 -0000       1.92
+++ ext/socket/socket.c 16 May 2003 01:16:10 -0000
@@ -733,7 +733,7 @@
  {
      int status;
      int mode;
-#if defined __CYGWIN__
+#if defined __CYGWIN__ || defined __APPLE__
      int wait_in_progress = -1;
  #endif

@@ -752,7 +752,7 @@
  #ifdef SOCKS5
      if (!socks)
  #endif
-    fcntl(fd, F_SETFL, mode|NONBLOCKING);
+      fcntl(fd, F_SETFL, mode|NONBLOCKING);
  #endif /* HAVE_FCNTL */

      for (;;) {
@@ -763,7 +763,21 @@
         else
  #endif
         {
-           status = connect(fd, sockaddr, len);
+#ifdef __APPLE__
+         if (wait_in_progress-- > 0) {
+           int sockerr;
+           int sockerrlen = sizeof(int);
+           status = getsockopt(fd, SOL_SOCKET, SO_ERROR, &sockerr, 
&sockerrlen);
+           if (status == 0 && sockerr) {
+             status = -1;
+             errno = sockerr;
+           }
+         } else {
+           status = connect(fd, sockaddr, len);
+         }
+#else
+         status = connect(fd, sockaddr, len);
+#endif
         }
         if (status < 0) {
             switch (errno) {
@@ -772,6 +786,9 @@
               case EINPROGRESS:
  #ifdef __CYGWIN__
               case EALREADY:
+               wait_in_progress = 10;
+#endif
+#ifdef __APPLE__
                 wait_in_progress = 10;
  #endif
  #endif


In This Thread

Prev Next