Skip to content

Commit 7e74b98

Browse files
committed
Optimize fast write strategy
1 parent 6b3538c commit 7e74b98

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

protocol/czar/mux.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package czar
22

33
import (
4+
"cmp"
45
"encoding/binary"
56
"io"
67
"sync"
@@ -12,7 +13,7 @@ import (
1213

1314
// A Stream managed by the multiplexer.
1415
type Stream struct {
15-
fwu time.Time
16+
cat time.Time
1617
idx uint8
1718
mux *Mux
1819
rbf []byte
@@ -87,7 +88,7 @@ func (s *Stream) Write(p []byte) (int, error) {
8788
buf []byte
8889
l = 0
8990
n = 0
90-
z = 1
91+
z = 0
9192
)
9293
for {
9394
switch {
@@ -105,9 +106,9 @@ func (s *Stream) Write(p []byte) (int, error) {
105106
binary.BigEndian.PutUint16(buf[2:4], uint16(l))
106107
copy(buf[4:], p[:l])
107108
p = p[l:]
108-
if time.Now().After(s.fwu) {
109-
z = 2
110-
}
109+
z = 2 - max(cmp.Compare(Conf.FastWriteDuration-time.Since(s.cat), 0), 0)
110+
doa.Doa(z >= 1)
111+
doa.Doa(z <= 2)
111112
err := s.mux.pri.Pri(z, func() error {
112113
if err := s.wer.Get(); err != nil {
113114
return err
@@ -129,7 +130,7 @@ func (s *Stream) Write(p []byte) (int, error) {
129130
// NewStream returns a new Stream.
130131
func NewStream(idx uint8, mux *Mux) *Stream {
131132
return &Stream{
132-
fwu: time.Now().Add(Conf.FastWriteDuration),
133+
cat: time.Now(),
133134
idx: idx,
134135
mux: mux,
135136
rbf: make([]byte, 0),

0 commit comments

Comments
 (0)