Index: [Article Count Order] [Thread]

Date:  Fri, 5 Apr 2002 00:32:39 -0800 (PST)
From:  mmm <mmcdanie@fourthcrusade.com>
Subject:  [webricken:88] Re: ai_family not supported (SocketError)
To:  <webricken@notwork.org>
Message-Id:  <Pine.LNX.4.33.0204050019360.21171-100000@fangora.fourthcrusade.com>
In-Reply-To:  <15533.1065.500057.763439@io.com>
X-Mail-Count: 00088

On Thu, 4 Apr 2002, Jim Menard wrote:

> Date: Thu, 4 Apr 2002 19:55:53 -0600
> From: Jim Menard <jimm@io.com>
> Reply-To: webricken@notwork.org
> To: webricken@notwork.org
> Subject: [webricken:86] Re: ai_family not supported (SocketError)
>
> Brad Cox writes:
> > I just joined this list. Sorry if this is a faq.
> >
> > On running the HelloWorld example on linux 7.0 + apache latest, I get
> > this error. Same results with eruby.
> >
> > Any suggestions?
>
> It is a FAQ. I asked it, too. Here's the answer I received from gotoyuzo:
>
> > Sorry. Listening socket is not required for this test.
> > Please try the following patch.
> >
> > --- TestWEBrickHTTPServer.rb~   Tue Feb  5 20:33:11 2002
> > +++ TestWEBrickHTTPServer.rb    Tue Feb  5 06:44:18 2002
> > @@ -8,14 +8,8 @@
> >    include WEBrick
> >
> >    def setup
> > -    (2000..3000).each{|port|
> > -      begin
> > -        logger = Log.new(nil, Log::FATAL)
> > -        @svr = HTTPServer.new(:Logger=>logger, :Port=>port)
> > -        break
> > -      rescue Errno::EACCES, Errno::EADDRINUSE
> > -      end
> > -    }
> > +    logger = Log.new(nil, Log::FATAL)
> > +    @svr = HTTPServer.new(:Logger=>logger, :ListenImmediately => false)
> >    end
> >
> > Socket::getaddrinfo may cause problem on some Linux box.
> > See also http://www.ruby-talk.com/28598.
> >
> > --
> > gotoyuzo
>
> I also needed to set the :BindAddress address to '0.0.0.0' when starting
> the server. Here's my httpd.rb:
>
>     require 'webrick'
>     require 'getopts'
>
>     DEFAULT_DOCROOT_DIR = File.join(File.dirname($0), 'src')
>
>     getopts nil, 'r:'
>
>     s=WEBrick::HTTPServer.new(
>       :BindAddress    => '0.0.0.0',
>       :Port           => 2000,
>       :Logger         => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG),
>       :DocumentRoot   => $OPT_R || DEFAULT_DOCROOT_DIR
>     )
>     trap("INT"){ s.shutdown }
>     s.start
>
> Jim
> --
> Jim Menard, jimm@io.com, http://www.io.com/~jimm/
> "Any sufficiently complicated C or Fortran program contains an ad hoc
> informally-specified bug-ridden slow implementation of half of Common Lisp."
>     -- Greenspun's Tenth Rule of Programming
>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I also had this problem.  After some searching, I discovered that
the getaddrinfo() call in the 'def listen' in file server.rb is trying to
return IPV6 information (in addition to IPV4) due to the address family
being AF_UNSPEC.  On some systems (my SuSE release 7.3 being one) this
causes a problem when attempting to retrieve information.
Changing the Socket::AF_UNSPEC to Socket::AF_INET fixed the problem.  The
family type AF_INET forces only IPV4 information to be returned in the
socket address structure.  Presumably this isn't going to break anything
regarding dropping the IPV6 information (since IPV6 info. obviously
couldn't be properly used when it _was_ being returned in the socket
address structure).

Anyway, that's what I understood from my research, and that's how I fixed
the problem on my system, and then the httpsd.rb server worked just fine,
and all the webrick sample programs worked fine after the change, also.

Michael McDaniel