github.com/cbeuw/gotfo@v0.0.0-20180331191851-f2b091af84de/fd_go18_unix.go (about) 1 // +build go1.8,!go1.9 2 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris 3 4 package gotfo 5 6 import ( 7 "net" 8 "syscall" 9 ) 10 11 type netFD struct { 12 // locking/lifetime of sysfd + serialize access to Read and Write methods 13 fdmu fdMutex 14 15 // immutable until Close 16 sysfd int 17 family int 18 sotype int 19 isStream bool 20 isConnected bool 21 net string 22 laddr net.Addr 23 raddr net.Addr 24 25 // writev cache. 26 iovecs *[]syscall.Iovec 27 28 // wait server 29 pd pollDesc 30 } 31 32 func newFD(fd int) *netFD { 33 nfd := &netFD{ 34 sysfd: fd, 35 family: syscall.AF_INET, 36 sotype: syscall.SOCK_STREAM, 37 net: "tcp", 38 isStream: true, 39 } 40 41 return nfd //, nfd.pd.init(nfd) 42 } 43 44 func (fd *netFD) init() error { 45 return fd.pd.init(fd) 46 } 47 48 func (fd *netFD) destroy() error { 49 // Poller may want to unregister fd in readiness notification mechanism, 50 // so this must be executed before closeFunc. 51 fd.pd.close() 52 err := syscall.Close(fd.sysfd) 53 fd.sysfd = -1 54 return err 55 }