in reply to Re: thread:shared
in thread thread:shared

zentara,

as I want to exchange results of a program running on several computer
I don't want that the client gets an echo of his own lines. Therefore the ID,
which is added by the Reader
push @chat, "$self->{ID}\t$1";
and removed by the Writer and send if $ID ne $1:
$chat[$i] =~ /(.+?)\s(.+)[\n\r]*/; print $socket $2,$EOL if ( $1 ne $ID && $2 ne $kill);
So the Writer skips the lines with its ID, ok? But this is easy to change!!

The occurence of the warning of the line 120:

%E = (map { $1 => $2; /(.+):(.+)/; } (split /;/, $Elm));
is something that I don't understand!!
This initial warning disappeares if you either remove
/(.+):(.+)/;
or
$1 => $2;
or if you have a seperate function for those two:
sub _split { /(.+):(.+)/; return ($1 => $2) if ($1); }
so that the line 120 looks like
%E = (map { _split($_) } (split /;/, $Elm));


Finally I have to tell you that there is a really, really stupid bug, after the loop of the Writer. This code

$Elm =''; # to rewrite $E foreach ( split /;/, $Elm ) { $Elm .= "$_;" unless ( $_ =~ /^$ID\:/); } cond_broadcast($Elm);
has to be changed into:
my $tmp = ''; foreach ( split /;/, $Elm ) { $tmp .= "$_;" if ( $_ !~ /^$ID\:/ && $_ =~/:/); } $Elm = $tmp; cond_broadcast($Elm);
I think, now everything is ok,
'it can be braodcasted'
Carl

Replies are listed 'Best First'.
Re: Re: Re: thread:shared
by zentara (Cardinal) on Dec 17, 2003 at 17:15 UTC
    Yeah, I figured out that "no-echo-to-self" part myself, but even with your bug fix, there is no echo, at least on my machine. Linux with Perl5.8.0. Are you using a later Perl version, I know some of Liz's modules require 5.81. I still only get newlines echoed around. As a first guess, I'm thinking it has something to do with your extensive use of $1 and $2, and maybe they are "going out of scope"? I feel confident that I can narrow it down, since I can trace the newlines.

    The bigger problem, which I see, is the way the server crashes when you close all clients, then restart them, and try to print something from client 1. It only affects client1.

    I have found a fix for this, but it was just by my "intuitive guessing", so I can't say what overall effect it will have. But.......if you don't detach the reader and writer threads, the crash problem goes away.(as far as my limited testing has shown). So comment out:

    # $r->detach(); # $w->detach();

    Maybe that will help your problem. Thanks again for the code. This is the first threaded-chat code I could find.