summaryrefslogtreecommitdiffstats
path: root/conn.go
diff options
context:
space:
mode:
authorNed <ned@appliedtrust.com>2016-01-04 20:55:27 +0100
committerNed <ned@appliedtrust.com>2016-01-04 20:55:27 +0100
commit061cdfc6fadb9662021dff00daa86f3f2e5eee89 (patch)
treef0f09979318dfaba4e289f9edc20bbcc715b08ef /conn.go
parentFixed bug with SizeLimit=1 (diff)
parentDialTLSDialer added && gofmt (diff)
downloadldap-061cdfc6fadb9662021dff00daa86f3f2e5eee89.tar
ldap-061cdfc6fadb9662021dff00daa86f3f2e5eee89.tar.gz
ldap-061cdfc6fadb9662021dff00daa86f3f2e5eee89.tar.bz2
ldap-061cdfc6fadb9662021dff00daa86f3f2e5eee89.tar.lz
ldap-061cdfc6fadb9662021dff00daa86f3f2e5eee89.tar.xz
ldap-061cdfc6fadb9662021dff00daa86f3f2e5eee89.tar.zst
ldap-061cdfc6fadb9662021dff00daa86f3f2e5eee89.zip
Diffstat (limited to 'conn.go')
-rw-r--r--conn.go88
1 files changed, 51 insertions, 37 deletions
diff --git a/conn.go b/conn.go
index 9f40317..253e58e 100644
--- a/conn.go
+++ b/conn.go
@@ -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
+}