[LON-CAPA-cvs] cvs: loncom / lond

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 27 Jul 2004 11:21:48 -0000


foxr		Tue Jul 27 07:21:48 2004 EDT

  Modified files:              
    /loncom	lond 
  Log:
  Added pong handler to the set of hash dispatched handlers.  2 down and many
  more to go... but at least most of them are already written in my private
  branch.
  
  
  
Index: loncom/lond
diff -u loncom/lond:1.214 loncom/lond:1.215
--- loncom/lond:1.214	Tue Jul 27 07:10:47 2004
+++ loncom/lond	Tue Jul 27 07:21:48 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.214 2004/07/27 11:10:47 foxr Exp $
+# $Id: lond,v 1.215 2004/07/27 11:21:48 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -56,7 +56,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.214 $'; #' stupid emacs
+my $VERSION='$Revision: 1.215 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -1035,7 +1035,8 @@
 
 #--------------------- Request Handlers --------------------------------------------
 #
-#   By convention each request handler registers itself prior to the sub declaration:
+#   By convention each request handler registers itself prior to the sub 
+#   declaration:
 #
 
 #  Handles ping requests.
@@ -1062,6 +1063,33 @@
 }
 &register_handler("ping", \&ping_handler, 0, 1, 1);       # Ping unencoded, client or manager.
 
+#
+# Handles pong requests.  Pong replies with our current host id, and
+#                         the results of a ping sent to us via our lonc.
+#
+# Parameters:
+#      $cmd    - the actual keyword that invoked us.
+#      $tail   - the tail of the request that invoked us.
+#      $replyfd- File descriptor connected to the client
+#  Implicit Inputs:
+#      $currenthostid - Global variable that carries the name of the host we are
+#                       connected to.
+#  Returns:
+#      1       - Ok to continue processing.
+#      0       - Program should exit.
+#  Side effects:
+#      Reply information is sent to the client.
+
+sub pong_handler {
+    my ($cmd, $tail, $replyfd) = @_;
+
+    my $reply=&reply("ping",$clientname);
+    &Reply( $replyfd, "$currenthostid:$reply\n", "$cmd:$tail"); 
+    return 1;
+}
+&register_handler("pong", \&pong_handler, 0, 1, 1);       # Pong unencoded, client or manager
+
+
 
 #---------------------------------------------------------------
 #
@@ -1174,16 +1202,10 @@
 
     }    
 
-# ------------------------------------------------------------- Normal commands
-    if ($userinput =~ /^pong/) { # client only
-	if(isClient) {
-	    my $reply=&reply("ping",$clientname);
-	    print $client "$currenthostid:$reply\n"; 
-	} else {
-	    Reply($client, "refused\n", $userinput);
-	}
+#------------------- Commands not yet in spearate handlers. --------------
+
 # ------------------------------------------------------------------------ ekey
-    } elsif ($userinput =~ /^ekey/) { # ok for both clients & mgrs
+    if ($userinput =~ /^ekey/) { # ok for both clients & mgrs
 	my $buildkey=time.$$.int(rand 100000);
 	$buildkey=~tr/1-6/A-F/;
 	$buildkey=int(rand 100000).$buildkey.int(rand 100000);