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 main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"asink"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/rpc"
|
|
|
|
)
|
|
|
|
|
2013-09-04 23:09:28 -04:00
|
|
|
type ClientAdmin int
|
2013-09-03 23:33:36 -04:00
|
|
|
|
2013-09-04 23:09:28 -04:00
|
|
|
func (c *ClientAdmin) StopClient(code *int, result *int) error {
|
2013-09-03 23:33:36 -04:00
|
|
|
asink.Exit(*code)
|
|
|
|
*result = 0
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-09-04 23:09:28 -04:00
|
|
|
func (c *ClientAdmin) GetClientStatus(code *int, result *string) error {
|
|
|
|
*result = GetStats()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-09-03 23:33:36 -04:00
|
|
|
func StartRPC(sock string, tornDown chan int) {
|
|
|
|
defer func() { tornDown <- 0 }() //the main thread waits for this to ensure the socket is closed
|
|
|
|
|
2013-09-04 23:09:28 -04:00
|
|
|
clientadmin := new(ClientAdmin)
|
|
|
|
rpc.Register(clientadmin)
|
2013-09-03 23:33:36 -04:00
|
|
|
|
|
|
|
rpc.HandleHTTP()
|
|
|
|
l, err := net.Listen("unix", sock)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer l.Close()
|
|
|
|
|
|
|
|
go http.Serve(l, nil)
|
|
|
|
|
|
|
|
asink.WaitOnExit()
|
|
|
|
}
|