nobu.nokada / softhome.net wrote:
> Hi,
> 
> At Thu, 15 May 2003 12:26:57 +0900,
> Dave Thomas wrote:
> 
>>Yes - but 'connection refused' should generate ECONNREFUSED, which is
>>handled specially inside ping.rb. Instead it seems to be generating
>>EINVAL.
> 
> 
> Agree, but I don't have Mac OS X box.  Can't you get strace
> log?
> 

Here's the appropriate section of the ktrace:

ktrace ruby -r socket -e "TCPSocket.new('localhost', 'echo')"

  15037 ruby     CALL  socket(0x1e,0x1,0x6)
  15037 ruby     RET   socket 11/0xb
  15037 ruby     CALL  fcntl(0xb,0x3,0)
  15037 ruby     RET   fcntl 2
  15037 ruby     CALL  fcntl(0xb,0x4,0x6)
  15037 ruby     RET   fcntl 0
  15037 ruby     CALL  connect(0xb,0x222960,0x1c)
  15037 ruby     RET   connect -1 errno 36 Operation now in progress
  15037 ruby     CALL  select(0xc,0,0xbfffd2b0,0,0)
  15037 ruby     RET   select 1
  15037 ruby     CALL  connect(0xb,0x222960,0x1c)
  15037 ruby     RET   connect -1 errno 22 Invalid argument
  15078 ruby     CALL  connect(0xb,0x2229e0,0x10)
  15078 ruby     RET   connect -1 errno 36 Operation now in progress
  15078 ruby     CALL  select(0xc,0,0xbfffd2b0,0,0)
  15078 ruby     RET   select 1
  15078 ruby     CALL  connect(0xb,0x2229e0,0x10)
  15078 ruby     RET   connect -1 errno 22 Invalid argument
  15078 ruby     CALL  fcntl(0xb,0x4,0x2)
  15078 ruby     RET   fcntl 0
  15078 ruby     CALL  close(0xb)

I'm guessing it tries an IPv6 connect, fails, then tries IPv4 and fails 
again.



If I do the same, but connect to 'ftp' (which does have a listener), 
then the trace looks like:

  15082 ruby     CALL  socket(0x1e,0x1,0x6)
  15082 ruby     RET   socket 11/0xb
  15082 ruby     CALL  fcntl(0xb,0x3,0)
  15082 ruby     RET   fcntl 2
  15082 ruby     CALL  fcntl(0xb,0x4,0x6)
  15082 ruby     RET   fcntl 0
  15082 ruby     CALL  connect(0xb,0x222960,0x1c)
  15082 ruby     RET   connect -1 errno 36 Operation now in progress
  15082 ruby     CALL  select(0xc,0,0xbfffd2b0,0,0)
  15082 ruby     RET   select 1
  15082 ruby     CALL  connect(0xb,0x222960,0x1c)
  15082 ruby     RET   connect -1 errno 22 Invalid argument
  15082 ruby     CALL  fcntl(0xb,0x4,0x2)
  15082 ruby     RET   fcntl 0
  15082 ruby     CALL  close(0xb)
  15082 ruby     RET   close 0
  15082 ruby     CALL  socket(0x2,0x1,0x6)
  15082 ruby     RET   socket 11/0xb
  15082 ruby     CALL  fcntl(0xb,0x3,0)
  15082 ruby     RET   fcntl 2
  15082 ruby     CALL  fcntl(0xb,0x4,0x6)
  15082 ruby     CALL  fcntl(0xb,0x3,0)
  15082 ruby     RET   fcntl 2
  15082 ruby     CALL  fcntl(0xb,0x4,0x6)
  15082 ruby     RET   fcntl 0
  15082 ruby     CALL  connect(0xb,0x2229e0,0x10)
  15082 ruby     RET   connect -1 errno 36 Operation now in progress
  15082 ruby     CALL  select(0xc,0,0xbfffd2b0,0,0)
  15082 ruby     RET   select 1
  15082 ruby     CALL  connect(0xb,0x2229e0,0x10)
  15082 ruby     RET   connect -1 errno 56 Socket is already connected
  15082 ruby     CALL  fcntl(0xb,0x4,0x2)
  15082 ruby     RET   fcntl 0
  15082 ruby     CALL  getrlimit(0x8,0xbfffd270)
  15082 ruby     RET   getrlimit 0
  15082 ruby     CALL  fcntl(0xb,0x3,0)
  15082 ruby     RET   fcntl 2
  15082 ruby     CALL  fcntl(0xb,0x3,0)
  15082 ruby     RET   fcntl 2
  15082 ruby     CALL  close(0xb)
  15082 ruby     RET   close 0
  15082 ruby     CALL  close(0xb)
  15082 ruby     RET   close -1 errno 9 Bad file descriptor
  15082 ruby     CALL  exit(0)



Not knowing anything about socket programming, I'm wondering if the 
error 56 is expected in these circumstances. I'm also slightly surprised 
by the double close of FD11 at the end.


Cheers


Dave