fix(socket): 修复TCP数据处理和编解码逻辑

移除调试日志注释,修正socket编解码器中的数据丢弃逻辑。
更新TomeeSocketCodec.Decode方法,确保正确处理数据包长度并丢弃已读取的数据。
This commit is contained in:
2025-10-19 02:08:27 +08:00
parent 7de149d946
commit 7946ed190f
2 changed files with 3 additions and 1 deletions

View File

@@ -49,6 +49,7 @@ func (codec TomeeSocketCodec) Decode(c gnet.Conn) ([]byte, error) {
// handle(c)
// 先读取4字节的包长度
lenBuf, err := c.Peek(4)
if err != nil {
if errors.Is(err, io.ErrShortBuffer) {
return nil, ErrIncompletePacket
@@ -75,7 +76,7 @@ func (codec TomeeSocketCodec) Decode(c gnet.Conn) ([]byte, error) {
copy(body, buf)
// 从缓冲区中丢弃已读取的数据
_, _ = c.Discard(4 + int(bodyLen))
_, _ = c.Discard(int(bodyLen))
return body, nil
}