View Review Details


Book:   Advanced Perl Programming
Subject:   Advanced Perl Programming Review
Date:   2001-10-02 16:48:20
From:   Anonymous Coward
Rating:  StarStarStarStarStar

Watch out for the Networking: Implementing RPC chapter! There are myriad errors in the code examples. Why doesn't someone review the code, and perhaps actually try to run it?


For example:


The peer demonstration (between two RPC servers) just won't work. Besides the fact that the code has a typo (new_rpc_server instead of new_server, mentioned in the errata), they each create a listening socket, supposedly to each opposite machine. That *won't* work. Even if they created a listening socket on their respective hosts, they wouldn't know who to contact for the TCP connection. The lower-level Msg library doesn't facilitate a server sending messages to some arbitrary client (as the RPC example implies).


Someone should *really* sit and go through the code.


Want another more explicit example:


BEGIN EXCERPT


sub rpc {


my $conn = shift;


my $subname = shift;


$subname = (caller() . '::' . $subname) unless $subname =~ /:/;


my $gimme = wantarray ? 'a' : 's'; # Array or scalar


my $msg_id = ++$g_msg_id;


my $serialized_msg = freeze ('>', $msg_id, $gimme, @_);


END EXCERPT


Notice that he shifts subname off the param list? Then proceeds to build the $serialized_msg with only the @_ params (NOT INCLUDING THE SUBNAME).


This is quite disasterous when the recevier gets here:


BEGIN EXCERPT


my $instant = thaw($msg);


my ($dir, $id, @args) = @$instant;


my ($result, @results);


if ($dir eq '>') {


# New request message


my $gimme = shift @args;


my $sub_name = shift @args;


try {


no strict 'refs'; # Because we call the subroutine using


# a symbolic reference


if ($gimme eq 'a') { # Want an array back


@results = &{$sub_name} (@args);


} else {


$result = &{$sub_name} (@args);


}


END EXCERPT


Notice again that he tries to shift the subname off the thaw'd @args array... Won't work, will it?!


I knew this already but for your knowledge - Don't trust ANYONE else's code. You'll pay for it with a significant loss of time.


See larger cover