|
|
|
@ -106,8 +106,8 @@ func (h *hub) Run() { |
|
|
|
return true |
|
|
|
return true |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// Return message to pool after all clients processed
|
|
|
|
// DON'T return message to pool - let GC handle it
|
|
|
|
h.messagePool.Put(message) |
|
|
|
// h.messagePool.Put(message)
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -139,18 +139,17 @@ func (c *Client) readPump() { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get a message buffer from the pool
|
|
|
|
// Create a new message buffer instead of reusing from pool
|
|
|
|
message := c.hub.messagePool.Get().([]byte) |
|
|
|
message := make([]byte, len(messageBytes)) |
|
|
|
message = message[:len(messageBytes)] |
|
|
|
|
|
|
|
copy(message, messageBytes) |
|
|
|
copy(message, messageBytes) |
|
|
|
|
|
|
|
|
|
|
|
// Non-blocking broadcast
|
|
|
|
// Non-blocking broadcast
|
|
|
|
select { |
|
|
|
select { |
|
|
|
case c.hub.broadcast <- message: |
|
|
|
case c.hub.broadcast <- message: |
|
|
|
// Message will be returned to pool by hub.Run()
|
|
|
|
// Message will be sent to all clients
|
|
|
|
default: |
|
|
|
default: |
|
|
|
// Broadcast buffer full, return message to pool and drop
|
|
|
|
// Broadcast buffer full, drop message
|
|
|
|
c.hub.messagePool.Put(message) |
|
|
|
fmt.Printf("Broadcast buffer full, dropping message\n") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|