Exemple #1
0
// Without lock
func (self *MmuxConnection) writeMessageQueue(request mqtt.Message) {
	// TODO: これそもそもmuxがあったらもうdummyか普通のか、ぐらいなような気が
	_, is_dummy := (*self.Connection).(*DummyPlug)
	if self.Connection == nil {
		// already disconnected
		return
	} else if is_dummy {
		if request.GetType() == mqtt.PACKET_TYPE_PUBLISH {
			self.OfflineQueue = append(self.OfflineQueue, request)
		}
	}

	(*self.Connection).WriteMessageQueue(request)
}
Exemple #2
0
func (self *MyConnection) writeMessage(msg codec.Message) error {
	self.logger.Debug("Write Message [%s]: %+v", msg.GetTypeAsString(), msg)
	var e error
	self.Mutex.Lock()

	self.Last = time.Now()
	if self.balancer != nil && self.balancer.PerSec > 0 {
		self.balancer.Execute(func() {
			_, e = codec.WriteMessageTo(msg, self.Writer)
		})
	} else {
		_, e = codec.WriteMessageTo(msg, self.Writer)
	}

	if e != nil {
		self.Mutex.Unlock()
		return e
	}

	self.Last = time.Now()
	self.kickFlusher()
	self.Mutex.Unlock()
	return nil
}