[LON-CAPA-cvs] cvs: loncom / lond
foxr
lon-capa-cvs@mail.lon-capa.org
Tue, 27 Jul 2004 11:10:47 -0000
foxr Tue Jul 27 07:10:47 2004 EDT
Modified files:
/loncom lond
Log:
Add ping handler to the dispatched set of handlers.
I think this just might even pass the style police so far.
Index: loncom/lond
diff -u loncom/lond:1.213 loncom/lond:1.214
--- loncom/lond:1.213 Tue Jul 27 06:50:37 2004
+++ loncom/lond Tue Jul 27 07:10:47 2004
@@ -2,7 +2,7 @@
# The LearningOnline Network
# lond "LON Daemon" Server (port "LOND" 5663)
#
-# $Id: lond,v 1.213 2004/07/27 10:50:37 foxr Exp $
+# $Id: lond,v 1.214 2004/07/27 11:10:47 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -56,9 +56,9 @@
my $status='';
my $lastlog='';
-my $VERSION='$Revision: 1.213 $'; #' stupid emacs
+my $VERSION='$Revision: 1.214 $'; #' stupid emacs
my $remoteVERSION;
-my $currenthostid;
+my $currenthostid="default";
my $currentdomainid;
my $client;
@@ -1032,6 +1032,37 @@
}
}
+
+#--------------------- Request Handlers --------------------------------------------
+#
+# By convention each request handler registers itself prior to the sub declaration:
+#
+
+# Handles ping requests.
+# 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
+# known as.
+# Returns:
+# 1 - Ok to continue processing.
+# 0 - Program should exit.
+# Side effects:
+# Reply information is sent to the client.
+
+sub ping_handler {
+ my ($cmd, $tail, $client) = @_;
+ Debug("$cmd $tail $client .. $currenthostid:");
+
+ Reply( $client,"$currenthostid\n","$cmd:$tail");
+
+ return 1;
+}
+®ister_handler("ping", \&ping_handler, 0, 1, 1); # Ping unencoded, client or manager.
+
+
#---------------------------------------------------------------
#
# Getting, decoding and dispatching requests:
@@ -1096,6 +1127,10 @@
chomp($command);
chomp($tail);
$tail =~ s/(\r)//; # This helps people debugging with e.g. telnet.
+ $command =~ s/(\r)//; # And this too for parameterless commands.
+ if(!$tail) {
+ $tail =""; # defined but blank.
+ }
&Debug("Command received: $command, encoded = $wasenc");
@@ -1140,15 +1175,7 @@
}
# ------------------------------------------------------------- Normal commands
-# ------------------------------------------------------------------------ ping
- if ($userinput =~ /^ping/) { # client only
- if(isClient) {
- print $client "$currenthostid\n";
- } else {
- Reply($client, "refused\n", $userinput);
- }
-# ------------------------------------------------------------------------ pong
- }elsif ($userinput =~ /^pong/) { # client only
+ if ($userinput =~ /^pong/) { # client only
if(isClient) {
my $reply=&reply("ping",$clientname);
print $client "$currenthostid:$reply\n";
@@ -3129,17 +3156,11 @@
# request - Original request from client.
#
sub Reply {
- alarm(120);
- my $fd = shift;
- my $reply = shift;
- my $request = shift;
-
my ($fd, $reply, $request) = @_;
print $fd $reply;
Debug("Request was $request Reply was $reply");
$Transactions++;
- alarm(0);
}