only allocate extra buffer when extra header is required

This commit is contained in:
xtaci
2017-03-28 14:25:48 +08:00
parent 79b4c78185
commit 4bdcbcdbeb
+6 -1
View File
@@ -122,7 +122,6 @@ func newUDPSession(conv uint32, dataShards, parityShards int, l *Listener, conn
sess.l = l
sess.block = block
sess.recvbuf = make([]byte, mtuLimit)
sess.ext = make([]byte, mtuLimit)
// FEC initialization
sess.fecDecoder = newFECDecoder(rxFECMulti*(dataShards+parityShards), dataShards, parityShards)
@@ -140,6 +139,12 @@ func newUDPSession(conv uint32, dataShards, parityShards int, l *Listener, conn
sess.headerSize += fecHeaderSizePlus2
}
// only allocate extended packet buffer
// when the extra header is required
if sess.headerSize > 0 {
sess.ext = make([]byte, mtuLimit)
}
sess.kcp = NewKCP(conv, func(buf []byte, size int) {
if size >= IKCP_OVERHEAD {
sess.output(buf[:size])