2 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
3 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
8 use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
9 require PublicInbox::NNTP;
10 require PublicInbox::NewsGroup;
11 my $nntpd = PublicInbox::NNTPD->new;
12 my $refresh = sub { $nntpd->refresh_groups };
15 LocalAddr => '127.0.0.1:1133',
22 my $s = IO::Socket::INET->new(%opts) or die "Error creating socket: $@\n";
23 $s->sockopt(SO_KEEPALIVE, 1);
24 $s->setsockopt(IPPROTO_TCP, TCP_NODELAY, 1);
26 $SIG{PIPE} = 'IGNORE';
30 Danga::Socket->AddOtherFds(fileno($s) => sub {
31 while (my $c = $s->accept) {
32 $c->blocking(0); # no accept4 :<
33 PublicInbox::NNTP->new($c, $nntpd);
36 Danga::Socket->EventLoop();
38 package PublicInbox::NNTPD;
41 use fields qw(groups err out);
45 my $self = fields::new($class);
52 require PublicInbox::Config;
53 my $pi_config = PublicInbox::Config->new;
55 foreach my $k (keys %$pi_config) {
56 $k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
58 my $git_dir = $pi_config->{$k};
59 my $address = $pi_config->{"publicinbox.$g.address"};
60 my $ng = PublicInbox::NewsGroup->new($g, $git_dir, $address);
61 my $old_ng = $self->{groups}->{$g};
63 # Reuse the old one if possible since it can hold references
64 # to valid mm and gcf objects
70 # Only valid if Msgmap works
71 $new->{$g} = $ng if $ng->mm;
73 # this will destroy old groups that got deleted
74 %{$self->{groups}} = %$new;