ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/tcp.ext
Revision: 1.1
Committed: Thu Dec 14 04:31:25 2006 UTC (17 years, 5 months ago) by root
Branch: MAIN
Log Message:
introducing tcp.ext: the tcp/ip connection handler.
we could do local sockets, and consequently have "local users"
again, just as in the old days.

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     # this listens for new tcp connections and hands them over to the server core
4     # wether this being an extension introduces or reduces stability problems
5     # is unknown as of today.
6    
7     use Socket;
8     use IO::Socket::INET;
9    
10     our $LISTEN = new IO::Socket::INET
11     LocalPort => cf::settings->csport,
12     Listen => 1,
13     ReuseAddr => 1;
14    
15     if (!$LISTEN) {
16     # extension yes, completely stupid, not yet
17     warn "unable to establish listen sockect, exiting.\n";
18     exit (2);
19     }
20    
21     Event->io (fd => $LISTEN, poll => 'r', cb => sub {
22     my ($fh, $peername) = $LISTEN->accept
23     or return;
24    
25     my $fd = fileno $fh;
26     my $host = inet_ntoa +(sockaddr_in $peername)[1];
27    
28     warn "new connection from $host\n";
29    
30     cf::add_client_socket $fd, $host;
31     });