* Improve detection of client connection state with jabber server
Be more aggressive in testing and responding to failed connectivity.
It can happen in various ways, depending on what's happening to the
jabber server (death, delay, graceful shutdown). With these changes
we attempt to cover all the bases and detect as early as possible that
a connection has died, specifically when trying to create a new
connection after one has failed.
* Do a better job of cleaning up dead connections
Transport::PeerHandle now has a reset() action which disconnects (when
possible) and clears the global connection reference.
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
my $self = shift;
my $con = OpenSRF::Transport::PeerHandle->retrieve;
- return if $con and $con->tcp_connected;
+ if ($con) {
+ # flush the socket to force a non-blocking read
+ # and to clear out any unanticipated leftovers
+ eval { $con->flush_socket };
+ return if $con->connected;
+ $con->reset;
+ }
my %params = @_;
sub connected {
if (my $con = OpenSRF::Transport::PeerHandle->retrieve) {
- return 1 if $con->tcp_connected;
+ return 1 if $con->connected;
}
return 0;
}
return 0;
}
+sub connected {
+ my $self = shift;
+ return $self->reader->connected if $self->reader;
+ return 0;
+}
=head2 send
sub flush_socket {
my $self = shift;
+ return 0 unless $self->reader;
return $self->reader->flush_socket;
}
return $_singleton_connection;
}
+sub reset {
+ return unless $_singleton_connection;
+ $_singleton_connection->disconnect;
+ $_singleton_connection = undef;
+}
+
sub new {
my( $class, $app ) = @_;
if ($first_read and defined $nbytes and $nbytes == 0) {
# if the first read on an active socket is 0 bytes,
# the socket has been disconnected from the remote end.
+ $self->{stream_state} = DISCONNECTED;
$logger->error("Disconnected from Jabber server");
throw OpenSRF::EX::Jabber("Disconnected from Jabber server");
}