doutizha7526 2014-03-14 17:43
浏览 509
已采纳

是什么原因导致客户端。调用rpc在Go(golang)中返回错误?

When does c.Call(...) return a non-nil value?

Can the c.Call(...) only return an error when a network failure occurs (packets lost or timed out or something along those lines)?

If the server srv crashes, will c.Call(...) return an error?

Specifically, can c.Call(...) return an error AFTER the request successfully arrived at srv but BEFORE the rpcname handler function returns?

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
}
  • 写回答

1条回答 默认 最新

  • dstjh46606 2014-03-15 05:23
    关注

    If you have a look at client.go in the source code for net/rpc you'll see quite a few lines where call.Error is set. These should show you all of the conditions under which a Call will return an error.

    Many of them are generated upon encountering errors from ClientCodec.WriteRequest and ClientCodec.ReadResponseBody. See the ClientCodec docs for more details.

    There are also a couple of possible errors for encountering unexpected EOF, and ErrShutdown when the client is closing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog