diff options
author | unai.avila <unai.avila@fonyou.com> | 2014-09-02 17:29:20 +0200 |
---|---|---|
committer | unai.avila <unai.avila@fonyou.com> | 2014-09-02 17:29:20 +0200 |
commit | 9fa237bffacb25f1397bf78165a3406da916b630 (patch) | |
tree | d86a32f916fe7b724e7c698c8c00b2eadde4be08 /conn.go | |
parent | import time (diff) | |
download | ldap-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 |
Diffstat (limited to 'conn.go')
-rw-r--r-- | conn.go | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -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 +} + |