1
0
mirror of https://github.com/golang/go synced 2024-11-21 19:24:45 -07:00

netchan: fix bug for imported send.

Also add a bit of debugging and sanitation code.
Fixes #769.

R=adg
CC=golang-dev
https://golang.org/cl/2206042
This commit is contained in:
Rob Pike 2010-09-16 13:59:31 +10:00
parent 5667d82599
commit 381ab58e2c
3 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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)