in reply to Re^3: yet another thread question: is Symbol::gensym threadsafe?
in thread yet another thread question: is Symbol::gensym threadsafe?
and, although the loop doesn't seem to be necessary:sub receive { my $self = shift; # Perl OO mantra + ... return undef unless ref $self; # .. continued unless (@_) { $self->{ERROR}->set(ILL_NUM); return 0; } my $sock = shift; local $/ = undef; unless (defined $sock->recv($self->{COMMAND}, $self->{COMMANDSIZE}) + && defined $sock->recv($self->{CONTENT_LENGTH}, $self->{CONTEN +TSIZE})) { $self->{ERROR}->set(SOCK_RECV); return 0; } my $cont = ''; $self->{CONTENT} = ''; while (length $self->{CONTENT} < $self->{CONTENT_LENGTH}) { unless (defined $sock->recv($cont, $self->{CONTENT_LENGTH})) { $self->{ERROR}->set(SOCK_RECV); return 0; } $self->{CONTENT} .= $cont; $cont = ''; } 1; }
i'm quite sure that this will fix the problem, and once again you nearly saved my life. :)sub send { my $self = shift; return undef unless ref $self; my $sock = shift || $self{ERROR}->set(ILL_NUM); return 0 if $self->error->get; $self->{CONTENT_LENGTH} = length $self->{CONTENT}; my $str = sprintf("%$self->{CODESIZE}s", $self->{CODE}) . sprintf("%$self->{CONTENTSIZE}d", $self->{CONTENT_LENGTH} +) . $self->{CONTENT}; my $length = length $str; local $\ = undef; my ($sent, $tsend) = (0, 0); while ($sent < $length) { unless ($tsent = $sock->send($str)) { $self->error->set(SOCK_SEND, $!); return 0; } $sent += $tsent; $tsent = 0; } 1; }
|
|---|