1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| func (client *Client) send(call *Call) { client.sending.Lock() defer client.sending.Unlock()
seq, err := client.registerCall(call) if err != nil { call.Error = err call.done() return }
client.header.ServiceMethod = call.ServiceMethod client.header.Seq = seq client.header.Error = ""
if err := client.cc.Write(&client.header, call.Args); err != nil { call := client.removeCall(seq) if call != nil { call.Error = err call.done() } } }
func (client *Client) Go(serviceMethod string, args, reply interface{}, done chan *Call) *Call { if done == nil { done = make(chan *Call, 10) } else if cap(done) == 0 { log.Panic("rpc client: done channel is unbuffered") } call := &Call{ ServiceMethod: serviceMethod, Args: args, Reply: reply, Done: done, } client.send(call) return call }
func (client *Client) Call(serviceMethod string, args, reply interface{}) error { call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).Done return call.Error }
|