simplify connection handling when setting the receive buffer

This commit is contained in:
Marten Seemann 2023-05-08 13:04:18 +03:00
parent 1cd78f131f
commit 600502ab06
6 changed files with 38 additions and 54 deletions

View file

@ -5,7 +5,6 @@ package quic
import (
"encoding/binary"
"errors"
"fmt"
"net"
"syscall"
"time"
@ -32,20 +31,10 @@ type batchConn interface {
ReadBatch(ms []ipv4.Message, flags int) (int, error)
}
func inspectReadBuffer(c interface{}) (int, error) {
conn, ok := c.(interface {
SyscallConn() (syscall.RawConn, error)
})
if !ok {
return 0, errors.New("doesn't have a SyscallConn")
}
rawConn, err := conn.SyscallConn()
if err != nil {
return 0, fmt.Errorf("couldn't get syscall.RawConn: %w", err)
}
func inspectReadBuffer(c syscall.RawConn) (int, error) {
var size int
var serr error
if err := rawConn.Control(func(fd uintptr) {
if err := c.Control(func(fd uintptr) {
size, serr = unix.GetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_RCVBUF)
}); err != nil {
return 0, err