종료시 컨넥션 정리

This commit is contained in:
2023-07-27 21:55:28 +09:00
parent 854084d819
commit 8ea2a698ce

View File

@ -372,12 +372,26 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
return room
}
defer func() {
for _, conn := range entireConns {
var roomnames []string
for _, room := range conn.joinedRooms {
roomnames = append(roomnames, room.name)
}
bt, _ := json.Marshal(roomnames)
sh.callReceiver.OnClientMessageReceived(conn.sender, Disconnected, bytes.NewBuffer(bt))
}
}()
// 유저에게서 온 메세지, 소켓 연결/해체 처리
for {
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
buffer.Reset()
select {
case <-ctx.Done():
return
case destroyedRoom := <-roomDestroyChan:
delete(rooms, destroyedRoom)
go sh.callReceiver.OnRoomDestroyed(sh.region, destroyedRoom)