major refactoring :/
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m56s

This commit is contained in:
matst80
2024-11-10 18:39:28 +01:00
parent 50a1c56d56
commit 056bfd9ffe
10 changed files with 469 additions and 130 deletions

View File

@@ -35,18 +35,16 @@ func Listen(address string) (*Server, error) {
}
type TCPServerMux struct {
mu sync.RWMutex
listeners map[uint16]func(data []byte) error
functions map[uint16]func(data []byte) (uint16, []byte, error)
connections []net.Conn
mu sync.RWMutex
listeners map[uint16]func(data []byte) error
functions map[uint16]func(data []byte) (uint16, []byte, error)
}
func NewTCPServerMux(maxClients int) *TCPServerMux {
m := &TCPServerMux{
connections: make([]net.Conn, 0, maxClients),
mu: sync.RWMutex{},
listeners: make(map[uint16]func(data []byte) error),
functions: make(map[uint16]func(data []byte) (uint16, []byte, error)),
mu: sync.RWMutex{},
listeners: make(map[uint16]func(data []byte) error),
functions: make(map[uint16]func(data []byte) (uint16, []byte, error)),
}
return m
@@ -90,9 +88,7 @@ func (m *TCPServerMux) handleFunction(connection net.Conn, messageType uint16, d
}
func (m *TCPServerMux) HandleConnection(connection net.Conn) error {
m.mu.Lock()
m.connections = append(m.connections, connection)
m.mu.Unlock()
defer connection.Close()
for {
messageType, data, err := ReceivePacket(connection)