}
+# --------------------------------------------------------------
+# Sets the socket to O_NONBLOCK, reads all of the data off of
+# the socket, the restores the sockets flags
+# Returns 1 on success, 0 if the socket isn't connected
+# --------------------------------------------------------------
+sub flush_socket {
+
+ my $self = shift;
+ my $socket = $self->{_socket};
+
+ if( $socket and $socket->connected() ) {
+
+ my $buf;
+ my $flags = fcntl($socket, F_GETFL, 0);
+
+ fcntl($socket, F_SETFL, $flags | O_NONBLOCK);
+ while( my $n = sysread( $socket, $buf, 8192 ) ) {
+ $logger->debug("flush_socket dropped $n bytes of data");
+ }
+ fcntl($socket, F_SETFL, $flags);
+
+ return 1;
+
+ } else {
+
+ return 0;
+ }
+}
+
+
+
1;
use Time::HiRes qw(time);
use JSON;
use vars qw/@ISA $app/;
+use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
use Carp;
+use IO::Socket::INET;
+use IO::Socket::UNIX;
+
# XXX Need to add actual logging statements in the code
my $logger = "OpenSRF::Utils::Logger";
$logger->debug( "Error closing Unix socket: $!", ERROR );
}
-
my $app = $self->app();
$logger->transport( "UnixServer for $app received $data", INTERNAL );
+ # --------------------------------------------------------------
+ # Drop all data from the socket before coninuting to process
+ # --------------------------------------------------------------
+ my $ph = OpenSRF::Transport::PeerHandle->retrieve;
+ if(!$ph->flush_socket()) {
+ $logger->error("We received a request ".
+ "and we are no longer connected to the jabber network. ".
+ "We will go away and drop this request: $data");
+ exit;
+ }
+
my $app_session = OpenSRF::Transport->handler( $self->app(), $data );
if(!ref($app_session)) {
$app_session->kill_me if ($app_session);
$0 = $orig;
-
-
}
OpenSRF::Application->application_implementation->child_init
if (OpenSRF::Application->application_implementation->can('child_init'));
- return OpenSRF::Transport::PeerHandle->retrieve;
+ return OpenSRF::Transport::PeerHandle->retrieve;
}
1;