From b0f98fdd4ff47f9532cb9d6ae1ca8769bd1f27d4 Mon Sep 17 00:00:00 2001 From: Kleissner Date: Mon, 25 Oct 2021 09:56:28 +0200 Subject: [PATCH] UDT: Simplify closing behavior - removing multiplexer level for reporting close of listener/socket back to upstream provided closer. --- udt/listener.go | 2 +- udt/multiplexer.go | 31 ------------------------------- udt/udtsocket.go | 3 ++- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/udt/listener.go b/udt/listener.go index 76e042d..fe5ec40 100644 --- a/udt/listener.go +++ b/udt/listener.go @@ -48,7 +48,7 @@ func (l *listener) Close() (err error) { close(a) close(c) - l.m.unlistenUDT(l) + l.m.closer.Close() return nil } diff --git a/udt/multiplexer.go b/udt/multiplexer.go index 008ffc8..a7fcea2 100644 --- a/udt/multiplexer.go +++ b/udt/multiplexer.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "math/rand" - "sync" "github.com/PeernetOfficial/core/udt/packet" ) @@ -17,7 +16,6 @@ type multiplexer struct { socketID uint32 // Socket ID listenSock *listener // the server socket listening to incoming connections, if there is one. Set by caller. maxPacketSize uint // the Maximum Transmission Unit of packets sent from this address - sync.Mutex // Synchronized access to socket/listenSock incomingData <-chan []byte // source to read packets from outgoingData chan<- []byte // destination to send packets to terminationSignal <-chan struct{} // external termination signal to watch @@ -39,39 +37,12 @@ func newMultiplexer(closer io.Closer, maxPacketSize uint, incomingData <-chan [] return } -// unlistenUDT is the closeListen equivalent -func (m *multiplexer) unlistenUDT(l *listener) { - m.Lock() - defer m.Unlock() - - if m.listenSock == nil { - return - } - - m.listenSock = nil - - m.closer.Close() -} - func (m *multiplexer) newSocket(config *Config, isServer bool, isDatagram bool) (s *udtSocket) { m.socketID = rand.Uint32() m.socket = newSocket(m, config, m.socketID, isServer, isDatagram) return m.socket } -func (m *multiplexer) closeSocket(sockID uint32) { - m.Lock() - defer m.Unlock() - - if m.socket == nil { - return - } - - m.socket = nil - - m.closer.Close() -} - // read runs in a goroutine and reads packets from conn using a buffer from the readBufferPool, or a new buffer. func (m *multiplexer) goRead() { for { @@ -98,11 +69,9 @@ func (m *multiplexer) goRead() { return } - m.Lock() if m.listenSock != nil { m.listenSock.readHandshake(m, hsPacket) } - m.Unlock() } if m.socketID == sockID && m.socket != nil { m.socket.readPacket(m, p) diff --git a/udt/udtsocket.go b/udt/udtsocket.go index 9369f45..dd2d398 100644 --- a/udt/udtsocket.go +++ b/udt/udtsocket.go @@ -627,10 +627,11 @@ func (s *udtSocket) shutdown(sockState sockState, permitLinger bool, err error) s.connTimeout = nil s.connRetry = nil - s.m.closeSocket(s.sockID) close(s.sockClosed) close(s.recvEvent) + s.m.closer.Close() + s.messageIn <- nil }