diff --git a/packetio/buffer.go b/packetio/buffer.go index 2d46d79..e8a10a4 100644 --- a/packetio/buffer.go +++ b/packetio/buffer.go @@ -7,6 +7,7 @@ package packetio import ( "errors" "io" + "math" "sync" "time" @@ -50,7 +51,7 @@ type Buffer struct { const ( minSize = 2048 cutoffSize = 128 * 1024 - maxSize = 4 * 1024 * 1024 + maxSize = math.MaxInt // same as bytes.Buffer ) // NewBuffer creates a new Buffer. @@ -331,7 +332,7 @@ func (b *Buffer) size() int { // SetLimitSize controls the maximum number of bytes that can be buffered. // Causes Write to return ErrFull when this limit is reached. -// A zero value means 4MB since v0.11.0. +// A zero value means math.MaxInt since v2.2.5. // // User can set packetioSizeHardLimit build tag to enable 4MB hard limit. // When packetioSizeHardLimit build tag is set, SetLimitSize exceeding diff --git a/packetio/buffer_test.go b/packetio/buffer_test.go index 4101212..ae82c9f 100644 --- a/packetio/buffer_test.go +++ b/packetio/buffer_test.go @@ -331,27 +331,19 @@ func TestBufferLimitSizes(t *testing.T) { 128 * 1024, 1024 * 1024, 8 * 1024 * 1024, - 0, // default } const headerSize = 2 const packetSize = 0x8000 for _, size := range sizes { size := size - name := "default" - if size > 0 { - name = fmt.Sprintf("%dkBytes", size/1024) - } + name := fmt.Sprintf("%dkBytes", size/1024) t.Run(name, func(t *testing.T) { assert := assert.New(t) buffer := NewBuffer() - if size == 0 { - size = maxSize - } else { - buffer.SetLimitSize(size + headerSize) - } + buffer.SetLimitSize(size + headerSize) now := time.Now() assert.NoError(buffer.SetReadDeadline(now.Add(5 * time.Second))) // Set deadline to avoid test deadlock diff --git a/udp/conn.go b/udp/conn.go index e2378f8..c2f257e 100644 --- a/udp/conn.go +++ b/udp/conn.go @@ -12,6 +12,7 @@ import ( "sync/atomic" "time" + "github.com/pion/logging" "github.com/pion/transport/v2/deadline" "github.com/pion/transport/v2/packetio" "golang.org/x/net/ipv4" @@ -51,6 +52,8 @@ type listener struct { readDoneCh chan struct{} errRead atomic.Value // error + + logger logging.LeveledLogger } // Accept waits for and returns the next connection to the listener. @@ -151,6 +154,8 @@ type ListenConfig struct { WriteBufferSize int Batch BatchIOConfig + + LoggerFactory logging.LoggerFactory } // Listen creates a new listener based on the ListenConfig. @@ -175,6 +180,13 @@ func (lc *ListenConfig) Listen(network string, laddr *net.UDPAddr) (net.Listener _ = conn.SetWriteBuffer(lc.WriteBufferSize) } + loggerFactory := lc.LoggerFactory + if loggerFactory == nil { + loggerFactory = logging.NewDefaultLoggerFactory() + } + + logger := loggerFactory.NewLogger("transport") + l := &listener{ pConn: conn, acceptCh: make(chan *Conn, lc.Backlog), @@ -183,6 +195,7 @@ func (lc *ListenConfig) Listen(network string, laddr *net.UDPAddr) (net.Listener acceptFilter: lc.AcceptFilter, connWG: &sync.WaitGroup{}, readDoneCh: make(chan struct{}), + logger: logger, } if lc.Batch.Enable { @@ -251,6 +264,7 @@ func (l *listener) read() { n, raddr, err := l.pConn.ReadFrom(buf) if err != nil { l.errRead.Store(err) + l.logger.Tracef("error reading from connection err=%v", err) return } l.dispatchMsg(raddr, buf[:n]) @@ -263,7 +277,10 @@ func (l *listener) dispatchMsg(addr net.Addr, buf []byte) { return } if ok { - _, _ = conn.buffer.Write(buf) + _, err := conn.buffer.Write(buf) + if err != nil { + l.logger.Tracef("error dispatching message addr=%v err=%v", addr, err) + } } }