version 1.41, 2004/02/09 13:39:28
|
version 1.44, 2004/03/02 16:25:17
|
Line 262 sub SocketTimeout {
|
Line 262 sub SocketTimeout {
|
Log("WARNING", "A socket timeout was detected"); |
Log("WARNING", "A socket timeout was detected"); |
Debug(0, " SocketTimeout called: "); |
Debug(0, " SocketTimeout called: "); |
$Socket->Dump(); |
$Socket->Dump(); |
|
if(exists($ActiveTransactions{$Socket})) { |
|
FailTransaction($ActiveTransactions{$Socket}); |
|
} |
KillSocket($Socket); # A transaction timeout also counts as |
KillSocket($Socket); # A transaction timeout also counts as |
# a connection failure: |
# a connection failure: |
$ConnectionRetriesLeft--; |
$ConnectionRetriesLeft--; |
|
if($ConnectionRetriesLeft <= 0) { |
|
Log("CRITICAL", "Host marked dead: ".GetServerHost()); |
|
} |
|
|
} |
} |
#----------------------------- Timer management ------------------------ |
#----------------------------- Timer management ------------------------ |
|
|
Line 326 sub Tick {
|
Line 333 sub Tick {
|
if($successCount == 0) { # All connections failed: |
if($successCount == 0) { # All connections failed: |
Debug(5,"Work in queue failed to make any connectiouns\n"); |
Debug(5,"Work in queue failed to make any connectiouns\n"); |
EmptyQueue(); # Fail pending transactions with con_lost. |
EmptyQueue(); # Fail pending transactions with con_lost. |
|
CloseAllLondConnections(); # Should all be closed but.... |
} |
} |
} else { |
} else { |
ShowStatus(GetServerHost()." >>> DEAD!!! <<<"); |
ShowStatus(GetServerHost()." >>> DEAD!!! <<<"); |
Debug(5,"Work in queue, but gave up on connections..flushing\n"); |
Debug(5,"Work in queue, but gave up on connections..flushing\n"); |
EmptyQueue(); # Connections can't be established. |
EmptyQueue(); # Connections can't be established. |
|
CloseAllLondConnections(); # Should all already be closed but... |
} |
} |
|
|
} |
} |
Line 521 sub CompleteTransaction {
|
Line 530 sub CompleteTransaction {
|
unlink $Transaction->getFile(); |
unlink $Transaction->getFile(); |
} |
} |
} |
} |
|
|
=pod |
=pod |
|
|
=head1 StartClientReply |
=head1 StartClientReply |
|
|
Initiates a reply to a client where the reply data is a parameter. |
Initiates a reply to a client where the reply data is a parameter. |
Line 537 sub CompleteTransaction {
|
Line 548 sub CompleteTransaction {
|
The data to send to apached client. |
The data to send to apached client. |
|
|
=cut |
=cut |
|
|
sub StartClientReply { |
sub StartClientReply { |
my $Transaction = shift; |
my $Transaction = shift; |
my $data = shift; |
my $data = shift; |
Line 554 sub StartClientReply {
|
Line 566 sub StartClientReply {
|
cb => \&ClientWritable, |
cb => \&ClientWritable, |
data => $data); |
data => $data); |
} |
} |
|
|
=pod |
=pod |
|
|
=head2 FailTransaction |
=head2 FailTransaction |
|
|
Finishes a transaction with failure because the associated lond socket |
Finishes a transaction with failure because the associated lond socket |
Line 564 sub StartClientReply {
|
Line 578 sub StartClientReply {
|
- The transaction is 'live' in which case we initiate the sending |
- The transaction is 'live' in which case we initiate the sending |
of "con_lost" to the client. |
of "con_lost" to the client. |
|
|
Deleting the transaction means killing it from the |
Deleting the transaction means killing it from the %ActiveTransactions hash. |
%ActiveTransactions hash. |
|
|
|
Parameters: |
Parameters: |
|
|
Line 573 Parameters:
|
Line 586 Parameters:
|
|
|
The LondTransaction we are failing. |
The LondTransaction we are failing. |
|
|
|
|
=cut |
=cut |
|
|
sub FailTransaction { |
sub FailTransaction { |
Line 584 sub FailTransaction {
|
Line 598 sub FailTransaction {
|
Debug(1," Replying con_lost to ".$transaction->getRequest()); |
Debug(1," Replying con_lost to ".$transaction->getRequest()); |
StartClientReply($transaction, "con_lost\n"); |
StartClientReply($transaction, "con_lost\n"); |
} |
} |
if($ConnectionRetriesLeft <= 0) { |
|
Log("CRITICAL", "Host marked dead: ".GetServerHost()); |
|
} |
|
|
|
} |
} |
|
|
Line 614 Close all connections open on lond prior
|
Line 625 Close all connections open on lond prior
|
=cut |
=cut |
sub CloseAllLondConnections { |
sub CloseAllLondConnections { |
foreach my $Socket (keys %ActiveConnections) { |
foreach my $Socket (keys %ActiveConnections) { |
KillSocket($Socket); |
if(exists($ActiveTransactions{$Socket})) { |
|
FailTransaction($ActiveTransactions{$Socket}); |
|
} |
|
KillSocket($Socket); |
} |
} |
} |
} |
=cut |
=cut |
Line 666 sub KillSocket {
|
Line 680 sub KillSocket {
|
# |
# |
if($ConnectionCount == 0) { |
if($ConnectionCount == 0) { |
EmptyQueue(); |
EmptyQueue(); |
|
CloseAllLondConnections; # Should all already be closed but... |
} |
} |
} |
} |
|
|
Line 932 sub LondWritable {
|
Line 947 sub LondWritable {
|
|
|
SocketDump(6,$Socket); |
SocketDump(6,$Socket); |
|
|
if ($State eq "Connected") { |
# If the socket is writable, we must always write. |
|
# Only by writing will we undergo state transitions. |
if ($Socket->Writable() != 0) { |
# Old logic wrote in state specific code below, however |
# The write resulted in an error. |
# That forces us at least through another invocation of |
# We'll treat this as if the socket got disconnected: |
# this function after writability is possible again. |
Log("WARNING", "Connection to ".$RemoteHost. |
# This logic also factors out common code for handling |
" has been disconnected"); |
# write failures... in all cases, write failures |
|
# Kill the socket. |
|
# This logic makes the branches of the >big< if below |
|
# so that the writing states are actually NO-OPs. |
|
|
|
if ($Socket->Writable() != 0) { |
|
# The write resulted in an error. |
|
# We'll treat this as if the socket got disconnected: |
|
Log("WARNING", "Connection to ".$RemoteHost. |
|
" has been disconnected"); |
|
if(exists($ActiveTransactions{$Socket})) { |
FailTransaction($ActiveTransactions{$Socket}); |
FailTransaction($ActiveTransactions{$Socket}); |
$Watcher->cancel(); |
|
KillSocket($Socket); |
|
return; |
|
} |
} |
|
$Watcher->cancel(); |
|
KillSocket($Socket); |
|
return; |
|
} |
|
|
|
|
|
|
|
if ($State eq "Connected") { |
|
|
# "init" is being sent... |
# "init" is being sent... |
|
|
} elsif ($State eq "Initialized") { |
} elsif ($State eq "Initialized") { |
|
|
# Now that init was sent, we switch |
# Now that init was sent, we switch |
Line 960 sub LondWritable {
|
Line 990 sub LondWritable {
|
# are echoing it back. This is a no-op, |
# are echoing it back. This is a no-op, |
# we're waiting for the state to change |
# we're waiting for the state to change |
|
|
if($Socket->Writable() != 0) { |
|
|
|
$Watcher->cancel(); |
|
KillSocket($Socket); |
|
return; |
|
} |
|
|
|
} elsif ($State eq "ChallengeReplied") { |
} elsif ($State eq "ChallengeReplied") { |
# The echo was sent back, so we switch |
# The echo was sent back, so we switch |
# to watching readability. |
# to watching readability. |
Line 975 sub LondWritable {
|
Line 998 sub LondWritable {
|
$Watcher->poll("r"); |
$Watcher->poll("r"); |
} elsif ($State eq "RequestingVersion") { |
} elsif ($State eq "RequestingVersion") { |
# Sending the peer a version request... |
# Sending the peer a version request... |
|
|
if($Socket->Writable() != 0) { |
|
$Watcher->cancel(); |
|
KillSocket($Socket); |
|
return; |
|
} |
|
} elsif ($State eq "ReadingVersionString") { |
} elsif ($State eq "ReadingVersionString") { |
# Transition to read since we have sent the |
# Transition to read since we have sent the |
# version command and now just need to read the |
# version command and now just need to read the |
Line 991 sub LondWritable {
|
Line 1009 sub LondWritable {
|
|
|
} elsif ($State eq "SetHost") { |
} elsif ($State eq "SetHost") { |
# Setting the remote domain... |
# Setting the remote domain... |
|
|
if($Socket->Writable() != 0) { |
|
$Watcher->cancel(); |
|
KillSocket($Socket); |
|
return; |
|
} |
|
} elsif ($State eq "HostSet") { |
} elsif ($State eq "HostSet") { |
# Back to readable to get the ok. |
# Back to readable to get the ok. |
|
|
Line 1007 sub LondWritable {
|
Line 1020 sub LondWritable {
|
} elsif ($State eq "RequestingKey") { |
} elsif ($State eq "RequestingKey") { |
# At this time we're requesting the key. |
# At this time we're requesting the key. |
# again, this is essentially a no-op. |
# again, this is essentially a no-op. |
# we'll write the next chunk until the |
|
# state changes. |
|
|
|
if($Socket->Writable() != 0) { |
|
# Write resulted in an error. |
|
|
|
$Watcher->cancel(); |
|
KillSocket($Socket); |
|
return; |
|
|
|
} |
|
} elsif ($State eq "ReceivingKey") { |
} elsif ($State eq "ReceivingKey") { |
# Now we need to wait for the key |
# Now we need to wait for the key |
# to come back from the peer: |
# to come back from the peer: |
Line 1030 sub LondWritable {
|
Line 1033 sub LondWritable {
|
# At this time we are sending a request to the |
# At this time we are sending a request to the |
# peer... write the next chunk: |
# peer... write the next chunk: |
|
|
if($Socket->Writable() != 0) { |
|
|
|
if(exists($ActiveTransactions{$Socket})) { |
|
Debug(3, "Lond connection lost, failing transactions"); |
|
FailTransaction($ActiveTransactions{$Socket}); |
|
} |
|
$Watcher->cancel(); |
|
KillSocket($Socket); |
|
return; |
|
|
|
} |
|
|
|
} elsif ($State eq "ReceivingReply") { |
} elsif ($State eq "ReceivingReply") { |
# The send has completed. Wait for the |
# The send has completed. Wait for the |
Line 1229 sub QueueTransaction {
|
Line 1221 sub QueueTransaction {
|
Debug(5,"Starting additional lond connection"); |
Debug(5,"Starting additional lond connection"); |
if(MakeLondConnection() == 0) { |
if(MakeLondConnection() == 0) { |
EmptyQueue(); # Fail transactions, can't make connection. |
EmptyQueue(); # Fail transactions, can't make connection. |
|
CloseAllLondConnections; # Should all be closed but... |
} |
} |
} else { |
} else { |
ShowStatus(GetServerHost()." >>> DEAD !!!! <<<"); |
ShowStatus(GetServerHost()." >>> DEAD !!!! <<<"); |
EmptyQueue(); # It's worse than that ... he's dead Jim. |
EmptyQueue(); # It's worse than that ... he's dead Jim. |
|
CloseAllLondConnections; # Should all be closed but.. |
} |
} |
} |
} |
} else { # Can start the request: |
} else { # Can start the request: |
Line 1275 sub ClientRequest {
|
Line 1269 sub ClientRequest {
|
Debug(8,"Data: ".$data." this read: ".$thisread); |
Debug(8,"Data: ".$data." this read: ".$thisread); |
$data = $data.$thisread; # Append new data. |
$data = $data.$thisread; # Append new data. |
$watcher->data($data); |
$watcher->data($data); |
if($data =~ /(.*\n)/) { # Request entirely read. |
if($data =~ /\n$/) { # Request entirely read. |
if($data eq "close_connection_exit\n") { |
if($data eq "close_connection_exit\n") { |
Log("CRITICAL", |
Log("CRITICAL", |
"Request Close Connection ... exiting"); |
"Request Close Connection ... exiting"); |