aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/net/rpc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2012-02-09 08:19:58 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2012-02-09 08:19:58 +0000
commit94252f4bcc0a3f487b804ce535cb77b8bef4db83 (patch)
tree7ca86535c5a6b99d4cc432ba5cfddabc5ee4ea16 /libgo/go/net/rpc
parentcd6368115dbd75d9187877097c48a0d8d4c04fd4 (diff)
downloadgcc-94252f4bcc0a3f487b804ce535cb77b8bef4db83.zip
gcc-94252f4bcc0a3f487b804ce535cb77b8bef4db83.tar.gz
gcc-94252f4bcc0a3f487b804ce535cb77b8bef4db83.tar.bz2
libgo: Update to weekly.2012-02-07.
From-SVN: r184034
Diffstat (limited to 'libgo/go/net/rpc')
-rw-r--r--libgo/go/net/rpc/client.go62
-rw-r--r--libgo/go/net/rpc/server_test.go9
2 files changed, 38 insertions, 33 deletions
diff --git a/libgo/go/net/rpc/client.go b/libgo/go/net/rpc/client.go
index abc1e59..34f9ae3 100644
--- a/libgo/go/net/rpc/client.go
+++ b/libgo/go/net/rpc/client.go
@@ -31,8 +31,7 @@ type Call struct {
Args interface{} // The argument to the function (*struct).
Reply interface{} // The reply from the function (*struct).
Error error // After completion, the error status.
- Done chan *Call // Strobes when call is complete; value is the error status.
- seq uint64
+ Done chan *Call // Strobes when call is complete.
}
// Client represents an RPC Client.
@@ -65,28 +64,33 @@ type ClientCodec interface {
Close() error
}
-func (client *Client) send(c *Call) {
+func (client *Client) send(call *Call) {
+ client.sending.Lock()
+ defer client.sending.Unlock()
+
// Register this call.
client.mutex.Lock()
if client.shutdown {
- c.Error = ErrShutdown
+ call.Error = ErrShutdown
client.mutex.Unlock()
- c.done()
+ call.done()
return
}
- c.seq = client.seq
+ seq := client.seq
client.seq++
- client.pending[c.seq] = c
+ client.pending[seq] = call
client.mutex.Unlock()
// Encode and send the request.
- client.sending.Lock()
- defer client.sending.Unlock()
- client.request.Seq = c.seq
- client.request.ServiceMethod = c.ServiceMethod
- if err := client.codec.WriteRequest(&client.request, c.Args); err != nil {
- c.Error = err
- c.done()
+ client.request.Seq = seq
+ client.request.ServiceMethod = call.ServiceMethod
+ err := client.codec.WriteRequest(&client.request, call.Args)
+ if err != nil {
+ client.mutex.Lock()
+ delete(client.pending, seq)
+ client.mutex.Unlock()
+ call.Error = err
+ call.done()
}
}
@@ -104,36 +108,39 @@ func (client *Client) input() {
}
seq := response.Seq
client.mutex.Lock()
- c := client.pending[seq]
+ call := client.pending[seq]
delete(client.pending, seq)
client.mutex.Unlock()
if response.Error == "" {
- err = client.codec.ReadResponseBody(c.Reply)
+ err = client.codec.ReadResponseBody(call.Reply)
if err != nil {
- c.Error = errors.New("reading body " + err.Error())
+ call.Error = errors.New("reading body " + err.Error())
}
} else {
// We've got an error response. Give this to the request;
// any subsequent requests will get the ReadResponseBody
// error if there is one.
- c.Error = ServerError(response.Error)
+ call.Error = ServerError(response.Error)
err = client.codec.ReadResponseBody(nil)
if err != nil {
err = errors.New("reading error body: " + err.Error())
}
}
- c.done()
+ call.done()
}
// Terminate pending calls.
+ client.sending.Lock()
client.mutex.Lock()
client.shutdown = true
+ closing := client.closing
for _, call := range client.pending {
call.Error = err
call.done()
}
client.mutex.Unlock()
- if err != io.EOF || !client.closing {
+ client.sending.Unlock()
+ if err != io.EOF || !closing {
log.Println("rpc: client protocol error:", err)
}
}
@@ -225,7 +232,12 @@ func DialHTTPPath(network, address, path string) (*Client, error) {
err = errors.New("unexpected HTTP response: " + resp.Status)
}
conn.Close()
- return nil, &net.OpError{"dial-http", network + " " + address, nil, err}
+ return nil, &net.OpError{
+ Op: "dial-http",
+ Net: network + " " + address,
+ Addr: nil,
+ Err: err,
+ }
}
// Dial connects to an RPC server at the specified network address.
@@ -269,20 +281,12 @@ func (client *Client) Go(serviceMethod string, args interface{}, reply interface
}
}
call.Done = done
- if client.shutdown {
- call.Error = ErrShutdown
- call.done()
- return call
- }
client.send(call)
return call
}
// Call invokes the named function, waits for it to complete, and returns its error status.
func (client *Client) Call(serviceMethod string, args interface{}, reply interface{}) error {
- if client.shutdown {
- return ErrShutdown
- }
call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).Done
return call.Error
}
diff --git a/libgo/go/net/rpc/server_test.go b/libgo/go/net/rpc/server_test.go
index b05c63c..8cfa033 100644
--- a/libgo/go/net/rpc/server_test.go
+++ b/libgo/go/net/rpc/server_test.go
@@ -442,8 +442,9 @@ func countMallocs(dial func() (*Client, error), t *testing.T) uint64 {
}
args := &Args{7, 8}
reply := new(Reply)
- runtime.UpdateMemStats()
- mallocs := 0 - runtime.MemStats.Mallocs
+ memstats := new(runtime.MemStats)
+ runtime.ReadMemStats(memstats)
+ mallocs := 0 - memstats.Mallocs
const count = 100
for i := 0; i < count; i++ {
err := client.Call("Arith.Add", args, reply)
@@ -454,8 +455,8 @@ func countMallocs(dial func() (*Client, error), t *testing.T) uint64 {
t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
}
}
- runtime.UpdateMemStats()
- mallocs += runtime.MemStats.Mallocs
+ runtime.ReadMemStats(memstats)
+ mallocs += memstats.Mallocs
return mallocs / count
}