mirror of
https://github.com/duanhf2012/origin.git
synced 2026-03-03 12:28:31 +08:00
优化包头
This commit is contained in:
@@ -89,7 +89,7 @@ func (p *MsgParser) Read(conn *TCPConn) ([]byte, error) {
|
|||||||
msgLen = binary.BigEndian.Uint32(bufMsgLen)
|
msgLen = binary.BigEndian.Uint32(bufMsgLen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
msgLen -= 2
|
|
||||||
|
|
||||||
// check len
|
// check len
|
||||||
if msgLen > p.maxMsgLen {
|
if msgLen > p.maxMsgLen {
|
||||||
@@ -97,7 +97,8 @@ func (p *MsgParser) Read(conn *TCPConn) ([]byte, error) {
|
|||||||
} else if msgLen < p.minMsgLen {
|
} else if msgLen < p.minMsgLen {
|
||||||
return nil, errors.New("message too short")
|
return nil, errors.New("message too short")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msgLen -= 2
|
||||||
// data
|
// data
|
||||||
msgData := make([]byte, msgLen)
|
msgData := make([]byte, msgLen)
|
||||||
if _, err := io.ReadFull(conn, msgData); err != nil {
|
if _, err := io.ReadFull(conn, msgData); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user