From e02f2b51c5b2a159570aab964491f431cc7b8532 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Sun, 8 Nov 2009 21:57:59 -0800 Subject: [PATCH] delete a pointless todo in all_test.go. address one in rpc/client.go R=rsc CC=go-dev http://go/go-review/1026030 --- src/pkg/reflect/all_test.go | 2 +- src/pkg/rpc/client.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go index 45a76259a9..f2e2f92bce 100644 --- a/src/pkg/reflect/all_test.go +++ b/src/pkg/reflect/all_test.go @@ -349,7 +349,7 @@ func TestPtrPointTo(t *testing.T) { } } -func TestAll(t *testing.T) { // TODO(r): wrap up better +func TestAll(t *testing.T) { testType(t, 1, Typeof((int8)(0)), "int8"); testType(t, 2, Typeof((*int8)(nil)).(*PtrType).Elem(), "int8"); diff --git a/src/pkg/rpc/client.go b/src/pkg/rpc/client.go index 01dcec7db5..e1b6a14eca 100644 --- a/src/pkg/rpc/client.go +++ b/src/pkg/rpc/client.go @@ -96,7 +96,7 @@ func (client *Client) input() { _ = call.Done <- call; // do not block } client.mutex.Unlock(); - log.Stderr("client protocol error:", err); + log.Stderr("rpc: client protocol error:", err); } // NewClient returns a new Client to handle requests to the @@ -144,18 +144,22 @@ func Dial(network, address string) (*Client, os.Error) { // Go invokes the function asynchronously. It returns the Call structure representing // the invocation. The done channel will signal when the call is complete by returning // the same Call object. If done is nil, Go will allocate a new channel. +// If non-nil, done must be buffered or Go will deliberately crash. func (client *Client) Go(serviceMethod string, args interface{}, reply interface{}, done chan *Call) *Call { c := new(Call); c.ServiceMethod = serviceMethod; c.Args = args; c.Reply = reply; if done == nil { - done = make(chan *Call, 1); // buffered. + done = make(chan *Call, 10); // buffered. } else { - // TODO(r): check cap > 0 // If caller passes done != nil, it must arrange that // done has enough buffer for the number of simultaneous - // RPCs that will be using that channel. + // RPCs that will be using that channel. If the channel + // is totally unbuffered, it's best not to run at all. + if cap(done) == 0 { + log.Crash("rpc: done channel is unbuffered"); + } } c.Done = done; if client.shutdown != nil { -- 2.50.0