in reply to Re: Attempt to free unreferenced scalar...
in thread Attempt to free unreferenced scalar...

I hope You're still tracking this thread, because i've got real big problem with this program after "patching" it...

Below is the changed fragment (old code is commented), and the problem is that it seems it's not multithreaded! I watched `ps fauxw` and during heavy load, while old version was runnig there were from 3 to 8 processes in beautiful tree, now it seems it has 1 child only at a time... Related problem is that during heavy load like this i get "connetcion refused" on clients...

Is there something wrong in this code? Maybe i just misunderstood Your "patching instructions"

Please Help!

my $dbh = DBI->connect("DBI:mysql:database=qmail;host=localhost", "qmail", $pass, {'RaiseError' => 1}); logmsg "server started on port $port"; my $waitedpid = 0; my $paddr; sub REAPER { #!!!!!!!!!!!!v $waitedpid = wait; $SIG{CHLD} = \&REAPER; # loathe sysV #logmsg "reaped $waitedpid" . ($? ? " with exit $?" : ''); } $SIG{CHLD} = \&REAPER; #!!!!!!!!!!!!!!^ for ( $waitedpid = 0; ($paddr = accept(Client,Server)) || $waitedpid; $waitedpid = 0, close Client) { next if $waitedpid and not $paddr; my($port,$iaddr) = sockaddr_in($paddr); my $name = gethostbyaddr($iaddr,AF_INET); logmsg "connection from $name [", inet_ntoa($iaddr), "] at port $port"; #do { # $kid = waitpid(-1,&WNOHANG); # } until $kid == -1; spawn sub { my $line = <STDIN>; chomp $line; my @param = split (/ /,$line);
-- Daniellek

Replies are listed 'Best First'.
Re: Attempt to free unreferenced scalar...
by Dominus (Parson) on Dec 15, 2000 at 19:48 UTC
    I can't understand what code is supposed to be in your program and what isn't. Please post the actual code that you are using that has a problem.
      Sorry, i was in little hurry...

      Here's this fragment clear.

      my $dbh = DBI->connect("DBI:mysql:database=qmail;host=localhost", "qmail", $pass, {'RaiseError' => 1}); logmsg "server started on port $port"; my $waitedpid = 0; my $paddr; for ( $waitedpid = 0; ($paddr = accept(Client,Server)) || $waitedpid; $waitedpid = 0, close Client) { next if $waitedpid and not $paddr; my($port,$iaddr) = sockaddr_in($paddr); my $name = gethostbyaddr($iaddr,AF_INET); logmsg "connection from $name [", inet_ntoa($iaddr), "] at port $port"; do { $kid = waitpid(-1,&WNOHANG); } until $kid == -1; spawn sub { my $line = <STDIN>; chomp $line; my @param = split (/ /,$line);
      -- Daniellek
        I notice that you didn't define &WNOHANG anywhere. To get WNOHANG, you have to say use POSIX ':sys_wait_h', but neither of the samples you posted do this.