Add user.stop

git-svn-id: file:///srv/svn/repo/suika/trunk@376 f0ae65fe-ee39-954e-97ec-027ff2717ef4
This commit is contained in:
contact 2020-08-10 13:03:38 +00:00
parent 676ffcc0b3
commit 1869b37956

14
user.go
View File

@ -45,6 +45,8 @@ type eventDownstreamDisconnected struct {
dc *downstreamConn
}
type eventStop struct{}
type networkHistory struct {
offlineClients map[string]uint64 // indexed by client name
ring *Ring // can be nil if there are no offline clients
@ -416,6 +418,14 @@ func (u *user) run() {
dc.logger.Printf("failed to handle message %q: %v", msg, err)
dc.Close()
}
case eventStop:
u.forEachDownstream(func(dc *downstreamConn) {
dc.Close()
})
for _, n := range u.networks {
n.stop()
}
return
default:
u.srv.Logger.Printf("received unknown event type: %T", e)
}
@ -550,3 +560,7 @@ func (u *user) updatePassword(hashed string) error {
u.User.Password = hashed
return u.srv.db.StoreUser(&u.User)
}
func (u *user) stop() {
u.events <- eventStop{}
}