| 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 |
root |
1.2 |
Event->io (fd => $LISTEN, poll => 'r', data => cf::WF_AUTOCANCEL, cb => sub { |
| 22 |
root |
1.1 |
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 |
|
|
}); |