1
0
Fork 0

Re-factor clean exiting to be usable in the client also

This commit is contained in:
Aaron Lindsay 2013-09-03 22:21:18 -04:00
parent 4eb75e1db1
commit 2dcd08d502
3 changed files with 10 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"asink"
"net"
"net/http"
"net/rpc"
@ -68,7 +69,7 @@ func (u *UserModifier) RemoveUser(user *User, result *int) error {
type ServerStopper int
func (s *ServerStopper) StopServer(code *int, result *int) error {
Exit(*code)
asink.Exit(*code)
*result = 0
return nil
}
@ -92,5 +93,5 @@ func StartRPC(sock string, tornDown chan int, adb *AsinkDB) {
go http.Serve(l, nil)
WaitOnExit()
asink.WaitOnExit()
}

View File

@ -29,6 +29,8 @@ func init() {
if err != nil {
panic(err)
}
asink.SetupCleanExitOnSignals()
}
const sock_usage = "Socket to use to connect to the Asink server."
@ -60,7 +62,7 @@ func StartServer(args []string) {
go http.Serve(l, nil)
//TODO handle errors from http.Serve?
WaitOnExit()
asink.WaitOnExit()
<-rpcTornDown
}

View File

@ -1,4 +1,4 @@
package main
package asink
import (
"os"
@ -14,9 +14,11 @@ func init() {
exitWaiterCount = 0
exitWaiterChan = make(chan int)
exitCalled = make(chan int)
go setupCleanExitOnSignals()
}
func SetupCleanExitOnSignals() {
go setupCleanExitOnSignals()
}
func setupCleanExitOnSignals() {
//wait to properly close the socket when we're exiting
exitCode := 0