Fix for incorrect shutting down

master
Evgeny Kovalev 1 year ago
parent b2a1571f8d
commit 4f965ddefb
  1. 20
      internal/gameServer/gameServer.go
  2. 18
      main.go

@ -3,6 +3,7 @@ package gameServer
import (
"fmt"
"log"
"sync"
"daydev.org/shipsgs/internal/config"
"daydev.org/shipsgs/internal/player"
@ -27,6 +28,9 @@ type GameServer struct {
//Quit the loops correctly and shut down the Game Server
Shutdown chan bool
//sync threads
WG sync.WaitGroup
}
func (m *GameServer) Init(logger *utils.Logger, config *config.S_Config) {
@ -36,27 +40,23 @@ func (m *GameServer) Init(logger *utils.Logger, config *config.S_Config) {
m.maxLobbies = m.Config.MaxLobbies
m.maxPlayers = m.Config.MaxPlayers
m.Shutdown = make(chan bool)
m.currentLobbies = 0
m.currentPlayers = 0
m.WG.Add(1)
}
func (m *GameServer) Update() {
for {
// select - go through the messages
select {
case c := <-m.connection:
fmt.Println("a new connection", c)
}
//default shutdown
if m.Shutdown == nil {
case <-m.Shutdown:
m.ShutdownServer()
break
m.WG.Done()
}
}
}
func (m *GameServer) Scheduled1S() {

@ -29,32 +29,36 @@ func main() {
closer.Bind(cleanup)
//Can be optimised to NEW instead of MAKE
sighup := make(chan bool)
ch_sighup = &sighup
//If debug - fill Stdout too - LOG to use?
//Logger = utils.New(os.Stdout, utils.LevelInfo)
//GameServer
var gs gameServer.GameServer
GS = &gs
go gs.Update()
config.ReadConfig()
GS = new(gameServer.GameServer)
GS.Init(Logger, &config.Config)
go GS.Update()
log.Println("Starting Healthy")
//closer.Hold()
server.SetupAndRun(":8080", ch_sighup)
GS.WG.Wait()
}
func cleanup() {
fmt.Println("Shutting down ")
*ch_sighup <- true
//Investigate why no messages on correct closing
GS.Shutdown = nil
GS.Shutdown <- true
// Main function has to be closed the last
*ch_sighup <- true
Logger.PrintInfo("main", map[string]string{
"Info": "Closing Application Normally",

Loading…
Cancel
Save