packer/rpc: make servers use odd seqnums, clients even [GH-727]
This commit is contained in:
parent
54e96d100a
commit
f06cd56e72
|
@ -17,7 +17,7 @@ type Client struct {
|
|||
}
|
||||
|
||||
func NewClient(rwc io.ReadWriteCloser) (*Client, error) {
|
||||
result, err := NewClientWithMux(NewMuxConn(rwc), 0)
|
||||
result, err := NewClientWithMux(NewMuxConn(rwc, 0), 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -41,11 +41,12 @@ const (
|
|||
)
|
||||
|
||||
// Create a new MuxConn around any io.ReadWriteCloser.
|
||||
func NewMuxConn(rwc io.ReadWriteCloser) *MuxConn {
|
||||
func NewMuxConn(rwc io.ReadWriteCloser, startId uint32) *MuxConn {
|
||||
m := &MuxConn{
|
||||
rwc: rwc,
|
||||
streams: make(map[uint32]*Stream),
|
||||
doneCh: make(chan struct{}),
|
||||
curId: startId,
|
||||
}
|
||||
|
||||
go m.cleaner()
|
||||
|
@ -145,7 +146,7 @@ func (m *MuxConn) NextId() uint32 {
|
|||
|
||||
for {
|
||||
result := m.curId
|
||||
m.curId++
|
||||
m.curId += 2
|
||||
if _, ok := m.streams[result]; !ok {
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func testMux(t *testing.T) (client *MuxConn, server *MuxConn) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
server = NewMuxConn(conn)
|
||||
server = NewMuxConn(conn, 1)
|
||||
}()
|
||||
|
||||
// Client side
|
||||
|
@ -41,7 +41,7 @@ func testMux(t *testing.T) (client *MuxConn, server *MuxConn) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
client = NewMuxConn(conn)
|
||||
client = NewMuxConn(conn, 0)
|
||||
|
||||
// Wait for the server
|
||||
<-doneCh
|
||||
|
@ -241,7 +241,14 @@ func TestMuxConnNextId(t *testing.T) {
|
|||
a := client.NextId()
|
||||
b := client.NextId()
|
||||
|
||||
if a != 0 || b != 1 {
|
||||
if a != 0 || b != 2 {
|
||||
t.Fatalf("IDs should increment")
|
||||
}
|
||||
|
||||
a = server.NextId()
|
||||
b = server.NextId()
|
||||
|
||||
if a != 1 || b != 3 {
|
||||
t.Fatalf("IDs should increment: %d %d", a, b)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ type Server struct {
|
|||
|
||||
// NewServer returns a new Packer RPC server.
|
||||
func NewServer(conn io.ReadWriteCloser) *Server {
|
||||
result := NewServerWithMux(NewMuxConn(conn), 0)
|
||||
result := NewServerWithMux(NewMuxConn(conn, 1), 0)
|
||||
result.closeMux = true
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue