UDT: Simplify closing behavior - removing multiplexer level for reporting close of listener/socket back to upstream provided closer.

This commit is contained in:
Kleissner
2021-10-25 09:56:28 +02:00
parent 13ef42ac39
commit b0f98fdd4f
3 changed files with 3 additions and 33 deletions

View File

@@ -48,7 +48,7 @@ func (l *listener) Close() (err error) {
close(a)
close(c)
l.m.unlistenUDT(l)
l.m.closer.Close()
return nil
}

View File

@@ -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)

View File

@@ -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
}