diff options
author | Ivan Egorov <vany.egorov@gmail.com> | 2015-12-29 11:41:49 +0100 |
---|---|---|
committer | Ivan Egorov <vany.egorov@gmail.com> | 2015-12-29 11:41:49 +0100 |
commit | 1f08215cab519953234d32be3a69bd807f81699b (patch) | |
tree | f0f09979318dfaba4e289f9edc20bbcc715b08ef /conn.go | |
parent | Fixed bug with SizeLimit=1 (diff) | |
download | ldap-1f08215cab519953234d32be3a69bd807f81699b.tar ldap-1f08215cab519953234d32be3a69bd807f81699b.tar.gz ldap-1f08215cab519953234d32be3a69bd807f81699b.tar.bz2 ldap-1f08215cab519953234d32be3a69bd807f81699b.tar.lz ldap-1f08215cab519953234d32be3a69bd807f81699b.tar.xz ldap-1f08215cab519953234d32be3a69bd807f81699b.tar.zst ldap-1f08215cab519953234d32be3a69bd807f81699b.zip |
Diffstat (limited to '')
-rw-r--r-- | conn.go | 88 |
1 files changed, 51 insertions, 37 deletions
@@ -10,7 +10,8 @@ import ( "log" "net" "sync" - "time" + "time" + "github.com/nmcclain/asn1-ber" ) @@ -57,13 +58,13 @@ func Dial(network, addr string) (*Conn, error) { // DialTimeout connects to the given address on the given network using net.DialTimeout // and then returns a new Conn for the connection. Acts like Dial but takes a timeout. func DialTimeout(network, addr string, timeout time.Duration) (*Conn, error) { - c, err := net.DialTimeout(network, addr, timeout) - if err != nil { - return nil, NewError(ErrorNetwork, err) - } - conn := NewConn(c) - conn.start() - return conn, nil + c, err := net.DialTimeout(network, addr, timeout) + if err != nil { + return nil, NewError(ErrorNetwork, err) + } + conn := NewConn(c) + conn.start() + return conn, nil } // DialTLS connects to the given address on the given network using tls.Dial @@ -79,6 +80,19 @@ func DialTLS(network, addr string, config *tls.Config) (*Conn, error) { return conn, nil } +// DialTLSDialer connects to the given address on the given network using tls.DialWithDialer +// and then returns a new Conn for the connection. +func DialTLSDialer(network, addr string, config *tls.Config, dialer *net.Dialer) (*Conn, error) { + c, err := tls.DialWithDialer(dialer, network, addr, config) + if err != nil { + return nil, NewError(ErrorNetwork, err) + } + conn := NewConn(c) + conn.isTLS = true + conn.start() + return conn, nil +} + // NewConn returns a new Conn using conn for network I/O. func NewConn(conn net.Conn) *Conn { return &Conn{ @@ -291,36 +305,36 @@ 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) - - if l.Debug { - if err := addLDAPDescriptions(packet); err != nil { - return err - } - ber.PrintPacket(packet) - } - - return nil -} + 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) + + if l.Debug { + if err := addLDAPDescriptions(packet); err != nil { + return err + } + ber.PrintPacket(packet) + } + + return nil +} |