Generalize RPC client code, add basic RPC functionality to client

This commit is contained in:
2013-09-03 23:33:36 -04:00
parent 2dcd08d502
commit d883e3d92d
6 changed files with 408 additions and 274 deletions

34
asink/rpc_server.go Normal file
View File

@ -0,0 +1,34 @@
package main
import (
"asink"
"net"
"net/http"
"net/rpc"
)
type ClientStopper int
func (c *ClientStopper) StopClient(code *int, result *int) error {
asink.Exit(*code)
*result = 0
return nil
}
func StartRPC(sock string, tornDown chan int) {
defer func() { tornDown <- 0 }() //the main thread waits for this to ensure the socket is closed
clientstop := new(ClientStopper)
rpc.Register(clientstop)
rpc.HandleHTTP()
l, err := net.Listen("unix", sock)
if err != nil {
panic(err)
}
defer l.Close()
go http.Serve(l, nil)
asink.WaitOnExit()
}