From: Chris R. <chr...@me...> - 2002-06-21 09:32:49
|
Herbert Rosmanith <he...@wi...> wrote: > > > hello everyone, > > I've been developing an application which uses Net::LDAP. In my testing > environment, everything was fine. When we moved the application to the > production environement, the connection to the LDAP-server would fail > after a while. The reason is a check-point firewall, which disconnects > idle tcp/ip sessions after a given time. Needless to say, my > LDAP-connection can be idle for hours (especially in the night-hours), > but for performance reasons it is required that the connection is not > being dropped. > > I've looked into Net/LDAP.pm and found a small and easy solution: > just use keepalive-sockets. My patch just adds two lines of perl > code to Net/LDAP.pm: > > 116 sub _connect { > 117 my ($ldap, $host, $arg) = @_; > 118 > 119 $ldap->{net_ldap_socket} = IO::Socket::INET->new( > 120 PeerAddr => $host, > 121 PeerPort => $arg->{port} || '389', > 122 Proto => 'tcp', > 123 Timeout => defined $arg->{timeout} > 124 ? $arg->{timeout} > 125 : 120 > 126 ); > ++ 127 $ldap->{net_ldap_socket}->sockopt(SO_KEEPALIVE,1) > ++ 128 if defined $arg->{keepalive}; > 129 > 130 } > > In the main-program, all you do is specifiyng "keepalive=>1" when > issuing a new(): > > : $ldap = Net::LDAP->new( $LDAP_host, > : port => $LDAP_port, > : timeout => $ldap_connect_timeout, > : keepalive => 1); > That looks OK to me. Cheers, Chris |