mux sending
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 27s
Build and Publish / BuildAndDeploy (push) Successful in 2m19s

This commit is contained in:
matst80
2024-11-12 22:35:03 +01:00
parent e1b254668f
commit addec8788f
4 changed files with 14 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ func CartListen(address string) (*CartServer, error) {
type TCPCartServerMux struct {
mu sync.RWMutex
sendMux sync.Mutex
listeners map[CartMessage]func(CartId, []byte) error
functions map[CartMessage]func(CartId, []byte) (CartMessage, []byte, error)
}
@@ -68,6 +69,8 @@ func (m *TCPCartServerMux) handleFunction(connection net.Conn, messageType CartM
m.mu.RLock()
fn, ok := m.functions[messageType]
m.mu.RUnlock()
m.sendMux.Lock()
defer m.sendMux.Unlock()
if ok {
responseType, responseData, err := fn(id, data)
connection.Write(header[:])