types cleanup
This commit is contained in:
@@ -37,21 +37,21 @@ func Listen(address string) (*Server, error) {
|
||||
|
||||
type TCPServerMux struct {
|
||||
mu sync.RWMutex
|
||||
listeners map[uint32]func(data []byte) error
|
||||
functions map[uint32]func(data []byte) (uint32, []byte, error)
|
||||
listeners map[PoolMessage]func(data []byte) error
|
||||
functions map[PoolMessage]func(data []byte) (PoolMessage, []byte, error)
|
||||
}
|
||||
|
||||
func NewTCPServerMux() *TCPServerMux {
|
||||
m := &TCPServerMux{
|
||||
mu: sync.RWMutex{},
|
||||
listeners: make(map[uint32]func(data []byte) error),
|
||||
functions: make(map[uint32]func(data []byte) (uint32, []byte, error)),
|
||||
listeners: make(map[PoolMessage]func(data []byte) error),
|
||||
functions: make(map[PoolMessage]func(data []byte) (PoolMessage, []byte, error)),
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *TCPServerMux) handleListener(messageType uint32, data []byte) (bool, error) {
|
||||
func (m *TCPServerMux) handleListener(messageType PoolMessage, data []byte) (bool, error) {
|
||||
m.mu.RLock()
|
||||
handler, ok := m.listeners[messageType]
|
||||
m.mu.RUnlock()
|
||||
@@ -64,7 +64,7 @@ func (m *TCPServerMux) handleListener(messageType uint32, data []byte) (bool, er
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (m *TCPServerMux) handleFunction(connection net.Conn, messageType uint32, data []byte) (bool, error) {
|
||||
func (m *TCPServerMux) handleFunction(connection net.Conn, messageType PoolMessage, data []byte) (bool, error) {
|
||||
m.mu.RLock()
|
||||
function, ok := m.functions[messageType]
|
||||
m.mu.RUnlock()
|
||||
@@ -124,7 +124,7 @@ func (m *TCPServerMux) HandleConnection(connection net.Conn) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *TCPServerMux) HandleData(connection net.Conn, t uint32, data []byte) {
|
||||
func (m *TCPServerMux) HandleData(connection net.Conn, t PoolMessage, data []byte) {
|
||||
// listener := m.listeners[t]
|
||||
// handler := m.functions[t]
|
||||
status, err := m.handleListener(t, data)
|
||||
@@ -142,13 +142,13 @@ func (m *TCPServerMux) HandleData(connection net.Conn, t uint32, data []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *TCPServerMux) ListenFor(messageType uint32, handler func(data []byte) error) {
|
||||
func (m *TCPServerMux) ListenFor(messageType PoolMessage, handler func(data []byte) error) {
|
||||
m.mu.Lock()
|
||||
m.listeners[messageType] = handler
|
||||
m.mu.Unlock()
|
||||
}
|
||||
|
||||
func (m *TCPServerMux) HandleCall(messageType uint32, handler func(data []byte) (uint32, []byte, error)) {
|
||||
func (m *TCPServerMux) HandleCall(messageType PoolMessage, handler func(data []byte) (PoolMessage, []byte, error)) {
|
||||
m.mu.Lock()
|
||||
m.functions[messageType] = handler
|
||||
m.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user