mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-10-07 16:51:47 +00:00
Thread-safe access to online flag
This commit is contained in:
parent
a117e1e3cb
commit
4e932d1e26
3 changed files with 6 additions and 5 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"dev.narayana.im/narayana/telegabber/calls/audio/ntgadapter"
|
"dev.narayana.im/narayana/telegabber/calls/audio/ntgadapter"
|
||||||
|
|
@ -133,7 +134,7 @@ type Client struct {
|
||||||
resources map[string]bool
|
resources map[string]bool
|
||||||
content *config.TelegramContentConfig
|
content *config.TelegramContentConfig
|
||||||
cache *cache.Cache
|
cache *cache.Cache
|
||||||
online bool
|
online atomic.Bool
|
||||||
|
|
||||||
loginWizard *loginWizardMetadata
|
loginWizard *loginWizardMetadata
|
||||||
loginStage LoginStage
|
loginStage LoginStage
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) (strin
|
||||||
|
|
||||||
c.Session.Login = ""
|
c.Session.Login = ""
|
||||||
c.wizardStageOrPrompt(LoginStageCancel, "")
|
c.wizardStageOrPrompt(LoginStageCancel, "")
|
||||||
c.online = false
|
c.online.Store(false)
|
||||||
// cleanup
|
// cleanup
|
||||||
case "cleanup":
|
case "cleanup":
|
||||||
c.unsubscribeFromAll()
|
c.unsubscribeFromAll()
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ func (c *Client) Connect(resource string, wasSessionLoginEmpty bool) error {
|
||||||
|
|
||||||
go c.updateHandler()
|
go c.updateHandler()
|
||||||
log.Warn("Going online")
|
log.Warn("Going online")
|
||||||
c.online = true
|
c.online.Store(true)
|
||||||
c.locks.authorizationReady.Unlock()
|
c.locks.authorizationReady.Unlock()
|
||||||
c.addResource(resource)
|
c.addResource(resource)
|
||||||
|
|
||||||
|
|
@ -327,7 +327,7 @@ func (c *Client) forceClose() {
|
||||||
defer c.locks.authorizerReadLock.Unlock()
|
defer c.locks.authorizerReadLock.Unlock()
|
||||||
defer c.locks.authorizerWriteLock.Unlock()
|
defer c.locks.authorizerWriteLock.Unlock()
|
||||||
|
|
||||||
c.online = false
|
c.online.Store(false)
|
||||||
c.authorizer = nil
|
c.authorizer = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -375,5 +375,5 @@ func (c *Client) cancelAuth() {
|
||||||
|
|
||||||
// Online checks if the updates listener is alive
|
// Online checks if the updates listener is alive
|
||||||
func (c *Client) Online() bool {
|
func (c *Client) Online() bool {
|
||||||
return c.online
|
return c.online.Load()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue