TakTuk3pm
Perl module that provides an interface to "taktuk(1)" communication facilities
Usage
use TakTuk;my $rank = TakTuk::get('rank');my $count = TakTuk::get('count');print "I'm process $rank among $count\n";if ($rank > 1) {my ($from, $message) = TakTuk::recv();if (not defined($message)) {print "Trying to recv: ",TakTuk::error_msg($TakTuk::error), "\n";} else {print "$rank received $message from $from\n";}}sleep 1;my $next = $rank+1;$next = 1 if ($next > $count);if (not TakTuk::send(to=>$next, body=>"[Salut numero $rank]")) {print "Trying to send to $next: ",TakTuk::error_msg($TakTuk::error), "\n";}if ($rank == 1) {my ($from, $message) = TakTuk::recv(timeout=>5);if (not defined($message)) {print "Trying to recv :",TakTuk::error_msg($TakTuk::error), "\n";} else {print "$rank received $message from $from\n";}}
Overview
The TakTuk communication layer Perl interface provides a way for programs executed using the taktuk(1) command to exchange data. It is based on a simple send/receive model using multicast-like sends and optionally timeouted receives. This is only designed to be a control facility, in particular this is not a high performance communication library.
The Perl communication interface for TakTuk is made of functions that can be called by scripts executed using the "taktuk_perl" command of the TakTuk engine (preferred way, less installation requirements on remote machines) or using the TakTuk Perl module provided with the TakTuk distribution. These functions are:
TakTuk::get($)-
gets some information from
TakTuk. Currently available information includes 'target', 'rank', 'count', 'father', 'child_min' and 'child_max'. This is a better way to get this information than environment variables as its takes into account renumbering that might occur after process spawn.
TakTuk::send(%)-
sends a scalar to a single peer or a set specification (see
taktuk(1)for information about set specifications). The two mandatory fields in the arguments are"to"(with a set specification) and"body". Optionally, a field"target"might be given. Returns an undefined value upon error.
TakTuk::recv(%)-
blocks until the reception of a message. Returns a list of two elements: the logical number of the source of the message and the message itself. Accepts an optional
"timeout"argument with a numeric value. Returns an empty list upon error.
When an error occur, all these functions set the variable $TakTuk::error to the numeric code of the error that occurred. A textual description of the error is provided by the function TakTuk::error_msg($) that takes the error code as an argument.
Error codes are the following :
- TakTuk::ESWRIT
-
a call to
"TakTuk::syswrite"failed. This is due to a"syswrite"error different than"EAGAIN". The code should be accessible using$!.
- TakTuk::EFCLSD
-
the communication channel to the
TakTukengine has been closed. This typically occur when shutting down the logical network (using Ctrl-C on root node for instance).
- TakTuk::ESREAD ("TakTuk::recv" only)
-
a call to
"sysread"failed (the code should be accessible using$!).
- TakTuk::EARGTO ("TakTuk::send" only)
-
"to"field missing in the arguments.
- TakTuk::EARGBD ("TakTuk::send" only)
-
"body"field missing in the arguments.
- TakTuk::ETMOUT ("TakTuk::recv" only)
-
The call to
"TakTuk::recv"timeouted. This only occur when giving a"timeout"field as"TakTuk::recv"argument.
Finally, the TakTuk Perl module defines some constants which value match the different states reported by the stream "state" (see taktuk(1) for details about this stream). These constant are the following:
TakTuk::TAKTUK_READYTakTuk::TAKTUK_NUMBEREDTakTuk::TAKTUK_TERMINATEDTakTuk::CONNECTION_FAILEDTakTuk::CONNECTION_INITIALIZEDTakTuk::CONNECTION_LOSTTakTuk::COMMAND_STARTEDTakTuk::COMMAND_FAILEDTakTuk::COMMAND_TERMINATEDTakTuk::UPDATE_FAILEDTakTuk::PIPE_STARTEDTakTuk::PIPE_FAILEDTakTuk::PIPE_TERMINATEDTakTuk::FILE_RECEPTION_STARTEDTakTuk::FILE_RECEPTION_FAILEDTakTuk::FILE_RECEPTION_TERMINATEDTakTuk::FILE_SEND_FAILEDTakTuk::INVALID_TARGETTakTuk::NO_TARGETTakTuk::MESSAGE_DELIVEREDTakTuk::INVALID_DESTINATIONTakTuk::UNAVAILABLE_DESTINATION
Releases
8 releases since Debian 6.0 (Squeeze); the text changed 7 times.