add some more tests for the client multiplexer

This commit is contained in:
Marten Seemann 2018-07-02 15:48:19 +07:00
parent 0928e91e4d
commit b682af20cf
5 changed files with 156 additions and 22 deletions

View file

@ -15,9 +15,14 @@ import (
var (
clientMuxerOnce sync.Once
clientMuxer *clientMultiplexer
clientMuxer multiplexer
)
type multiplexer interface {
AddConn(net.PacketConn) packetHandlerManager
AddHandler(net.PacketConn, protocol.ConnectionID, packetHandler) error
}
// The clientMultiplexer listens on multiple net.PacketConns and dispatches
// incoming packets to the session handler.
type clientMultiplexer struct {
@ -29,7 +34,9 @@ type clientMultiplexer struct {
logger utils.Logger
}
func getClientMultiplexer() *clientMultiplexer {
var _ multiplexer = &clientMultiplexer{}
func getClientMultiplexer() multiplexer {
clientMuxerOnce.Do(func() {
clientMuxer = &clientMultiplexer{
conns: make(map[net.PacketConn]packetHandlerManager),