From 55a8067be6ff3b441142a22e6ec10a7dd07d3600 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 9 Sep 2025 20:40:58 +0200 Subject: [PATCH] update Mutex --- TCPClient.go | 25 ++++++------------------- main.go | 3 +++ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/TCPClient.go b/TCPClient.go index 8fee07a..f0b5924 100644 --- a/TCPClient.go +++ b/TCPClient.go @@ -88,10 +88,8 @@ func (c *TCPClient) StartClient() { go func() { for message := range c.TCPServer.CmdChan { - c.Mutex.Lock() Log.Infof("Received Command: %s", message) c.Write([]byte(message + "\r\n")) - c.Mutex.Unlock() } }() @@ -99,51 +97,38 @@ func (c *TCPClient) StartClient() { } func (c *TCPClient) Close() { - c.Writer.WriteString("bye") - time.Sleep(time.Second * 2) + c.Writer.Write([]byte("bye\r\n")) } func (c *TCPClient) SetFilters() { if Cfg.Cluster.FT8 { - c.Mutex.Lock() c.Write([]byte("set/ft8\r\n")) Log.Info("FT8: On") - c.Mutex.Unlock() } if Cfg.Cluster.Skimmer { - c.Mutex.Lock() c.Write([]byte("set/skimmer\r\n")) Log.Info("Skimmer: On") - c.Mutex.Unlock() } if Cfg.Cluster.FT4 { - c.Mutex.Lock() c.Write([]byte("set/ft4\r\n")) Log.Info("FT4: On") - c.Mutex.Unlock() } if !Cfg.Cluster.FT8 { - c.Mutex.Lock() c.Write([]byte("set/noft8\r\n")) Log.Info("FT8: Off") - c.Mutex.Unlock() } if !Cfg.Cluster.FT4 { - c.Mutex.Lock() c.Write([]byte("set/noft4\r\n")) Log.Info("FT4: Off") - c.Mutex.Unlock() } if !Cfg.Cluster.Skimmer { - c.Mutex.Lock() c.Write([]byte("set/noskimmer\r\n")) Log.Info("Skimmer: Off") - c.Mutex.Unlock() } } @@ -211,12 +196,14 @@ func (c *TCPClient) ReadLine() { } // Write sends raw data to remove telnet server -func (tc *TCPClient) Write(data []byte) (n int, err error) { - n, err = tc.Writer.Write(data) +func (c *TCPClient) Write(data []byte) (n int, err error) { + Mutex.Lock() + n, err = c.Writer.Write(data) if err != nil { Log.Errorf("Error while sending command to telnet client: %s", err) } else { - err = tc.Writer.Flush() + err = c.Writer.Flush() } + Mutex.Unlock() return } diff --git a/main.go b/main.go index 6e6505e..657dbfd 100644 --- a/main.go +++ b/main.go @@ -5,8 +5,11 @@ import ( "log" "os" "path/filepath" + "sync" ) +var Mutex sync.Mutex + func ParseFlags() (string, error) { // String that contains the configured configuration path var configPath string