mirror of
https://github.com/go-i2p/go-sam-go.git
synced 2025-07-01 13:27:58 -04:00
Work on making DatagramConn implement net.Conn
This commit is contained in:
@ -73,8 +73,13 @@ func (r *DatagramReader) receiveLoop() {
|
||||
logger := log.WithField("session_id", r.session.ID())
|
||||
logger.Debug("Starting receive loop")
|
||||
|
||||
// Ensure we signal completion when this loop exits
|
||||
r.doneChan = make(chan struct{})
|
||||
// Signal completion when this loop exits - doneChan must be initialized
|
||||
// before this goroutine starts to avoid race conditions with Close()
|
||||
defer func() {
|
||||
if r.doneChan != nil {
|
||||
close(r.doneChan)
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
// Check for closure in a non-blocking way first
|
||||
|
@ -2,6 +2,7 @@ package datagram
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/go-i2p/go-sam-go/common"
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
@ -48,6 +49,9 @@ func (s *DatagramSession) NewReader() *DatagramReader {
|
||||
recvChan: make(chan *Datagram, 10), // Buffer for incoming datagrams
|
||||
errorChan: make(chan error, 1),
|
||||
closeChan: make(chan struct{}),
|
||||
doneChan: make(chan struct{}),
|
||||
closed: false,
|
||||
mu: sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user