Commit edbdee5d authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: accept/dial stream IDs are unique [GH-727]

parent 629f3eee
......@@ -17,7 +17,7 @@ type Client struct {
}
func NewClient(rwc io.ReadWriteCloser) (*Client, error) {
result, err := newClientWithMux(NewMuxConn(rwc, 0), 0)
result, err := newClientWithMux(NewMuxConn(rwc), 0)
if err != nil {
return nil, err
}
......
......@@ -164,7 +164,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
}
}()
if args.StdinStreamId > 0 {
if args.StdinStreamId >= 0 {
conn, err := c.mux.Dial(args.StdinStreamId)
if err != nil {
close(doneCh)
......@@ -175,7 +175,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
cmd.Stdin = conn
}
if args.StdoutStreamId > 0 {
if args.StdoutStreamId >= 0 {
conn, err := c.mux.Dial(args.StdoutStreamId)
if err != nil {
close(doneCh)
......@@ -186,7 +186,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
cmd.Stdout = conn
}
if args.StderrStreamId > 0 {
if args.StderrStreamId >= 0 {
conn, err := c.mux.Dial(args.StderrStreamId)
if err != nil {
close(doneCh)
......@@ -253,7 +253,6 @@ func (c *CommunicatorServer) Download(args *CommunicatorDownloadArgs, reply *int
}
func serveSingleCopy(name string, mux *MuxConn, id uint32, dst io.Writer, src io.Reader) {
log.Printf("[DEBUG] %s: Connecting to stream %d", name, id)
conn, err := mux.Accept(id)
if err != nil {
log.Printf("[ERR] '%s' accept error: %s", name, err)
......
This diff is collapsed.
......@@ -33,7 +33,7 @@ func testMux(t *testing.T) (client *MuxConn, server *MuxConn) {
t.Fatalf("err: %s", err)
}
server = NewMuxConn(conn, 1)
server = NewMuxConn(conn)
}()
// 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, 0)
client = NewMuxConn(conn)
// Wait for the server
<-doneCh
......@@ -241,14 +241,14 @@ func TestMuxConnNextId(t *testing.T) {
a := client.NextId()
b := client.NextId()
if a != 0 || b != 2 {
if a != 0 || b != 1 {
t.Fatalf("IDs should increment")
}
a = server.NextId()
b = server.NextId()
if a != 1 || b != 3 {
if a != 0 || b != 1 {
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, 1), 0)
result := newServerWithMux(NewMuxConn(conn), 0)
result.closeMux = true
return result
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment