major refactoring :/
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m56s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m56s
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user