mirror of
https://github.com/aler9/gortsplib
synced 2025-12-24 13:38:08 +08:00
36 lines
729 B
Go
36 lines
729 B
Go
// Package readbuffer contains a function to set the read buffer size of a UDP socket.
|
|
package readbuffer
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"syscall"
|
|
)
|
|
|
|
// PacketConn is a packet connection.
|
|
type PacketConn interface {
|
|
net.PacketConn
|
|
SyscallConn() (syscall.RawConn, error)
|
|
SetReadBuffer(bytes int) error
|
|
}
|
|
|
|
// SetReadBuffer sets the read buffer size of the UDP connection and checks that it was set correctly.
|
|
func SetReadBuffer(pc PacketConn, size int) error {
|
|
err := pc.SetReadBuffer(size)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
v, err := ReadBuffer(pc)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if v != size {
|
|
return fmt.Errorf("unable to set read buffer size to %v, check that the operating system allows that",
|
|
size)
|
|
}
|
|
|
|
return nil
|
|
}
|