in reply to XML::Parser Streams performing undesired buffering

In Expat/Expat.xs, line 374 in my version reads:
cnt = perl_call_method("read", G_SCALAR);
Change this to:
cnt = perl_call_method("sysread", G_SCALAR);
Then "make install". That should do ya (on Unix-like systems, at least), although I would like to reiterate that a well-formed XML document has a single top-level element, so it can't really be considered parsed until you get to the end.

Another way to do this is to subclass IO::Socket::INET to override the read method.

Update: Here's how you would do the subclassing thing:

use strict; use XML::Parser; use IO::Socket::INET; { package DebufSocket; our @ISA = qw(IO::Socket::INET); sub read { my $self = shift; $self->sysread(@_); } } sub handle_elem_start { my ($expat,$name,$atts) = @_; print "in element \"$name\", at byte ".$expat->current_byte()." in s +tream\n"; } my $sock=DebufSocket->new( PeerAddr => '', PeerPort => 6537) or die "socket: $!\n"; my $parser=XML::Parser->new( Style => 'Stream', Handlers => { Start => \&handle_elem_start } ); $parser->parse($sock);

Replies are listed 'Best First'.
Re: Re: XML::Parser Streams performing undesired buffering
by lhoward (Vicar) on Jun 20, 2003 at 14:06 UTC
    Thanks for the great suggestions. Thelonius subclassing of IO::Socket::INET solution is the one I ended up going with and it works beautifully.