+
+sub waitfor
+{
+ my $conn = shift;
+ my $msg = shift;
+ $msg =~ s/\cM//g;
+
+ my $buf = $conn->{msg};
+ $buf =~ s/\r/\\r/g;
+ $buf =~ s/\n/\\n/g;
+
+ dbg "state $conn->{state} '$msg' '$buf'" if isdbg('wm7d');
+
+ $conn->{_wm7d} ||= [];
+
+ if ($conn->{state} eq 'waitfor') {
+ if ($msg =~ /utc$/ ) {
+ $conn->send_later("$conn->{target_call}\n");
+ $conn->{state} = 'working';
+ }
+ } elsif ($conn->{state} eq 'working') {
+ if ($conn->{msg} =~ /^\rquery->\s*$/) {
+ $conn->send_later("QUIT\n");
+ $conn->{state} = 'ending';
+ }
+ return if $msg =~ /^query->/;
+ push @{$conn->{_wm7d}}, $msg;
+ } else {
+ return if $msg =~ /^query->/ || $msg =~ /bye/;
+# $conn->handle_raw($msg);
+ push @{$conn->{_wm7d}}, $msg;
+ }
+}
+
+sub on_disc
+{
+ my $conn = shift;
+ my $dxchan = shift;
+ $DB::single = 1;
+
+ $dxchan->send(map {"$conn->{prefix}$_"} @{$conn->{_wm7d}});
+}