Glue mux meta with data in one frame for Datagram

This commit is contained in:
yuhan6665 2025-04-06 21:10:34 -04:00
parent e4a5344189
commit a749050d91
2 changed files with 13 additions and 3 deletions

View File

@ -90,7 +90,8 @@ func TestRegressionOutboundLeak(t *testing.T) {
}
{
b := buf.FromBytes([]byte("hello"))
b := buf.New()
b.Write([]byte("hello"))
common.Must(muxClientDownlink.Writer.WriteMultiBuffer(buf.MultiBuffer{b}))
}
@ -102,7 +103,8 @@ func TestRegressionOutboundLeak(t *testing.T) {
}
{
b := buf.FromBytes([]byte("world"))
b := buf.New()
b.Write([]byte("world"))
common.Must(websiteUplink.Writer.WriteMultiBuffer(buf.MultiBuffer{b}))
}

View File

@ -78,9 +78,17 @@ func writeMetaWithFrame(writer buf.Writer, meta FrameMetadata, data buf.MultiBuf
if _, err := serial.WriteUint16(frame, uint16(data.Len())); err != nil {
return err
}
mb2 := make(buf.MultiBuffer, 0, len(data)+1)
mb2 = append(mb2, frame)
for _, b := range data {
if frame.Len() + b.Len() < buf.Size {
frame.Write(b.Bytes())
b.Release()
b = nil
} else {
break;
}
}
mb2 = append(mb2, data...)
return writer.WriteMultiBuffer(mb2)
}