in reply to XML::Parser Streams performing undesired buffering
In Expat/Expat.xs, line 374 in my version reads:
Change this to:cnt = perl_call_method("read", 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.cnt = perl_call_method("sysread", G_SCALAR);
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 => '162.134.173.177', PeerPort => 6537) or die "socket: $!\n"; my $parser=XML::Parser->new( Style => 'Stream', Handlers => { Start => \&handle_elem_start } ); $parser->parse($sock);
In Section
Seekers of Perl Wisdom