Update of /cvsroot/perl-ldap/ldap/lib/Net
In directory sc8-pr-cvs1:/tmp/cvs-serv1965/lib/Net
Modified Files:
LDAP.pm
Log Message:
Better handling on IO errors
Index: LDAP.pm
===================================================================
RCS file: /cvsroot/perl-ldap/ldap/lib/Net/LDAP.pm,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- LDAP.pm 27 Jan 2003 18:24:15 -0000 1.40
+++ LDAP.pm 6 May 2003 15:37:51 -0000 1.41
@@ -20,6 +20,7 @@
LDAP_LOCAL_ERROR
LDAP_PARAM_ERROR
LDAP_INAPPROPRIATE_AUTH
+ LDAP_SERVER_DOWN
);
$VERSION = "0.2701";
@@ -625,7 +626,9 @@
if $debug & 4;
}
- syswrite($ldap->socket, $mesg->pdu, length($mesg->pdu))
+ my $socket = $ldap->socket or return LDAP_SERVER_DOWN;
+
+ syswrite($socket, $mesg->pdu, length($mesg->pdu))
or return _error($ldap, $mesg, LDAP_LOCAL_ERROR,"$!");
# for CLDAP, here we need to recode when we were sent
@@ -652,14 +655,14 @@
sub _recvresp {
my $ldap = shift;
my $what = shift;
- my $sock = $ldap->socket;
+ my $sock = $ldap->socket or return LDAP_SERVER_DOWN;
my $sel = IO::Select->new($sock);
my $ready;
for( $ready = 1 ; $ready ; $ready = $sel->can_read(0)) {
my $pdu;
asn_read($sock, $pdu)
- or return LDAP_OPERATIONS_ERROR;
+ or return _drop_conn($self, LDAP_OPERATIONS_ERROR, "Communications Error");
my $debug;
if ($debug = $ldap->debug) {
@@ -695,6 +698,20 @@
return LDAP_SUCCESS;
}
+
+sub _drop_conn {
+ my ($self, $err, $etxt) = @_;
+
+ delete $self->{net_ldap_socket};
+ if (my $msgs = delete $self->{net_ldap_mesg}) {
+ foreach my $mesg (values %$msgs) {
+ $mesg->set_error($err, $etxt);
+ }
+ }
+
+ $err;
+}
+
sub _forgetmesg {
my $ldap = shift;
|