--- deliantra/server/ext/tcp.ext 2006/12/21 06:12:35 1.3 +++ deliantra/server/ext/tcp.ext 2010/05/09 21:46:39 1.18 @@ -1,31 +1,30 @@ -#! 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, - 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; + +for (@$BIND) { + my ($host, $port) = @$_; + cf::info "listening on ", (format_hostport $host, $port), "\n"; -Event->io (fd => $LISTEN, poll => 'r', data => cf::WF_AUTOCANCEL, cb => sub { - my ($fh, $peername) = $LISTEN->accept - or return; + push @LISTENERS, tcp_server $host, $port, sub { + my ($fh, $host, $port) = @_ + or return; - my $fd = fileno $fh; - my $host = inet_ntoa +(sockaddr_in $peername)[1]; + my $lhost = AnyEvent::Socket::format_address + +(AnyEvent::Socket::unpack_sockaddr getsockname $fh)[1]; - warn "new connection from $host\n"; + cf::info "new connection from ", (format_hostport $host, $port), "\n" + if $lhost ne $host; # do not log connections from the host, e.g. for watchdogs + + cf::client::create fileno $fh, $host; + }; +} - cf::client::create $fd, $host; -});