Created
September 25, 2016 06:41
-
-
Save skoowoo/53cc5ebaa559c46ff1b5d9eb5dfaba6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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