koushin: rename Session.locker to imapLocker
This commit is contained in:
parent
85c01b87a9
commit
c0b4998b38
1 changed files with 10 additions and 10 deletions
20
session.go
20
session.go
|
@ -49,8 +49,8 @@ type Session struct {
|
||||||
pings chan struct{}
|
pings chan struct{}
|
||||||
timer *time.Timer
|
timer *time.Timer
|
||||||
|
|
||||||
locker sync.Mutex
|
imapLocker sync.Mutex
|
||||||
imapConn *imapclient.Client // protected by locker, can be nil
|
imapConn *imapclient.Client // protected by locker, can be nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) ping() {
|
func (s *Session) ping() {
|
||||||
|
@ -65,8 +65,8 @@ func (s *Session) Username() string {
|
||||||
// DoIMAP executes an IMAP operation on this session. The IMAP client can only
|
// DoIMAP executes an IMAP operation on this session. The IMAP client can only
|
||||||
// be used from inside f.
|
// be used from inside f.
|
||||||
func (s *Session) DoIMAP(f func(*imapclient.Client) error) error {
|
func (s *Session) DoIMAP(f func(*imapclient.Client) error) error {
|
||||||
s.locker.Lock()
|
s.imapLocker.Lock()
|
||||||
defer s.locker.Unlock()
|
defer s.imapLocker.Unlock()
|
||||||
|
|
||||||
if s.imapConn == nil {
|
if s.imapConn == nil {
|
||||||
var err error
|
var err error
|
||||||
|
@ -214,17 +214,17 @@ func (sm *SessionManager) Put(username, password string) (*Session, error) {
|
||||||
alive := true
|
alive := true
|
||||||
for alive {
|
for alive {
|
||||||
var loggedOut <-chan struct{}
|
var loggedOut <-chan struct{}
|
||||||
s.locker.Lock()
|
s.imapLocker.Lock()
|
||||||
if s.imapConn != nil {
|
if s.imapConn != nil {
|
||||||
loggedOut = s.imapConn.LoggedOut()
|
loggedOut = s.imapConn.LoggedOut()
|
||||||
}
|
}
|
||||||
s.locker.Unlock()
|
s.imapLocker.Unlock()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-loggedOut:
|
case <-loggedOut:
|
||||||
s.locker.Lock()
|
s.imapLocker.Lock()
|
||||||
s.imapConn = nil
|
s.imapConn = nil
|
||||||
s.locker.Unlock()
|
s.imapLocker.Unlock()
|
||||||
case <-s.pings:
|
case <-s.pings:
|
||||||
if !timer.Stop() {
|
if !timer.Stop() {
|
||||||
<-timer.C
|
<-timer.C
|
||||||
|
@ -239,11 +239,11 @@ func (sm *SessionManager) Put(username, password string) (*Session, error) {
|
||||||
|
|
||||||
timer.Stop()
|
timer.Stop()
|
||||||
|
|
||||||
s.locker.Lock()
|
s.imapLocker.Lock()
|
||||||
if s.imapConn != nil {
|
if s.imapConn != nil {
|
||||||
s.imapConn.Logout()
|
s.imapConn.Logout()
|
||||||
}
|
}
|
||||||
s.locker.Unlock()
|
s.imapLocker.Unlock()
|
||||||
|
|
||||||
sm.locker.Lock()
|
sm.locker.Lock()
|
||||||
delete(sm.sessions, token)
|
delete(sm.sessions, token)
|
||||||
|
|
Loading…
Reference in a new issue