On Sep 6, 2005, at 07:18 AM, Marc Chantreux wrote:
Hi all,
this is a simple search code :
my $msg = $ad->search(
base => "ou=$base,dc=Univ-R,dc=local"
, filter => '(objectClass=user)'
, attrs => [ qw( description cn ) ]
, callback => sub {
my ( $msg , $r ) = @_;
if ( $msg->code ) {
die 'E:' , $msg->error , "\n";
}
if ( $r->isa('Net::LDAP::Entry') ) {
print 'O:' , $r->dn , "\n";
} else {
print 'W:' , ref($r) , "\n";
}
$msg->pop_entry;
}
);
This will cause :
Deep recursion on subroutine "Net::LDAP::Message::code" at s.pl
line 46, <DATA> line 225.
E:Protocol Error
i've seen that in /Net/LDAP/Message.pm
43 $self->sync unless exists $self->{resultCode};
Message->code calls Message->sync calls LDAP->sync calls LDAP-
>_recvresp calls Message->code.
Yes thats right.
You cannot get the final response code from a search until all
entries have been read because the code is in the final response
packet. But the callback is called as each entry arrives.
So you cannot call ->code from within a callback because it cannot
return until the last packet is seen, so it causes the callback to be
called for the next, which call ->code which causes the same for the
next and so on.
It is not a bug, but a limitation if you want to process entries as
they are returned from the server as they arrive.
In the past I have been tempted to have ->sync fail if called from
within a callback to prevent this situation. Either way you get an
error, just this way it is more dramatic and causes people to fix
thier code.
Graham.