--- deliantra/server/ext/tcp.ext 2007/01/21 21:28:27 1.6 +++ deliantra/server/ext/tcp.ext 2010/03/16 20:37:54 1.15 @@ -1,40 +1,26 @@ -#! perl +#! perl # MANDATORY # this listens for new tcp connections and hands them over to the server core # wether this being an extension introduces or reduces stability problems # is unknown as of today. use Socket; -use IO::Socket::INET; +use AnyEvent::Socket; -our $LISTEN = new IO::Socket::INET - LocalPort => cf::settings->csport, - Listen => 1, - Blocking => 0, # bugfix workaround for Event calling handler twice :( - ReuseAddr => 1; - -if (!$LISTEN) { - # extension yes, completely stupid, not yet - warn "unable to establish listen sockect, exiting.\n"; - exit (2); -} +our $BIND = $cf::CFG{bind_addresses} || [[undef, 13327]]; +our @LISTENERS; -Event->io ( - reentrant => 0, - fd => $LISTEN, - nice => 1, - poll => 'r', - data => cf::WF_AUTOCANCEL, - cb => sub { - my ($fh, $peername) = $LISTEN->accept - or return; +for (@$BIND) { + my ($host, $port) = @$_; + warn "listening on ", (format_hostport $host, $port), "\n"; - my $fd = fileno $fh; - my $host = inet_ntoa +(sockaddr_in $peername)[1]; + push @LISTENERS, tcp_server $host, $port, sub { + my ($fh, $host, $port) = @_ + or return; - warn "new connection from $host\n"; + warn "new connection from ", (format_hostport $host, $port), "\n"; - cf::client::create $fd, $host; - }, -); + cf::client::create fileno $fh, $host; + }; +}