Close TCP recvChan after all writes have completed

Closes #260
This commit is contained in:
Jerko Steiner
2020-08-09 13:55:49 +02:00
parent 8f4d021fc7
commit fa49161dd0
+6 -1
View File
@@ -194,9 +194,10 @@ func (t *tcpPacketConn) removeConn(conn net.Conn) {
func (t *tcpPacketConn) Close() error {
t.mu.Lock()
var shouldCloseRecvChan bool
t.closeOnce.Do(func() {
close(t.closedChan)
close(t.recvChan)
shouldCloseRecvChan = true
})
for _, conn := range t.conns {
@@ -208,6 +209,10 @@ func (t *tcpPacketConn) Close() error {
t.wg.Wait()
if shouldCloseRecvChan {
close(t.recvChan)
}
return nil
}