#!../src/tops  -i -s ../sys  -u drivers
# File test/net  September 2004
# Infix version December 2005
# Note that usrpath is directory drivers.  TASK_PORT gets dserv1 from
# usrpath, and drivers/dserv1 has a generic #! line just for this demo.

/* Testing word TASK_PORT.

   TASK_PORT lets the program send a task to be run to another instance
   of the program, thereby reducing the risk of failure due to running 
   the task itself.

----------------------------------------------------------------------*/

   if(missing("CONNECT")) HALT(
      dot(" net: words for networking not present, test skipped"), nl
   );

   t0=time;

   nl(dot(cats("-", 72)));

   nl(.("Testing word TASK_PORT"));
   nl(.out("Start a server on a new PID, connect and send a task to it, and after results are received, close the server and kill the PID." ,72));

   nl;
   nl(dot(" usrpath: " + usrpath));

   nl(
      dot(
         " net: TASK_PORT will idle no more than "
         + intstr(TASK_PORT.STARTUP)
         + " seconds for server to start" 
      )
   );

   R = TASK_PORT(
      5, // secs for server to perform and send R before it is killed
      {" This postfix text gives the server's task--send random mat R:
         4 3 random 
         0.5 less (hR) \ random between +0.5 and -0.5
      "}
   );

   nl(nl, dot("Server results received:"));
   nl(dot(mtext(mformatset("% 22.16e"), R))); 
   nl(dot("Total seconds: " + format(time-t0,"%0.2f")));
   nl();
   nl(dot(cats(clients, "-", 72)));

   end

/*----------------------------------------------------------------------

Below is the postfix version of this file.

#!../src/tops  -s ../sys  -u ../usr
# File test/net  September 2004

   "CONNECT" missing
   IF " words for networking not present, test skipped" dot nl
      halt
   THEN

\-----------------------------------------------------------------------

   "-" 72 cats . nl
   "Testing word TASK_PORT" . nl
   "Starting a server on a new PID, connecting and porting a task to it, and after results are received, closing the server and killing the PID (ntrace output below shows activity on both server and client):"
   72 .out nl nl

   ntrace
   " net: idle for up to" . "TASK_PORT" "STARTUP" yank .i
   " seconds for server to start" . nl

   10 \ seconds to perform task on server before it is killed
   {" This is the text for the server's task:
      nl clients nl
      ntrace
      4 3 random 0.5 less (hA)
   "} (hTask) TASK_PORT (hA)

   nl nl "Server results received:" . nl (hA)
   "% 22.16e" mformatset mtext . nl nl
   clients
   "-" 72 cats . nl
*/
