Created
September 25, 2016 06:31
-
-
Save skoowoo/db7dd113901444fb21b49809c766a646 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" | |
) | |
type fdMutex struct { | |
state uint64 | |
rsema uint32 | |
wsema uint32 | |
} | |
type pollDesc struct { | |
runtimeCtx uintptr | |
} | |
type netFD struct { | |
// locking/lifetime of sysfd + serialize access to Read and Write methods | |
fdmu fdMutex | |
// immutable until Close | |
sysfd int | |
family int | |
sotype int | |
isConnected bool | |
net string | |
laddr net.Addr // 加上包 | |
raddr net.Addr // 加上包 | |
// wait server | |
pd pollDesc | |
} | |
func main() { | |
conn, err := net.Dial("tcp", "www.taobao.com:80") | |
if err != nil { | |
panic(err) | |
} | |
if tcpConn, ok := conn.(*net.TCPConn); ok { | |
fd := *(**netFD)(unsafe.Pointer(tcpConn)) | |
println("fd: ", fd.sysfd) | |
const tcpUserTimeout = 0x12 | |
syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, tcpUserTimeout, 1000) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment