Compare commits

4 Commits

Author SHA1 Message Date
Marc Magnin cf77eaf346 remove subscriptions when a client disconnect 2019-01-18 14:38:51 +01:00
Marc Magnin 7c4d7a0c06 simple fix 2019-01-03 21:23:14 +01:00
joyz 2b56664d85 remove no use 2018-12-27 21:22:32 +08:00
joy.zhou 7547ad3bdc Restruct (#34)
* modify

* remove

* modify

* modify

* remove no use

* add online/offline notification

* modify

* format log

* add reference
2018-12-26 14:51:13 +08:00
2 changed files with 12 additions and 5 deletions
+2
View File
@@ -617,7 +617,9 @@ func (b *Broker) removeClient(c *client) {
func (b *Broker) PublishMessage(packet *packets.PublishPacket) {
var subs []interface{}
var qoss []byte
b.mu.Lock()
err := b.topicsMgr.Subscribers([]byte(packet.TopicName), packet.Qos, &subs, &qoss)
b.mu.Unlock()
if err != nil {
log.Error("search sub client error, ", zap.Error(err))
return
+10 -5
View File
@@ -51,11 +51,6 @@ type client struct {
rmsgs []*packets.PublishPacket
}
type subInfo struct {
sub *subscription
num int
}
type subscription struct {
client *client
topic string
@@ -117,6 +112,14 @@ func (c *client) readLoop() {
log.Error("read packet error: ", zap.Error(err), zap.String("ClientID", c.info.clientID))
msg := &Message{client: c, packet: DisconnectdPacket}
b.SubmitWork(msg)
// remove subscriptions related to that client
for topic, sub := range c.subMap {
t := []byte(topic)
c.topicsMgr.Unsubscribe(t, sub)
c.session.RemoveTopic(topic)
delete(c.subMap, topic)
}
return
}
@@ -218,7 +221,9 @@ func (c *client) ProcessPublishMessage(packet *packets.PublishPacket) {
}
}
c.mu.Lock()
err := c.topicsMgr.Subscribers([]byte(packet.TopicName), packet.Qos, &c.subs, &c.qoss)
c.mu.Unlock()
if err != nil {
log.Error("Error retrieving subscribers list: ", zap.String("ClientID", c.info.clientID))
return