2013-09-04 22:02:17 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2013 Aaron Lindsay <aaron@aclindsay.com>
|
|
|
|
*/
|
|
|
|
|
2013-09-03 23:33:36 -04:00
|
|
|
package asink
|
2013-08-23 00:09:03 -04:00
|
|
|
|
|
|
|
import (
|
2013-08-27 09:41:55 -04:00
|
|
|
"log"
|
2013-08-23 00:09:03 -04:00
|
|
|
"net"
|
|
|
|
"net/rpc"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2013-09-02 23:35:48 -04:00
|
|
|
func RPCCall(socket, method string, args interface{}, reply interface{}) error {
|
2013-08-23 00:09:03 -04:00
|
|
|
client, err := rpc.DialHTTP("unix", socket)
|
|
|
|
if err != nil {
|
|
|
|
if err2, ok := err.(*net.OpError); ok {
|
|
|
|
if err2.Err == syscall.ENOENT {
|
2013-08-27 09:41:55 -04:00
|
|
|
log.Fatal("The socket (" + socket + ") was not found")
|
2013-08-23 00:09:03 -04:00
|
|
|
} else if err2.Err == syscall.ECONNREFUSED {
|
2013-08-27 09:41:55 -04:00
|
|
|
log.Fatal("A connection was refused to " + socket + ". Please check the permissions and ensure the server is running.")
|
2013-08-23 00:09:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
err = client.Call(method, args, reply)
|
|
|
|
return err
|
|
|
|
}
|