update Mutex

This commit is contained in:
2025-09-09 20:40:58 +02:00
parent c8d85898ca
commit 55a8067be6
2 changed files with 9 additions and 19 deletions

View File

@@ -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
}