http://www.perlmonks.org?node_id=267261

lhoward has asked for the wisdom of the Perl Monks concerning the following question:

I am interfacing with an existing application that provides an XML event stream over a TCP socket. If I establish a IO::Socket connection without hooking it up to XML::Parser I see the data flow by in real-time. However, when I hook up my socket to XML::Parser, it seems to be buffering IO and then processing a whole bunch at once. Since I want to process the stream more-or-less in realtime; this is undesirable behavior from my point of view. In my experimentation it seems to be buffering data until it gets 32k, then processing that additional stream data. I've checked the docs and module source code but can't find any way to set this buffering size manually. I've encluded example code (with lots of my error checking and other fluff not relevant to the problem at hand) removed:
use strict; use XML::Parser; use IO::Socket::INET; my $sock=IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => 6537); my $parser=XML::Parser->new( Style => 'Stream', Handlers => { Start => \&handle_elem_start } ); $parser->parse($sock); sub handle_elem_start{ my ($expat,$name,&atts)=@_; print "in element \"$name\", at byte ".$expat->current_byte()." in s +tream\n"; }
Is there anyway to set the buffer size? Or to force XML::Parser to process its buffer? Might one of the other XML parsers on CPAN serve me better for the task at hand? Any ideas on how to avoid the unwanted buffering? L