Skip to content

Commit

Permalink
minor cleanup and updated comments
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Feb 22, 2022
1 parent cea05a4 commit 298edd4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion server/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func (h *Hub) run() {
logs.Err.Println("hub.topicUnreg failed:", err)
}
} else {
// User is being deleted.
go h.stopTopicsForUser(unreg.forUser, reason, unreg.done)
}

Expand Down Expand Up @@ -384,7 +385,7 @@ func (h *Hub) topicsStateForUser(uid types.Uid, suspended bool) {
// 2.1 Unregister it with no further action
//
func (h *Hub) topicUnreg(sess *Session, topic string, msg *ClientComMessage, reason int) error {
now := time.Now().UTC().Round(time.Millisecond)
now := types.TimeNow()

if reason == StopDeleted {
asUid := types.ParseUserId(msg.AsUser)
Expand Down
5 changes: 3 additions & 2 deletions server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ func (s *Session) unsubAll() {

for _, sub := range s.subs {
// sub.done is the same as topic.unreg
// The whole session is being dropped.
sub.done <- &ClientComMessage{sess: s}
// The whole session is being dropped; ClientComMessage is a wrapper for session, ClientComMessage.init is false.
// keep redundant init: false so it can be searched for.
sub.done <- &ClientComMessage{sess: s, init: false}
}
}

Expand Down
7 changes: 4 additions & 3 deletions server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type Topic struct {
clientMsg chan *ClientComMessage
// Channel for receiving server messages generated on the server or received from other cluster nodes, buffered = 64.
serverMsg chan *ServerComMessage
// Channel for receiving {get}/{set} requests, buffered = 64
// Channel for receiving {get}/{set}/{del} requests, buffered = 64
meta chan *ClientComMessage
// Subscribe requests from sessions, buffered = 256
reg chan *ClientComMessage
Expand Down Expand Up @@ -1223,8 +1223,9 @@ func (t *Topic) broadcastToSessions(msg *ServerComMessage) {

// Drop "bad" sessions.
for _, sess := range dropSessions {
// The whole session is being dropped, so ClientComMessage.init is not set.
t.unregisterSession(&ClientComMessage{sess: sess})
// The whole session is being dropped, so ClientComMessage.init is false.
// keep redundant init: false so it can be searched for.
t.unregisterSession(&ClientComMessage{sess: sess, init: false})
}
}

Expand Down

0 comments on commit 298edd4

Please sign in to comment.