Skip to content

Commit a749050

Browse files
committed
Glue mux meta with data in one frame for Datagram
1 parent e4a5344 commit a749050

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

common/mux/server_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ func TestRegressionOutboundLeak(t *testing.T) {
9090
}
9191

9292
{
93-
b := buf.FromBytes([]byte("hello"))
93+
b := buf.New()
94+
b.Write([]byte("hello"))
9495
common.Must(muxClientDownlink.Writer.WriteMultiBuffer(buf.MultiBuffer{b}))
9596
}
9697

@@ -102,7 +103,8 @@ func TestRegressionOutboundLeak(t *testing.T) {
102103
}
103104

104105
{
105-
b := buf.FromBytes([]byte("world"))
106+
b := buf.New()
107+
b.Write([]byte("world"))
106108
common.Must(websiteUplink.Writer.WriteMultiBuffer(buf.MultiBuffer{b}))
107109
}
108110

common/mux/writer.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,17 @@ func writeMetaWithFrame(writer buf.Writer, meta FrameMetadata, data buf.MultiBuf
7878
if _, err := serial.WriteUint16(frame, uint16(data.Len())); err != nil {
7979
return err
8080
}
81-
8281
mb2 := make(buf.MultiBuffer, 0, len(data)+1)
8382
mb2 = append(mb2, frame)
83+
for _, b := range data {
84+
if frame.Len() + b.Len() < buf.Size {
85+
frame.Write(b.Bytes())
86+
b.Release()
87+
b = nil
88+
} else {
89+
break;
90+
}
91+
}
8492
mb2 = append(mb2, data...)
8593
return writer.WriteMultiBuffer(mb2)
8694
}

0 commit comments

Comments
 (0)