… | |
… | |
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 sockect, 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 | |
|
|
31 | # HACK to avoid blocking on common files on log-in. |
|
|
32 | # remove once async |
|
|
33 | cf::async {#d# |
|
|
34 | warn "HACK ext/tcp.ext: $cf::CONFDIR/$_\n" and Coro::AIO::aio_load "$cf::CONFDIR/$_", my $dummy for qw(rules news motd);#d# |
|
|
35 | warn "HACK ext/tcp.ext: $cf::LOCALDIR/crossfiremail\n" and Coro::AIO::aio_load "$cf::LOCALDIR/crossfiremail", my $dummy;#d# |
37 | cf::client::create $fd, $host; |
36 | cf::client::create $fd, $host; |
38 | }, |
37 | undef $fh;#d# |
39 | ); |
38 | };#d#d |
|
|
39 | }; |
40 | |
40 | |