mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 11:59:40 +01:00
persist last seen on shutdown
This commit is contained in:
parent
a38d375bda
commit
0f04acaa40
@ -1724,7 +1724,7 @@ func (client *Client) wakeWriter() {
|
||||
|
||||
func (client *Client) writeLoop() {
|
||||
for {
|
||||
client.performWrite()
|
||||
client.performWrite(0)
|
||||
client.writerSemaphore.Release()
|
||||
|
||||
client.stateMutex.RLock()
|
||||
@ -1737,9 +1737,9 @@ func (client *Client) writeLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
func (client *Client) performWrite() {
|
||||
func (client *Client) performWrite(additionalDirtyBits uint) {
|
||||
client.stateMutex.Lock()
|
||||
dirtyBits := client.dirtyBits
|
||||
dirtyBits := client.dirtyBits | additionalDirtyBits
|
||||
client.dirtyBits = 0
|
||||
account := client.account
|
||||
client.stateMutex.Unlock()
|
||||
@ -1775,3 +1775,21 @@ func (client *Client) performWrite() {
|
||||
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
|
||||
}
|
||||
|
@ -116,6 +116,9 @@ func (server *Server) Shutdown() {
|
||||
//TODO(dan): Make sure we disallow new nicks
|
||||
for _, client := range server.clients.AllClients() {
|
||||
client.Notice("Server is shutting down")
|
||||
if client.AlwaysOn() {
|
||||
client.Store(IncludeLastSeen)
|
||||
}
|
||||
}
|
||||
|
||||
if err := server.store.Close(); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user