修正server端的connect_req和connect_rep消息没有保持同一条通路的问题

This commit is contained in:
lwch
2021-08-24 15:44:56 +08:00
parent d7a0b9309c
commit 85c20d294b

View File

@@ -159,22 +159,20 @@ func (h *Handler) msgHook(msg *network.Msg, toCli *client) {
fromCli := h.clients[from]
h.RUnlock()
switch msg.GetXType() {
case network.Msg_connect_rep:
if msg.GetCrep().GetOk() {
id := msg.GetCrep().GetId()
var pair [2]*client
if fromCli != nil {
fromCli.addLink(id)
pair[0] = fromCli
}
if toCli != nil {
toCli.addLink(id)
pair[1] = toCli
}
h.Lock()
h.links[id] = pair
h.Unlock()
case network.Msg_connect_req:
id := msg.GetCrep().GetId()
var pair [2]*client
if fromCli != nil {
fromCli.addLink(id)
pair[0] = fromCli
}
if toCli != nil {
toCli.addLink(id)
pair[1] = toCli
}
h.Lock()
h.links[id] = pair
h.Unlock()
case network.Msg_disconnect:
if fromCli != nil {
fromCli.removeLink(msg.GetXDisconnect().GetId())