chopping up dup messages in Client::process()
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 30 Aug 2006 00:35:12 +0000 (00:35 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 30 Aug 2006 00:35:12 +0000 (00:35 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@771 9efc2488-bf62-4759-914b-345cdb29e865

src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm

index b90e172..d67e77d 100644 (file)
@@ -192,6 +192,7 @@ sub timed_read {
                $self->{temp_buffer} = '';
 
                my ($tag) = ($buffer =~ /<([^\s\?\>]+)/o);
+               $self->{last_tag} = $tag;
                $logger->transport("Using tag: $tag  ", INTERNAL);
 
                if ( $buffer =~ /^(.*?<\/$tag>){1}(.*)/s) {
@@ -285,7 +286,8 @@ sub timed_read {
 
                                if ($first_read) {
                                        $logger->transport(" First read Buffer\n [$buffer]", INTERNAL);
-                                       ($tag) = ($buffer =~ /<([^\s\?\>]+){1}/o);
+                                       ($tag) = ($buffer =~ /<([^\s\?\>\/]+){1}/o);
+                                       $self->{last_tag} = $tag;
                                        $first_read--;
                                        $logger->transport("Using tag: $tag  ", INTERNAL);
                                }
@@ -563,6 +565,18 @@ sub process {
                        "Call to Client->timed_read( $timeout ) successfully returned data", INTERNAL );
        }
 
+       my $t = $self->{last_tag};
+       my @msgs = $val =~ /(<$t[^>]*>.*?<\/$t>)/g;
+       $val = shift(@msgs);
+
+       if (@msgs) {
+               my $tmp = $self->{temp_buffer};
+
+               $self->{temp_buffer} = '';
+               $self->{temp_buffer} .= $_ for (@msgs);
+               $self->{temp_buffer} .= $tmp;
+       }
+
        return $val;
 
 }