Ejemplo n.º 1
0
// Write message to outbound queue.
func (c *connection) Send(message buffercache.Buffer) {
	c.mutex.Lock()
	defer c.mutex.Unlock()
	if c.isClosed {
		return
	}
	//fmt.Println("Outbound queue size", c.Idx, len(c.queue))
	if c.queue.Len() >= maxQueueSize {
		log.Println("Outbound queue overflow", c.Idx, c.queue.Len())
		return
	}
	message.Incref()
	c.queue.PushBack(message)
	c.condition.Signal()
}
Ejemplo n.º 2
0
func (r *roomWorker) Broadcast(sessionID string, message buffercache.Buffer) {
	worker := func() {
		r.mutex.RLock()
		for id, user := range r.users {
			if id == sessionID || user.Sender == nil {
				// Skip broadcast to self or non existing sender.
				continue
			}
			//fmt.Printf("%s\n", m.Message)
			user.Send(message)
		}
		r.mutex.RUnlock()
		message.Decref()
	}

	message.Incref()
	r.Run(worker)
}