clean exit on server abort
This commit is contained in:
parent
9388ea78f7
commit
b823c890f9
|
@ -6,7 +6,9 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
@ -42,6 +44,11 @@ func render() {
|
||||||
func runClient(cmd *cobra.Command, args []string) {
|
func runClient(cmd *cobra.Command, args []string) {
|
||||||
data.InitNC()
|
data.InitNC()
|
||||||
defer data.ExitNC()
|
defer data.ExitNC()
|
||||||
|
|
||||||
|
c := make(chan os.Signal)
|
||||||
|
signal.Notify(c, os.Interrupt, os.Kill)
|
||||||
|
signal.Notify(c, syscall.SIGTERM)
|
||||||
|
|
||||||
fmt.Println("running client ...")
|
fmt.Println("running client ...")
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
|
@ -58,13 +65,22 @@ func runClient(cmd *cobra.Command, args []string) {
|
||||||
register(con, id)
|
register(con, id)
|
||||||
|
|
||||||
go render()
|
go render()
|
||||||
for {
|
run := true
|
||||||
|
for run {
|
||||||
|
// block until sigkill:
|
||||||
|
select {
|
||||||
|
case <-c:
|
||||||
|
// funzt noch nicht:
|
||||||
|
run = false
|
||||||
|
default:
|
||||||
|
}
|
||||||
var oFrame data.Frame
|
var oFrame data.Frame
|
||||||
// always use new decoder - reusing may lead to errors
|
// always use new decoder - reusing may lead to errors
|
||||||
gd := gob.NewDecoder(con)
|
gd := gob.NewDecoder(con)
|
||||||
err = gd.Decode(&oFrame)
|
err = gd.Decode(&oFrame)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("RGS:", err)
|
log.Println("RGS:", err)
|
||||||
|
run = false
|
||||||
}
|
}
|
||||||
renderQueue <- oFrame
|
renderQueue <- oFrame
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user