fix: 修复 CMPP 协议字段容量与版本兼容性
CSS quality / css-quality (push) Has been cancelled

This commit is contained in:
hectorzhao
2026-09-20 15:49:37 +08:00
parent b24cd7c08d
commit 001d5f2cbd
37 changed files with 1933 additions and 295 deletions
+22 -7
View File
@@ -15,6 +15,7 @@ package cmpp
import (
"errors"
"fmt"
"net"
"time"
)
@@ -72,7 +73,7 @@ func (cli *Client) Connect(servAddr, user, password string, timeout time.Duratio
}
var ok bool
var status uint8
var status uint32
if cli.typ == V20 || cli.typ == V21 {
var rsp *Cmpp2ConnRspPkt
rsp, ok = p.(*Cmpp2ConnRspPkt)
@@ -80,7 +81,7 @@ func (cli *Client) Connect(servAddr, user, password string, timeout time.Duratio
err = ErrRespNotMatch
return err
}
status = rsp.Status
status = uint32(rsp.Status)
} else {
var rsp *Cmpp3ConnRspPkt
rsp, ok = p.(*Cmpp3ConnRspPkt)
@@ -88,15 +89,16 @@ func (cli *Client) Connect(servAddr, user, password string, timeout time.Duratio
err = ErrRespNotMatch
return err
}
status = uint8(rsp.Status)
status = rsp.Status
}
if status != 0 {
if status <= ErrnoConnOthers { //ErrnoConnOthers = 5
err = ConnRspStatusErrMap[status]
if status <= uint32(ErrnoConnOthers) { //ErrnoConnOthers = 5
err = ConnRspStatusErrMap[uint8(status)]
} else {
err = ConnRspStatusErrMap[ErrnoConnOthers]
}
err = fmt.Errorf("CMPP CONNECT_RESP status=%d: %w", status, err)
return err
}
@@ -112,8 +114,21 @@ func (cli *Client) Disconnect() {
// SendReqPkt pack the cmpp request packet structure and send it to the other peer.
func (cli *Client) SendReqPkt(packet Packer) (uint32, error) {
seq := <-cli.conn.SeqId
return seq, cli.conn.SendPkt(packet, seq)
return cli.SendReqPktAvailable(packet, nil)
}
// The caller holds its pending-request lock until the returned sequence is registered.
// A wrapped sequence must never replace an outstanding request.
func (cli *Client) SendReqPktAvailable(packet Packer, available func(uint32) bool) (uint32, error) {
for {
seq, ok := <-cli.conn.SeqId
if !ok {
return 0, ErrConnIsClosed
}
if available == nil || available(seq) {
return seq, cli.conn.SendPkt(packet, seq)
}
}
}
// SendRspPkt pack the cmpp response packet structure and send it to the other peer.