Skip to content

Commit

Permalink
Merge pull request samuel#81 from dallasmarlow/master
Browse files Browse the repository at this point in the history
Expose connection session ID
  • Loading branch information
samuel committed May 31, 2016
2 parents 6eb1b09 + e997981 commit 8b35c1c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions zk/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,16 @@ func (c *Conn) Close() {
}
}

// States returns the current state of the connection.
// State returns the current state of the connection.
func (c *Conn) State() State {
return State(atomic.LoadInt32((*int32)(&c.state)))
}

// SessionId returns the current session id of the connection.
func (c *Conn) SessionID() int64 {
return atomic.LoadInt64(&c.sessionID)
}

// SetLogger sets the logger to be used for printing errors.
// Logger is an interface provided by this package.
func (c *Conn) SetLogger(l Logger) {
Expand Down Expand Up @@ -487,15 +492,15 @@ func (c *Conn) authenticate() error {
return err
}
if r.SessionID == 0 {
c.sessionID = 0
atomic.StoreInt64(&c.sessionID, int64(0))
c.passwd = emptyPassword
c.lastZxid = 0
c.setState(StateExpired)
return ErrSessionExpired
}

atomic.StoreInt64(&c.sessionID, r.SessionID)
c.setTimeouts(r.TimeOut)
c.sessionID = r.SessionID
c.passwd = r.Passwd
c.setState(StateHasSession)

Expand Down

0 comments on commit 8b35c1c

Please sign in to comment.