Process input directly after receipt.
Do the most common case of input processing first!
Don't autoflush things like debug files automatically but do it
in periodic processing every second (for now).
if (defined $msg) {
push @{$self->{inqueue}}, $msg;
}
+ $self->process_one;
}
# obtain a channel object by callsign [$obj = DXChannel::get($call)]
# handle A records
my $user = $self->user;
- if ($sort eq 'A' || $sort eq 'O') {
- $self->start($line, $sort);
- } elsif ($sort eq 'I') {
- die "\$user not defined for $call" if !defined $user;
+ if ($sort eq 'I') {
+ die "\$user not defined for $call" unless defined $user;
# normal input
$self->normal($line);
+ } elsif ($sort eq 'G') {
+ $self->enhanced($line);
+ } elsif ($sort eq 'A' || $sort eq 'O') {
+ $self->start($line, $sort);
} elsif ($sort eq 'Z') {
$self->disconnect;
} elsif ($sort eq 'D') {
; # ignored (an echo)
- } elsif ($sort eq 'G') {
- $self->enhanced($line);
} else {
- dbg atime . " Unknown command letter ($sort) received from $call\n";
+ dbg atime . " DXChannel::process_one: Unknown command letter ($sort) received from $call\n";
}
}
}
sub process
{
- foreach my $dxchan (get_all()) {
+ foreach my $dxchan (values %channels) {
next if $dxchan->{disconnecting};
$dxchan->process_one;
}
$self->{ann_talk} = $user->wantann_talk;
$self->{here} = 1;
$self->{prompt} = $user->prompt if $user->prompt;
+ $self->{lastmsgpoll} = 0;
# sort out new dx spot stuff
$user->wantdxcq(0) unless defined $user->{wantdxcq};
my $dxchan;
foreach $dxchan (@dxchan) {
- next if $dxchan->{sort} ne 'U';
+ next unless $dxchan->{sort} eq 'U';
# send a outstanding message prompt if required
if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
use DXUtil;
use DXLog ();
use Carp ();
+use POSIX qw(isatty);
%dbglevel = ();
$fp = undef;
$keepdays = 10;
$cleandays = 100;
+our $no_stdout; # set if not running in a terminal
+
# Avoid generating "subroutine redefined" warnings with the following
# hack (from CGI::Carp):
if (!defined $DB::VERSION) {
my @l = split /\n/, $r;
for (@l) {
s/([\x00-\x08\x0B-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
- print "$_\n" if defined \*STDOUT;
+ print "$_\n" if defined \*STDOUT && !$no_stdout;
my $str = "$t^$_";
&$callback($str) if $callback;
$fp->writeunix($t, $str);
$callback = shift;
# add sig{__DIE__} handling
- if (!defined $DB::VERSION) {
+ unless (defined $DB::VERSION) {
$SIG{__WARN__} = sub {
if ($_[0] =~ /Deep\s+recursion/i) {
dbg($@);
};
$SIG{__DIE__} = sub { dbg($@); dbg(Carp::longmess(@_)); };
+
+ # switch off STDOUT printing if we are not talking to a TTY
+ unless ($^O =~ /^MS/ || $^O =~ /^OS-2/) {
+ unless (isatty(STDOUT->fileno)) {
+ ++$no_stdout;
+ }
+ }
}
$fp = DXLog::new('debug', 'dat', 'd');
use vars qw($log);
+our %logobj;
+
$log = new('log', 'dat', 'm');
# create a log object that contains all the useful info needed
# make sure the directory exists
mkdir($ref->{prefix}, 0777) unless -e $ref->{prefix};
- return bless $ref;
+ my $self = bless $ref;
+ $logobj{$self} = $self;
+ return $self;
}
sub _genfn
my $fh = new IO::File $self->{fn}, $mode, 0666;
return undef if !$fh;
- $fh->autoflush(1) if $mode ne 'r'; # make it autoflushing if writable
+ $fh->autoflush(0) if $mode ne 'r'; # make it (not) autoflushing if writable
$self->{fh} = $fh;
# print "opening $self->{fn}\n";
delete $self->{fh};
}
+sub flush_all
+{
+ foreach my $l (values %logobj) {
+ $l->{fh}->flush if exists $l->{fh};
+ }
+}
+
sub DESTROY
{
my $self = shift;
+ delete $logobj{$self};
undef $self->{fh}; # close the filehandle
delete $self->{fh} if $self->{fh};
}
use vars qw($version $build $gitversion);
$version = '1.57';
-$build = '33';
-$gitversion = '4b94818';
+$build = '34';
+$gitversion = '981c165';
1;
$maxconnect_node = 0; # Ditto but for nodes. In either case if a new incoming connection
# takes the no of references in the routing table above these numbers
# then the connection is refused. This only affects INCOMING connections.
-$idle_interval = 0.100; # the wait between invocations of the main idle loop processing.
+$idle_interval = 0.500; # the wait between invocations of the main idle loop processing.
our $ending; # signal that we are ending;
my $timenow = time;
BPQMsg::process();
- DXChannel::process();
+# DXChannel::process();
# $DB::trace = 0;
AGWMsg::process();
Timer::handler();
-
+ DXLog::flush_all();
}
if (defined &Local::process) {