mirror of
				https://github.com/tailscale/tailscale.git
				synced 2025-10-31 08:11:32 +01:00 
			
		
		
		
	This package contains platform-independent abstractions for fetching information about an open TCP connection. Updates #8413 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: I236657b1060d7e6a45efc7a2f6aacf474547a2fe
		
			
				
	
	
		
			34 lines
		
	
	
		
			642 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			642 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright (c) Tailscale Inc & AUTHORS
 | |
| // SPDX-License-Identifier: BSD-3-Clause
 | |
| 
 | |
| package tcpinfo
 | |
| 
 | |
| import (
 | |
| 	"net"
 | |
| 	"time"
 | |
| 
 | |
| 	"golang.org/x/sys/unix"
 | |
| )
 | |
| 
 | |
| func rttImpl(conn *net.TCPConn) (time.Duration, error) {
 | |
| 	rawConn, err := conn.SyscallConn()
 | |
| 	if err != nil {
 | |
| 		return 0, err
 | |
| 	}
 | |
| 
 | |
| 	var (
 | |
| 		tcpInfo *unix.TCPConnectionInfo
 | |
| 		sysErr  error
 | |
| 	)
 | |
| 	err = rawConn.Control(func(fd uintptr) {
 | |
| 		tcpInfo, sysErr = unix.GetsockoptTCPConnectionInfo(int(fd), unix.IPPROTO_TCP, unix.TCP_CONNECTION_INFO)
 | |
| 	})
 | |
| 	if err != nil {
 | |
| 		return 0, err
 | |
| 	} else if sysErr != nil {
 | |
| 		return 0, sysErr
 | |
| 	}
 | |
| 
 | |
| 	return time.Duration(tcpInfo.Rttcur) * time.Millisecond, nil
 | |
| }
 |