c.Call(…)什么时候返回非零值? c.Call(…)只能在发生网络故障时丢失一个错误(数据包丢失或超时或沿着这些线路)? 如果服务器srv崩溃,c.Call(…)会返回错误吗? 具体来说,c.Call(…)可以在
c.Call(…)只能在发生网络故障时丢失一个错误(数据包丢失或超时或沿着这些线路)?
如果服务器srv崩溃,c.Call(…)会返回错误吗?
具体来说,c.Call(…)可以在请求成功到达srv之后返回错误,但是在rpcname处理函数返回之前?
import (
"net/rpc"
"fmt"
)
func call(srv string, rpcname string, args interface{}, reply interface{}) bool {
c, errx := rpc.Dial("unix", srv)
if errx != nil {
return false
}
defer c.Close()
err := c.Call(rpcname, args, reply)
if err == nil {
return true
}
fmt.Println(err)
return false
}
如果你看一下
client.go in the source code for net/rpc,你会看到很多行,其中设置了call.Error.这些应该显示Call将返回错误的所有条件.
其中许多是在遇到来自ClientCodec.WriteRequest和ClientCodec.ReadResponseBody的错误时生成的.有关详细信息,请参阅ClientCodec docs.
遇到意外EOF时也会出现几个错误,客户端关闭时会出现ErrShutdown.
