ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/tcp.ext
Revision: 1.7
Committed: Tue Mar 6 21:19:10 2007 UTC (17 years, 2 months ago) by root
Branch: MAIN
CVS Tags: rel-2_2, rel-2_3, rel-2_1
Changes since 1.6: +1 -1 lines
Log Message:
*** empty log message ***

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 root 1.5 Blocking => 0, # bugfix workaround for Event calling handler twice :(
14 root 1.1 ReuseAddr => 1;
15    
16     if (!$LISTEN) {
17     # extension yes, completely stupid, not yet
18 root 1.7 warn "unable to establish listen socket, exiting.\n";
19 root 1.1 exit (2);
20     }
21    
22 root 1.6 Event->io (
23     reentrant => 0,
24     fd => $LISTEN,
25     nice => 1,
26     poll => 'r',
27     data => cf::WF_AUTOCANCEL,
28     cb => sub {
29     my ($fh, $peername) = $LISTEN->accept
30     or return;
31 root 1.1
32 root 1.6 my $fd = fileno $fh;
33     my $host = inet_ntoa +(sockaddr_in $peername)[1];
34 root 1.1
35 root 1.6 warn "new connection from $host\n";
36    
37     cf::client::create $fd, $host;
38     },
39     );
40 root 1.1