Skip to content

Commit b032ed7

Browse files
committed
Add stream pool configuration for dynamic stream management
1 parent 652f689 commit b032ed7

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

protocol/czar/engine.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ var Conf = struct {
5858
// small, the transmission efficiency will be reduced, and if it is too large, the concurrency capability of mux
5959
// will be reduced.
6060
PacketSize int
61+
StreamPool int
6162
}{
6263
IdleProbeDuration: time.Second * 32,
6364
IdleReplyDuration: time.Second * 48,
6465
PacketSize: 2048,
66+
StreamPool: 256,
6567
}
6668

6769
// Server implemented the czar protocol.

protocol/czar/mux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,15 @@ func NewMux(conn io.ReadWriteCloser) *Mux {
296296
idp: NewSip(),
297297
pri: priority.NewPriority(2),
298298
rer: NewErr(),
299-
usb: make([]*Stream, 256),
299+
usb: make([]*Stream, Conf.StreamPool),
300300
}
301301
return mux
302302
}
303303

304304
// NewMuxServer returns a new MuxServer.
305305
func NewMuxServer(conn io.ReadWriteCloser) *Mux {
306306
mux := NewMux(conn)
307-
for i := range 256 {
307+
for i := range Conf.StreamPool {
308308
mux.usb[i] = NewWither(uint8(i), mux)
309309
}
310310
go mux.Recv()

protocol/czar/sip.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ func (s *Sip) Get() (uint8, error) {
2020
s.m.Lock()
2121
defer s.m.Unlock()
2222
n := big.NewInt(0).Not(s.i)
23-
m := n.TrailingZeroBits()
24-
if m == 256 {
23+
m := int(n.TrailingZeroBits())
24+
if m == Conf.StreamPool {
2525
return 0, errors.New("daze: out of stream")
2626
}
27-
s.i.SetBit(s.i, int(m), 1)
27+
s.i.SetBit(s.i, m, 1)
2828
return uint8(m), nil
2929
}
3030

protocol/czar/sip_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func TestProtocolCzarSip(t *testing.T) {
1010
sid := NewSip()
11-
for i := range 256 {
11+
for i := range Conf.StreamPool {
1212
doa.Doa(doa.Try(sid.Get()) == uint8(i))
1313
}
1414
doa.Doa(doa.Err(sid.Get()) != nil)

0 commit comments

Comments
 (0)