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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|