OLD | NEW |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package jsonrpc implements a JSON-RPC ClientCodec and ServerCodec | 5 // Package jsonrpc implements a JSON-RPC ClientCodec and ServerCodec |
6 // for the rpc package. | 6 // for the rpc package. |
7 package jsonrpc | 7 package jsonrpc |
8 | 8 |
9 import ( | 9 import ( |
10 "fmt" | 10 "fmt" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 c.mutex.Lock() | 80 c.mutex.Lock() |
81 r.ServiceMethod = c.pending[c.resp.Id] | 81 r.ServiceMethod = c.pending[c.resp.Id] |
82 c.pending[c.resp.Id] = "", false | 82 c.pending[c.resp.Id] = "", false |
83 c.mutex.Unlock() | 83 c.mutex.Unlock() |
84 | 84 |
85 r.Error = "" | 85 r.Error = "" |
86 r.Seq = c.resp.Id | 86 r.Seq = c.resp.Id |
87 if c.resp.Error != nil { | 87 if c.resp.Error != nil { |
88 x, ok := c.resp.Error.(string) | 88 x, ok := c.resp.Error.(string) |
89 if !ok { | 89 if !ok { |
90 » » » return os.NewError(fmt.Sprintf("invalid error %v", c.res
p.Error)) | 90 » » » return fmt.Errorf("invalid error %v", c.resp.Error) |
91 } | 91 } |
92 if x == "" { | 92 if x == "" { |
93 x = "unspecified error" | 93 x = "unspecified error" |
94 } | 94 } |
95 r.Error = x | 95 r.Error = x |
96 } | 96 } |
97 return nil | 97 return nil |
98 } | 98 } |
99 | 99 |
100 func (c *clientCodec) ReadResponseBody(x interface{}) os.Error { | 100 func (c *clientCodec) ReadResponseBody(x interface{}) os.Error { |
(...skipping 11 matching lines...) Expand all Loading... |
112 } | 112 } |
113 | 113 |
114 // Dial connects to a JSON-RPC server at the specified network address. | 114 // Dial connects to a JSON-RPC server at the specified network address. |
115 func Dial(network, address string) (*rpc.Client, os.Error) { | 115 func Dial(network, address string) (*rpc.Client, os.Error) { |
116 conn, err := net.Dial(network, "", address) | 116 conn, err := net.Dial(network, "", address) |
117 if err != nil { | 117 if err != nil { |
118 return nil, err | 118 return nil, err |
119 } | 119 } |
120 return NewClient(conn), err | 120 return NewClient(conn), err |
121 } | 121 } |
OLD | NEW |