multiplex multiple clients on one packet conn

This commit is contained in:
Marten Seemann
2018-05-22 11:08:48 +08:00
parent dacc94ccba
commit 2c05dbff07
9 changed files with 259 additions and 27 deletions

View File

@@ -7,6 +7,10 @@ import (
"github.com/lucas-clemente/quic-go/internal/protocol"
)
// The packetHandlerMap stores packetHandlers, identified by connection ID.
// It is used:
// * by the server to store sessions
// * when multiplexing outgoing connections to store clients
type packetHandlerMap struct {
mutex sync.RWMutex
@@ -50,7 +54,7 @@ func (h *packetHandlerMap) Remove(id protocol.ConnectionID) {
})
}
func (h *packetHandlerMap) Close() {
func (h *packetHandlerMap) Close(err error) {
h.mutex.Lock()
if h.closed {
h.mutex.Unlock()
@@ -64,7 +68,7 @@ func (h *packetHandlerMap) Close() {
wg.Add(1)
go func(handler packetHandler) {
// session.Close() blocks until the CONNECTION_CLOSE has been sent and the run-loop has stopped
_ = handler.Close(nil)
_ = handler.Close(err)
wg.Done()
}(handler)
}