updated README, avoid gooutinges for TCP handling, force disconnects when client is gone.

This commit is contained in:
Torsten Harenberg
2025-10-26 17:49:59 +01:00
parent 4ed3ce9b10
commit fb72775735
3 changed files with 19 additions and 14 deletions

View File

@@ -5,12 +5,13 @@ import (
"context"
"errors"
"fmt"
"github.com/TwiN/go-color"
"log"
"net"
"regexp"
"strings"
"time"
"github.com/TwiN/go-color"
)
// Chunks splits a string into chunks of chunkSize length
@@ -41,6 +42,7 @@ func Chunks(s string, chunkSize int) []string {
func handleTCPCmdConnection(conn net.Conn) {
defer func() {
s.Status &^= StatusTCPCmdActive
s.Command.Cmd.Enqueue("DD") // force stop all connetions if TCP connection is closing
err := conn.Close()
if err != nil {
writeDebug(err.Error(), 0)
@@ -158,7 +160,7 @@ func handleTCPDataConnection(conn net.Conn) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
for {
for ctx.Err() == nil {
msg, err := s.Data.Response.DequeueOrWaitContext(ctx, 1)
if err != nil {
s.Protocol <- fmt.Sprintf(color.InRed("End of TCP Data Connection %s\n"), conn.RemoteAddr())
@@ -326,8 +328,8 @@ func tcpCmdServer(Config *Userconfig) {
continue
}
// Handle connection in a separate goroutine
go handleTCPCmdConnection(conn)
// don't handle in goroutine as you normally would. There shouldn't be more than one connection.
handleTCPCmdConnection(conn)
}
}
@@ -354,7 +356,7 @@ func tcpDataServer(Config *Userconfig) {
continue
}
// Handle connection in a separate goroutine
go handleTCPDataConnection(conn)
// don't handle in goroutine as you normally would. There shouldn't be more than one connection.
handleTCPDataConnection(conn)
}
}