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