Pregunta

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
}
¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top