conn에 msg를 쓰는 쓰레드 단일화
This commit is contained in:
@ -14,16 +14,18 @@ type room struct {
|
||||
messageChan chan *UpstreamMessage
|
||||
name string
|
||||
destroyChan chan<- string
|
||||
sendMsgChan chan<- send_msg_queue_elem
|
||||
}
|
||||
|
||||
// 만약 destroyChan가 nil이면 room이 비어도 파괴되지 않는다. 영구 유지되는 room
|
||||
func makeRoom(name string, destroyChan chan<- string) *room {
|
||||
func makeRoom(name string, destroyChan chan<- string, sendMsgChan chan<- send_msg_queue_elem) *room {
|
||||
return &room{
|
||||
inChan: make(chan *wsconn, 10),
|
||||
outChan: make(chan *wsconn, 10),
|
||||
messageChan: make(chan *UpstreamMessage, 100),
|
||||
name: name,
|
||||
destroyChan: destroyChan,
|
||||
sendMsgChan: sendMsgChan,
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +87,11 @@ func (r *room) loop(ctx context.Context, conns *map[string]*wsconn) (normalEnd b
|
||||
bt, _ := json.Marshal(ds)
|
||||
|
||||
for _, conn := range *conns {
|
||||
conn.Conn.WriteMessage(websocket.TextMessage, bt)
|
||||
r.sendMsgChan <- send_msg_queue_elem{
|
||||
to: conn,
|
||||
mt: websocket.TextMessage,
|
||||
msg: bt,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user