… | |
… | |
1016 | listen $state{fh}, $len |
1016 | listen $state{fh}, $len |
1017 | or Carp::croak "listen: $!"; |
1017 | or Carp::croak "listen: $!"; |
1018 | |
1018 | |
1019 | $state{aw} = AE::io $state{fh}, 0, sub { |
1019 | $state{aw} = AE::io $state{fh}, 0, sub { |
1020 | # this closure keeps $state alive |
1020 | # this closure keeps $state alive |
1021 | while (my $peer = accept my $fh, $state{fh}) { |
1021 | while ($state{fh} && (my $peer = accept my $fh, $state{fh})) { |
1022 | fh_nonblocking $fh, 1; # POSIX requires inheritance, the outside world does not |
1022 | fh_nonblocking $fh, 1; # POSIX requires inheritance, the outside world does not |
1023 | |
1023 | |
1024 | my ($service, $host) = unpack_sockaddr $peer; |
1024 | my ($service, $host) = unpack_sockaddr $peer; |
1025 | $accept->($fh, format_address $host, $service); |
1025 | $accept->($fh, format_address $host, $service); |
1026 | } |
1026 | } |