Skip to content

Commit 84a8b49

Browse files
committed
Make packet size as a configuration item
1 parent 491bb4b commit 84a8b49

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

protocol/czar/engine.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ import (
4545
var Conf = struct {
4646
// The newly created stream has a higher write priority.
4747
FastWriteDuration time.Duration
48+
// Packet size. Since the size of the packet header is 4, this value must be greater than 4. If the value is too
49+
// small, the transmission efficiency will be reduced, and if it is too large, the concurrency capability of mux
50+
// will be reduced.
51+
PacketSize int
4852
}{
4953
FastWriteDuration: time.Second * 8,
54+
PacketSize: 2048,
5055
}
5156

5257
// Server implemented the czar protocol.

protocol/czar/mux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ func (s *Stream) Write(p []byte) (int, error) {
9191
)
9292
for {
9393
switch {
94-
case len(p) >= 2044:
95-
buf = make([]byte, 2048)
96-
l = 2044
94+
case len(p) >= Conf.PacketSize-4:
95+
buf = make([]byte, Conf.PacketSize)
96+
l = Conf.PacketSize - 4
9797
case len(p) >= 1:
9898
buf = make([]byte, 4+len(p))
9999
l = len(p)

0 commit comments

Comments
 (0)