[LON-CAPA-cvs] cvs: newloncapa / loncnew /types LondConnection.pm
foxr
lon-capa-cvs@mail.lon-capa.org
Thu, 27 Feb 2003 03:02:27 -0000
foxr Wed Feb 26 22:02:27 2003 EDT
Modified files:
/newloncapa loncnew
/newloncapa/types LondConnection.pm
Log:
Continued development of the code: Adding code to LondWritable to handle
the socket states.
Index: newloncapa/loncnew
diff -u newloncapa/loncnew:1.1.1.1 newloncapa/loncnew:1.2
--- newloncapa/loncnew:1.1.1.1 Wed Feb 26 20:28:12 2003
+++ newloncapa/loncnew Wed Feb 26 22:02:27 2003
@@ -117,9 +117,55 @@
The connection has sent a request. Now it must
receive a reply. Readability monitoring is
requested.
+
+ This function is an event handler and therefore receives as
+a parameter the event that has fired. The data for the watcher
+of this event is a reference to a list of one or two elements,
+depending on state. The first (and possibly only) element is the
+socket. The second (present only if a request is in progress)
+is the socket on which to return a reply to the caller.
+
=cut
sub LondWritable {
+ my $Event = shift;
+ my $Watcher = $Event->w;
+ my @data = $Watcher->data;
+ my $Socket = $data[0]; # I know there's at least a socket.
+
+ # Figure out what to do depending on the state of the socket:
+
+ my $State = $Socket->GetState();
+
+ if ($State eq "Connected") {
+ # "init" is being sent...
+
+ if ($Socket->Writable() != 0) {
+ # The write resulted in an error.
+ }
+
+ } elsif ($State eq "Initialized") {
+
+ # Now that init was sent, we switch
+ # to watching for readability:
+
+ $Watcher->poll = "r";
+ $Watcher->callback = LondReadable;
+
+ } elsif ($State eq "ChallengeReceived") {
+ } elsif ($State eq "ChallengeReplied") {
+ } elsif ($State eq "RequestingKey") {
+ } elsif ($State eq "ReceivingKey") {
+ } elsif ($State eq "SendingRequest") {
+ } elsif ($State eq "ReceivingReply") {
+ } else {
+ # Control only passes here on an error:
+ # the socket state does not match any
+ # of the known states... so an error
+ # must be logged.
+ &Debug(4, "Invalid socket state ".$State."\n");
+ }
+
}
=pod
Index: newloncapa/types/LondConnection.pm
diff -u newloncapa/types/LondConnection.pm:1.1.1.1 newloncapa/types/LondConnection.pm:1.2
--- newloncapa/types/LondConnection.pm:1.1.1.1 Wed Feb 26 20:28:12 2003
+++ newloncapa/types/LondConnection.pm Wed Feb 26 22:02:27 2003
@@ -196,7 +196,9 @@
#
# Figure out the next state:
#
- if($self->{State} eq "ChallengeReceived") {
+ if($self->{State} eq "Connected") {
+ $self->Transition("Initialized");
+ } elsif($self->{State} eq "ChallengeReceived") {
$self->Transition("ChallengeReplied");
} elsif ($self->{State} eq "SendingRequest") {
$self->Transition("ReceivingReply");
@@ -330,9 +332,9 @@
=head1 Theory
The lond object is a state machine. It lives through the following states:
-=item Initialized: Freshly created, not yet connected.
=item Connected: a TCP connection has been formed, but the passkey has not yet
been negotiated.
+=item Initialized: "init" sent.
=item ChallengeReceived: lond sent its challenge to us.
=item ChallengeReplied: We replied to lond's challenge waiting for lond's ok.
=item Idle: Connection was negotiated but no requests are active.