… | |
… | |
8 | use IO::Socket::INET; |
8 | use IO::Socket::INET; |
9 | |
9 | |
10 | our $LISTEN = new IO::Socket::INET |
10 | our $LISTEN = new IO::Socket::INET |
11 | LocalPort => cf::settings->csport, |
11 | LocalPort => cf::settings->csport, |
12 | Listen => 1, |
12 | Listen => 1, |
|
|
13 | Blocking => 0, |
13 | ReuseAddr => 1; |
14 | ReuseAddr => 1; |
14 | |
15 | |
15 | if (!$LISTEN) { |
16 | if (!$LISTEN) { |
16 | # extension yes, completely stupid, not yet |
17 | # extension yes, completely stupid, not yet |
17 | warn "unable to establish listen sockect, exiting.\n"; |
18 | warn "unable to establish listen socket, exiting.\n"; |
18 | exit (2); |
19 | exit (2); |
19 | } |
20 | } |
20 | |
21 | |
21 | Event->io (fd => $LISTEN, nice => 1, poll => 'r', data => cf::WF_AUTOCANCEL, cb => sub { |
22 | our $LISTENER = EV::io $LISTEN, EV::READ, sub { |
22 | my ($fh, $peername) = $LISTEN->accept |
23 | my ($fh, $peername) = $LISTEN->accept |
23 | or return; |
24 | or return; |
24 | |
25 | |
25 | my $fd = fileno $fh; |
26 | my $fd = fileno $fh; |
26 | my $host = inet_ntoa +(sockaddr_in $peername)[1]; |
27 | my $host = inet_ntoa +(sockaddr_in $peername)[1]; |
27 | |
28 | |
28 | warn "new connection from $host\n"; |
29 | warn "new connection from $host\n"; |
29 | |
30 | |
30 | cf::client::create $fd, $host; |
31 | cf::client::create $fd, $host; |
31 | }); |
32 | }; |
|
|
33 | |