summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorunai.avila <unai.avila@fonyou.com>2014-09-02 17:29:20 +0200
committerunai.avila <unai.avila@fonyou.com>2014-09-02 17:29:20 +0200
commit9fa237bffacb25f1397bf78165a3406da916b630 (patch)
treed86a32f916fe7b724e7c698c8c00b2eadde4be08
parentimport time (diff)
downloadldap-9fa237bffacb25f1397bf78165a3406da916b630.tar
ldap-9fa237bffacb25f1397bf78165a3406da916b630.tar.gz
ldap-9fa237bffacb25f1397bf78165a3406da916b630.tar.bz2
ldap-9fa237bffacb25f1397bf78165a3406da916b630.tar.lz
ldap-9fa237bffacb25f1397bf78165a3406da916b630.tar.xz
ldap-9fa237bffacb25f1397bf78165a3406da916b630.tar.zst
ldap-9fa237bffacb25f1397bf78165a3406da916b630.zip
-rw-r--r--conn.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/conn.go b/conn.go
index b9c4560..862b5ff 100644
--- a/conn.go
+++ b/conn.go
@@ -292,3 +292,46 @@ func (l *Conn) reader() {
}
}
+// Use Abandon operation to perform connection keepalives
+func (l *Conn) Ping() error {
+
+ messageID := l.nextMessageID()
+
+ packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
+ packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, messageID, "MessageID"))
+ abandonRequest := ber.Encode(ber.ClassApplication, ber.TypePrimitive, ApplicationAbandonRequest, nil, "Abandon Request")
+ packet.AppendChild(abandonRequest)
+
+ if l.Debug {
+ ber.PrintPacket(packet)
+ }
+
+ channel, err := l.sendMessage(packet)
+ if err != nil {
+ return err
+ }
+ if channel == nil {
+ return NewError(ErrorNetwork, errors.New("ldap: could not send message"))
+ }
+ defer l.finishMessage(messageID)
+
+ packet = <-channel
+ if packet == nil {
+ return NewError(ErrorNetwork, errors.New("ldap: could not retrieve response"))
+ }
+
+ if l.Debug {
+ if err := addLDAPDescriptions(packet); err != nil {
+ return err
+ }
+ ber.PrintPacket(packet)
+ }
+
+ resultCode, resultDescription := getLDAPResultCode(packet)
+ if resultCode != 0 {
+ return NewError(resultCode, errors.New(resultDescription))
+ }
+
+ return nil
+}
+