Skip to content

Commit 0216f66

Browse files
committed
Refactor czar
1 parent e08cd5a commit 0216f66

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

protocol/czar/engine.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ import (
2727
// To open a stream:
2828
//
2929
// +-----+-----+-----+-----+
30-
// | Sid | 0 | Rsv |
30+
// | 0 | Sid | Rsv |
3131
// +-----+-----+-----+-----+
3232
//
3333
// Both server and client can push data to each other.
3434
//
3535
// +-----+-----+-----+-----+-----+-----+
36-
// | Sid | 1 | Len | Msg |
36+
// | 1 | Sid | Len | Msg |
3737
// +-----+-----+-----+-----+-----+-----+
3838
//
3939
// Close the specified stream.
4040
//
4141
// +-----+-----+-----+-----+
42-
// | Sid | 2 | 0/1 | Rsv |
42+
// | 2 | Sid | 0/1 | Rsv |
4343
// +-----+-----+-----+-----+
4444
//
4545
// Keep alive probe and reply.
4646
//
4747
// +-----+-----+-----+-----+
48-
// | 0x0 | 3 | 0/1 | Rsv |
48+
// | 3 | 0x0 | 0/1 | Rsv |
4949
// +-----+-----+-----+-----+
5050

5151
// Conf is acting as package level configuration.

protocol/czar/mux.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (s *Stream) Close() error {
2828
s.wer.Put(io.ErrClosedPipe)
2929
s.zo0.Do(func() {
3030
s.mux.pri.Pri(0, func() error {
31-
s.mux.con.Write([]byte{s.idx, 0x02, 0x00, 0x00})
31+
s.mux.con.Write([]byte{0x02, s.idx, 0x00, 0x00})
3232
return nil
3333
})
3434
})
@@ -41,7 +41,7 @@ func (s *Stream) Esolc() error {
4141
s.wer.Put(io.ErrClosedPipe)
4242
s.zo0.Do(func() {
4343
s.mux.pri.Pri(0, func() error {
44-
s.mux.con.Write([]byte{s.idx, 0x02, 0x01, 0x00})
44+
s.mux.con.Write([]byte{0x02, s.idx, 0x01, 0x00})
4545
return nil
4646
})
4747
})
@@ -98,8 +98,8 @@ func (s *Stream) Write(p []byte) (int, error) {
9898
case len(p) >= 0:
9999
return n, nil
100100
}
101-
buf[0] = s.idx
102-
buf[1] = 0x01
101+
buf[0] = 0x01
102+
buf[1] = s.idx
103103
binary.BigEndian.PutUint16(buf[2:4], uint16(l))
104104
copy(buf[4:], p[:l])
105105
p = p[l:]
@@ -177,7 +177,7 @@ func (m *Mux) Open() (*Stream, error) {
177177
return nil, err
178178
}
179179
err = m.pri.Pri(0, func() error {
180-
return doa.Err(m.con.Write([]byte{idx, 0x00, 0x00, 0x00}))
180+
return doa.Err(m.con.Write([]byte{0x00, idx, 0x00, 0x00}))
181181
})
182182
if err != nil {
183183
m.idp.Put(idx)
@@ -200,7 +200,7 @@ func (m *Mux) Recv() {
200200
old *Stream
201201
prb = time.AfterFunc(Conf.IdleProbeDuration, func() {
202202
if m.pri.Pri(0, func() error {
203-
return doa.Err(m.con.Write([]byte{0x00, 0x03, 0x00, 0x00}))
203+
return doa.Err(m.con.Write([]byte{0x03, 0x00, 0x00, 0x00}))
204204
}) != nil {
205205
m.Close()
206206
}
@@ -218,8 +218,8 @@ func (m *Mux) Recv() {
218218
m.rer.Put(err)
219219
break
220220
}
221-
idx = buf[0]
222-
cmd = buf[1]
221+
cmd = buf[0]
222+
idx = buf[1]
223223
switch {
224224
case cmd == 0x00:
225225
// Make sure the stream has been closed properly.
@@ -257,7 +257,7 @@ func (m *Mux) Recv() {
257257
switch buf[2] {
258258
case 0x00:
259259
m.pri.Pri(0, func() error {
260-
return doa.Err(m.con.Write([]byte{0x00, 0x03, 0x01, 0x00}))
260+
return doa.Err(m.con.Write([]byte{0x03, 0x00, 0x01, 0x00}))
261261
})
262262
case 0x01:
263263
}

0 commit comments

Comments
 (0)