@stdoutq = (); # the queue of stuff to send out to the user
$conn = 0; # the connection object for the cluster
$lastbit = ""; # the last bit of an incomplete input line
-$nl = "\r";
# cease communications
sub cease
cease(1);
}
+sub setmode
+{
+ if ($mode == 1) {
+ $nl = "\r";
+ } else {
+ $nl = "\n";
+ }
+ $/ = $nl;
+ if ($mode == 0) {
+ $\ = undef;
+ } else {
+ $\ = $nl;
+ }
+}
+
# handle incoming messages
sub rec_socket
{
cease(1);
}
if (defined $msg) {
- my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)|(.*)$/;
+ my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
if ($sort eq 'D') {
$nl = "" if $mode == 0;
- $line =~ s/\n/\r/o if $mode == 1;
- print $line, $nl;
+ $line =~ s/\n/\r/og if $mode == 1;
+ print $line;
} elsif ($sort eq 'M') {
$mode = $line; # set new mode from cluster
- } elsif ($sort eq 'Z') { # end, disconnect, go, away .....
+ setmode();
+ } elsif ($sort eq 'Z') { # end, disconnect, go, away .....
cease(0);
}
}
# print "sys: $r $buf";
if ($r > 0) {
if ($mode) {
- $buf =~ s/\r/\n/o if $mode == 1;
+ $buf =~ s/\r/\n/og if $mode == 1;
$dangle = !($buf =~ /\n$/);
@lines = split /\n/, $buf;
if ($dangle) { # pull off any dangly bits
$call = uc $ARGV[0];
die "client.pl <call> [<mode>]\r\n" if (!$call);
$mode = $ARGV[1] if (@ARGV > 1);
+setmode();
-if ($mode != 1) {
- $nl = "\n";
- $\ = $nl;
-}
-select STDOUT; $| = 1;
+#select STDOUT; $| = 1;
+STDOUT->autoflush(1);
$SIG{'INT'} = \&sig_term;
$SIG{'TERM'} = \&sig_term;
-#$SIG{'HUP'} = \&sig_term;
+$SIG{'HUP'} = \&sig_term;
$conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
$conn->send_now("A$call|start");