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 |
Blocking => 0, # bugfix workaround for Event calling handler twice :( |
14 |
ReuseAddr => 1; |
15 |
|
16 |
if (!$LISTEN) { |
17 |
# extension yes, completely stupid, not yet |
18 |
warn "unable to establish listen socket, exiting.\n"; |
19 |
exit (2); |
20 |
} |
21 |
|
22 |
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 |
|
32 |
my $fd = fileno $fh; |
33 |
my $host = inet_ntoa +(sockaddr_in $peername)[1]; |
34 |
|
35 |
warn "new connection from $host\n"; |
36 |
|
37 |
cf::client::create $fd, $host; |
38 |
}, |
39 |
); |
40 |
|