diff --git a/src/pkg/netchan/common.go b/src/pkg/netchan/common.go index 010b957acdf..3f99868490b 100644 --- a/src/pkg/netchan/common.go +++ b/src/pkg/netchan/common.go @@ -21,6 +21,16 @@ const ( Send ) +func (dir Dir) String() string { + switch dir { + case Recv: + return "Recv" + case Send: + return "Send" + } + return "???" +} + // Payload types const ( payRequest = iota // request structure follows diff --git a/src/pkg/netchan/export.go b/src/pkg/netchan/export.go index c42e35c56d9..a58797e630c 100644 --- a/src/pkg/netchan/export.go +++ b/src/pkg/netchan/export.go @@ -19,7 +19,7 @@ */ package netchan -// BUG: can't use range clause to receive when using ImportNValues with N non-zero. +// BUG: can't use range clause to receive when using ImportNValues to limit the count. import ( "log" @@ -94,6 +94,7 @@ func (client *expClient) run() { reqValue := reflect.NewValue(req) error := new(error) for { + *hdr = header{} if err := client.decode(hdrValue); err != nil { log.Stderr("error decoding client header:", err) break diff --git a/src/pkg/netchan/import.go b/src/pkg/netchan/import.go index 77ec24d77ba..028a25f7f80 100644 --- a/src/pkg/netchan/import.go +++ b/src/pkg/netchan/import.go @@ -64,6 +64,7 @@ func (imp *Importer) run() { err := new(error) errValue := reflect.NewValue(err) for { + *hdr = header{} if e := imp.decode(hdrValue); e != nil { log.Stderr("importer header:", e) imp.shutdown() @@ -152,7 +153,7 @@ func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, n int) } if dir == Send { go func() { - for i := 0; n == 0 || i < n; i++ { + for i := 0; n == -1 || i < n; i++ { val := ch.Recv() if err := imp.encode(hdr, payData, val.Interface()); err != nil { log.Stderr("error encoding client response:", err)