Merge branch 'main' of https://106.52.207.92:9103/limingjie/OmniSocketGo
This commit is contained in:
@@ -15,10 +15,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
linuxTimestampControlBufferSize = 256 // 控制消息缓冲区。
|
||||
linuxTXTimestampWaitTimeout = 250 * time.Millisecond // 等待 TX 时间戳的上限。
|
||||
linuxTXTimestampPollInterval = time.Millisecond // 轮询 errqueue 的间隔。
|
||||
linuxDataPollInterval = time.Millisecond // 轮询普通收发的间隔。
|
||||
linuxTimestampControlBufferSize = 2048 // 控制消息缓冲区。
|
||||
linuxSocketWriteBufferSize = 10 * 1024 * 1024 // 请求把 socket 发送缓冲区调到 10 MiB。
|
||||
linuxTXTimestampWaitTimeout = 5000 * time.Millisecond // 等待 TX 时间戳的上限。
|
||||
linuxTXTimestampPollInterval = time.Millisecond // 轮询 errqueue 的间隔。
|
||||
linuxDataPollInterval = time.Millisecond // 轮询普通收发的间隔。
|
||||
|
||||
linuxSOTimestampingNew = 0x41
|
||||
linuxSCMTimestampingNew = linuxSOTimestampingNew
|
||||
@@ -88,6 +89,10 @@ func (c *TCPConn) initLinuxTimestamping() error {
|
||||
return fmt.Errorf("transport: missing syscall conn")
|
||||
}
|
||||
|
||||
if err := configureLinuxSocketWriteBuffer(rawConn); err != nil {
|
||||
return fmt.Errorf("transport: configure socket write buffer: %w", err)
|
||||
}
|
||||
|
||||
//socket是否可以成功打开 timestamping 取决于内核版本和配置,尝试多个 flag 组合直到成功或遇到非 EINVAL 错误。
|
||||
if err := enableLinuxTimestamping(rawConn); err != nil {
|
||||
return fmt.Errorf("transport: enable linux timestamping: %w", err)
|
||||
@@ -97,6 +102,20 @@ func (c *TCPConn) initLinuxTimestamping() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 设置 TCP缓冲区buffer size
|
||||
func configureLinuxSocketWriteBuffer(rawConn syscall.RawConn) error {
|
||||
var lastErr error
|
||||
|
||||
err := rawConn.Control(func(fd uintptr) {
|
||||
lastErr = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF, linuxSocketWriteBufferSize)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return lastErr
|
||||
}
|
||||
|
||||
// 给 socket开权限打开TX software timestamping。
|
||||
func enableLinuxTimestamping(rawConn syscall.RawConn) error {
|
||||
flagCandidates := []int{ //不同linux版本可能支持不同的 flag 组合,尝试多个组合直到成功。
|
||||
|
||||
@@ -182,7 +182,7 @@ func TestSelectTXTimestampEventsFallsBackToHighestObservedID(t *testing.T) {
|
||||
|
||||
func TestLinuxTimestampingDebugLoggerCapturesChunkAndErrqueueEvents(t *testing.T) {
|
||||
clientConn, serverConn := newTCPPair(t)
|
||||
setTCPWriteBuffer(t, clientConn, 4096)
|
||||
setTCPWriteBuffer(t, clientConn, 10*1024*1024)
|
||||
|
||||
debugLogger := &recordingTXTimestampDebugLogger{}
|
||||
senderLogger := &recordingLogger{}
|
||||
|
||||
Reference in New Issue
Block a user