diff options
Diffstat (limited to 'vendor/github.com/go-ldap/ldap/conn.go')
-rw-r--r-- | vendor/github.com/go-ldap/ldap/conn.go | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/vendor/github.com/go-ldap/ldap/conn.go b/vendor/github.com/go-ldap/ldap/conn.go index e701a9b66..b5bd99adb 100644 --- a/vendor/github.com/go-ldap/ldap/conn.go +++ b/vendor/github.com/go-ldap/ldap/conn.go @@ -11,7 +11,6 @@ import ( "log" "net" "sync" - "sync/atomic" "time" "gopkg.in/asn1-ber.v1" @@ -83,8 +82,8 @@ const ( type Conn struct { conn net.Conn isTLS bool - closeCount uint32 - closeErr atomicValue + isClosing bool + closeErr error isStartingTLS bool Debug debugging chanConfirm chan bool @@ -159,20 +158,10 @@ func (l *Conn) Start() { l.wgClose.Add(1) } -// isClosing returns whether or not we're currently closing. -func (l *Conn) isClosing() bool { - return atomic.LoadUint32(&l.closeCount) > 0 -} - -// setClosing sets the closing value to true -func (l *Conn) setClosing() { - atomic.AddUint32(&l.closeCount, 1) -} - // Close closes the connection. func (l *Conn) Close() { l.once.Do(func() { - l.setClosing() + l.isClosing = true l.wgSender.Wait() l.Debug.Printf("Sending quit message and waiting for confirmation") @@ -269,7 +258,7 @@ func (l *Conn) sendMessage(packet *ber.Packet) (*messageContext, error) { } func (l *Conn) sendMessageWithFlags(packet *ber.Packet, flags sendMessageFlags) (*messageContext, error) { - if l.isClosing() { + if l.isClosing { return nil, NewError(ErrorNetwork, errors.New("ldap: connection closed")) } l.messageMutex.Lock() @@ -308,7 +297,7 @@ func (l *Conn) sendMessageWithFlags(packet *ber.Packet, flags sendMessageFlags) func (l *Conn) finishMessage(msgCtx *messageContext) { close(msgCtx.done) - if l.isClosing() { + if l.isClosing { return } @@ -327,7 +316,7 @@ func (l *Conn) finishMessage(msgCtx *messageContext) { } func (l *Conn) sendProcessMessage(message *messagePacket) bool { - if l.isClosing() { + if l.isClosing { return false } l.wgSender.Add(1) @@ -344,8 +333,8 @@ func (l *Conn) processMessages() { for messageID, msgCtx := range l.messageContexts { // If we are closing due to an error, inform anyone who // is waiting about the error. - if l.isClosing() && l.closeErr.Load() != nil { - msgCtx.sendResponse(&PacketResponse{Error: l.closeErr.Load().(error)}) + if l.isClosing && l.closeErr != nil { + msgCtx.sendResponse(&PacketResponse{Error: l.closeErr}) } l.Debug.Printf("Closing channel for MessageID %d", messageID) close(msgCtx.responses) @@ -408,7 +397,7 @@ func (l *Conn) processMessages() { if msgCtx, ok := l.messageContexts[message.MessageID]; ok { msgCtx.sendResponse(&PacketResponse{message.Packet, nil}) } else { - log.Printf("Received unexpected message %d, %v", message.MessageID, l.isClosing()) + log.Printf("Received unexpected message %d, %v", message.MessageID, l.isClosing) ber.PrintPacket(message.Packet) } case MessageTimeout: @@ -450,8 +439,8 @@ func (l *Conn) reader() { packet, err := ber.ReadPacket(l.conn) if err != nil { // A read error is expected here if we are closing the connection... - if !l.isClosing() { - l.closeErr.Store(fmt.Errorf("unable to read LDAP response packet: %s", err)) + if !l.isClosing { + l.closeErr = fmt.Errorf("unable to read LDAP response packet: %s", err) l.Debug.Printf("reader error: %s", err.Error()) } return |