delete unused connections from the multiplexer

This commit is contained in:
Jan Rüth 2019-01-08 10:43:20 +01:00 committed by Marten Seemann
parent 6fbe8d563e
commit 1a0aa50471
4 changed files with 37 additions and 1 deletions

View file

@ -15,6 +15,7 @@ var (
type multiplexer interface {
AddConn(net.PacketConn, int) (packetHandlerManager, error)
RemoveConn(net.PacketConn) error
}
type connManager struct {
@ -61,3 +62,15 @@ func (m *connMultiplexer) AddConn(c net.PacketConn, connIDLen int) (packetHandle
}
return p.manager, nil
}
func (m *connMultiplexer) RemoveConn(c net.PacketConn) error {
m.mutex.Lock()
defer m.mutex.Unlock()
if _, ok := m.conns[c]; !ok {
return fmt.Errorf("cannote remove connection, connection is unknown")
}
delete(m.conns, c)
return nil
}