package channelz
import (
"syscall"
"golang.org/x/sys/unix"
)
type SocketOptionData struct {
Linger *unix .Linger
RecvTimeout *unix .Timeval
SendTimeout *unix .Timeval
TCPInfo *unix .TCPInfo
}
func (s *SocketOptionData ) Getsockopt (fd uintptr ) {
if v , err := unix .GetsockoptLinger (int (fd ), syscall .SOL_SOCKET , syscall .SO_LINGER ); err == nil {
s .Linger = v
}
if v , err := unix .GetsockoptTimeval (int (fd ), syscall .SOL_SOCKET , syscall .SO_RCVTIMEO ); err == nil {
s .RecvTimeout = v
}
if v , err := unix .GetsockoptTimeval (int (fd ), syscall .SOL_SOCKET , syscall .SO_SNDTIMEO ); err == nil {
s .SendTimeout = v
}
if v , err := unix .GetsockoptTCPInfo (int (fd ), syscall .SOL_TCP , syscall .TCP_INFO ); err == nil {
s .TCPInfo = v
}
}
func GetSocketOption (socket any ) *SocketOptionData {
c , ok := socket .(syscall .Conn )
if !ok {
return nil
}
data := &SocketOptionData {}
if rawConn , err := c .SyscallConn (); err == nil {
rawConn .Control (data .Getsockopt )
return data
}
return nil
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .