Skip to content

Instantly share code, notes, and snippets.

@skoowoo
Created September 25, 2016 06:41
Show Gist options
  • Save skoowoo/53cc5ebaa559c46ff1b5d9eb5dfaba6a to your computer and use it in GitHub Desktop.
Save skoowoo/53cc5ebaa559c46ff1b5d9eb5dfaba6a to your computer and use it in GitHub Desktop.
package main
import (
"net"
"unsafe"
"syscall"
)
func main() {
conn, err := net.Dial("tcp", "www.taobao.com:80")
if err != nil {
panic(err)
}
if tcpConn, ok := conn.(*net.TCPConn); ok {
fdAddr := *(**int)(unsafe.Pointer(tcpConn))
sysfd := *(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(fdAddr)) + 16))
println("fd: ", sysfd)
const tcpUserTimeout = 0x12
syscall.SetsockoptInt(sysfd, syscall.IPPROTO_TCP, tcpUserTimeout, 1000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment