The problem you are experiencing seems to be intentional. The socket
is set to enable reuse of the address. I think that UNIX ignores this
for all but UDP multicast sockets, Windows appears to honor the
request, for what reason I can not guess. (Is this a Windows bug or a
Ruby bug?) Any idea why this option was set?
Hope this helps,
-- Will
<CODE filename="t.rb">
require 'socket'
p TCPServer.new("localhost", 3333)
p TCPServer.new("localhost", 3333)
</CODE>
[E:/ruby/test] ruby -v
ruby 1.7.1 (2001-09-08) [i586-mswin32]
Before:
[E:/ruby/test] ruby t.rb
#<TCPServer:0x2b89980>
#<TCPServer:0x2b89920>
After:
[E:/ruby/test] ruby t.rb
#<TCPServer:0x2b89980>
t.rb:5:in `new': Unknown Error - "bind(2)" (Errno::E10048)
from t.rb:5
Index: socket.c
===================================================================
RCS file: /src/ruby/ext/socket/socket.c,v
retrieving revision 1.54
diff -w -c -r1.54 socket.c
*** socket.c 2001/09/05 22:18:56 1.54
--- socket.c 2001/09/21 00:39:51
***************
*** 851,858 ****
}
if (type == INET_SERVER) {
! status = 1;
! setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
! (char*)&status, sizeof(status));
status = bind(fd, res->ai_addr, res->ai_addrlen);
syscall = "bind(2)";
}
--- 851,858 ----
}
if (type == INET_SERVER) {
! // status = 1;
! // setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
! // (char*)&status, sizeof(status));
status = bind(fd, res->ai_addr, res->ai_addrlen);
syscall = "bind(2)";
}
Jonathan Entner <jonathan.entner / jhuapl.edu> writes:
> "Hal E. Fulton" wrote:
> > > pigeon% ruby -rsocket -e 'p TCPServer.new("localhost",
> > 3333);TCPServer.new("localhost", 3333)'
> > > #<TCPServer:0x401b3f50>
> > > -e:1:in `new': Address already in use - "bind(2)" (Errno::EADDRINUSE)
> > > from -e:1
> > > pigeon%
> >
> > Maybe it's a Windows issue. Not sure how the networking stuff
> > differs... I think NT is more Unix-like, but I'm using 98 (and
> > 1.6.3 cygwin).
> >
> > In that environment, this one-liner does not give me an error.
>
<... snip>
>
> Jonathan Entner
> jonathan.entner / jhuapl.edu