mux sending
This commit is contained in:
@@ -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[:])
|
||||
|
||||
Reference in New Issue
Block a user