mirror of https://bitbucket.org/ausocean/av.git
packet.resize() now only makes a new buf when necessary.
This commit is contained in:
parent
ddd1e4ab17
commit
969e2f4fa9
|
@ -199,9 +199,7 @@ func (pkt *packet) readFrom(c *Conn) error {
|
||||||
hSize += 4
|
hSize += 4
|
||||||
}
|
}
|
||||||
|
|
||||||
if pkt.bodySize > 0 && pkt.body == nil {
|
pkt.resize(pkt.bodySize, pkt.headerType)
|
||||||
pkt.resize(pkt.bodySize, (hbuf[0]&0xc0)>>6)
|
|
||||||
}
|
|
||||||
|
|
||||||
if pkt.bodySize > c.inChunkSize {
|
if pkt.bodySize > c.inChunkSize {
|
||||||
c.log(WarnLevel, pkg+"reading large packet", "size", int(pkt.bodySize))
|
c.log(WarnLevel, pkg+"reading large packet", "size", int(pkt.bodySize))
|
||||||
|
@ -234,10 +232,12 @@ func (pkt *packet) readFrom(c *Conn) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// resize adjusts the packet's storage to accommodate a body of the given size and header type.
|
// resize adjusts the packet's storage (if necessary) to accommodate a body of the given size and header type.
|
||||||
// When headerSizeAuto is specified, the header type is computed based on packet type.
|
// When headerSizeAuto is specified, the header type is computed based on packet type.
|
||||||
func (pkt *packet) resize(size uint32, ht uint8) {
|
func (pkt *packet) resize(size uint32, ht uint8) {
|
||||||
|
if cap(pkt.buf) < fullHeaderSize+int(size) {
|
||||||
pkt.buf = make([]byte, fullHeaderSize+size)
|
pkt.buf = make([]byte, fullHeaderSize+size)
|
||||||
|
}
|
||||||
pkt.body = pkt.buf[fullHeaderSize:]
|
pkt.body = pkt.buf[fullHeaderSize:]
|
||||||
if ht != headerSizeAuto {
|
if ht != headerSizeAuto {
|
||||||
pkt.headerType = ht
|
pkt.headerType = ht
|
||||||
|
|
Loading…
Reference in New Issue