3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 20:09:41 +01:00

persist last seen on shutdown

This commit is contained in:
Shivaram Lingamneni 2020-06-29 00:30:27 -04:00
parent a38d375bda
commit 0f04acaa40
2 changed files with 24 additions and 3 deletions

View File

@ -1724,7 +1724,7 @@ func (client *Client) wakeWriter() {
func (client *Client) writeLoop() { func (client *Client) writeLoop() {
for { for {
client.performWrite() client.performWrite(0)
client.writerSemaphore.Release() client.writerSemaphore.Release()
client.stateMutex.RLock() client.stateMutex.RLock()
@ -1737,9 +1737,9 @@ func (client *Client) writeLoop() {
} }
} }
func (client *Client) performWrite() { func (client *Client) performWrite(additionalDirtyBits uint) {
client.stateMutex.Lock() client.stateMutex.Lock()
dirtyBits := client.dirtyBits dirtyBits := client.dirtyBits | additionalDirtyBits
client.dirtyBits = 0 client.dirtyBits = 0
account := client.account account := client.account
client.stateMutex.Unlock() client.stateMutex.Unlock()
@ -1775,3 +1775,21 @@ func (client *Client) performWrite() {
client.server.accounts.saveModes(account, uModes) client.server.accounts.saveModes(account, uModes)
} }
} }
// Blocking store; see Channel.Store and Socket.BlockingWrite
func (client *Client) Store(dirtyBits uint) (err error) {
defer func() {
client.stateMutex.Lock()
isDirty := client.dirtyBits != 0
client.stateMutex.Unlock()
if isDirty {
client.wakeWriter()
}
}()
client.writerSemaphore.Acquire()
defer client.writerSemaphore.Release()
client.performWrite(dirtyBits)
return nil
}

View File

@ -116,6 +116,9 @@ func (server *Server) Shutdown() {
//TODO(dan): Make sure we disallow new nicks //TODO(dan): Make sure we disallow new nicks
for _, client := range server.clients.AllClients() { for _, client := range server.clients.AllClients() {
client.Notice("Server is shutting down") client.Notice("Server is shutting down")
if client.AlwaysOn() {
client.Store(IncludeLastSeen)
}
} }
if err := server.store.Close(); err != nil { if err := server.store.Close(); err != nil {