func getInterfaceInfos() ([]syscall.InterfaceInfo, error) { s, err := sysSocket(syscall.AF_INET, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP) if err != nil { return nil, os.NewSyscallError("Socket", err) } defer syscall.Closesocket(s) iia := [20]syscall.InterfaceInfo{} ret := uint32(0) size := uint32(unsafe.Sizeof(iia)) err = syscall.WSAIoctl(s, syscall.SIO_GET_INTERFACE_LIST, nil, 0, (*byte)(unsafe.Pointer(&iia[0])), size, &ret, nil, 0) if err != nil { return nil, os.NewSyscallError("WSAIoctl", err) } iilen := ret / uint32(unsafe.Sizeof(iia[0])) return iia[:iilen-1], nil }
func getInterfaceList() ([]syscall.InterfaceInfo, os.Error) { s, e := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP) if e != 0 { return nil, os.NewSyscallError("Socket", e) } defer syscall.Closesocket(s) ii := [20]syscall.InterfaceInfo{} ret := uint32(0) size := uint32(unsafe.Sizeof(ii)) e = syscall.WSAIoctl(s, syscall.SIO_GET_INTERFACE_LIST, nil, 0, (*byte)(unsafe.Pointer(&ii[0])), size, &ret, nil, 0) if e != 0 { return nil, os.NewSyscallError("WSAIoctl", e) } c := ret / uint32(unsafe.Sizeof(ii[0])) return ii[:c-1], nil }
func setKeepAlivePeriod(fd *netFD, d time.Duration) error { if err := fd.incref(); err != nil { return err } defer fd.decref() // The kernel expects milliseconds so round to next highest // millisecond. d += (time.Millisecond - time.Nanosecond) msecs := uint32(d / time.Millisecond) ka := syscall.TCPKeepalive{ OnOff: 1, Time: msecs, Interval: msecs, } ret := uint32(0) size := uint32(unsafe.Sizeof(ka)) err := syscall.WSAIoctl(fd.sysfd, syscall.SIO_KEEPALIVE_VALS, (*byte)(unsafe.Pointer(&ka)), size, nil, 0, &ret, nil, 0) return os.NewSyscallError("WSAIoctl", err) }
func (fd *netFD) init() error { if err := fd.pd.Init(fd); err != nil { return err } if hasLoadSetFileCompletionNotificationModes { // We do not use events, so we can skip them always. flags := uint8(syscall.FILE_SKIP_SET_EVENT_ON_HANDLE) // It's not safe to skip completion notifications for UDP: // http://blogs.technet.com/b/winserverperformance/archive/2008/06/26/designing-applications-for-high-performance-part-iii.aspx if skipSyncNotif && fd.net == "tcp" { flags |= syscall.FILE_SKIP_COMPLETION_PORT_ON_SUCCESS } err := syscall.SetFileCompletionNotificationModes(fd.sysfd, flags) if err == nil && flags&syscall.FILE_SKIP_COMPLETION_PORT_ON_SUCCESS != 0 { fd.skipSyncNotif = true } } // Disable SIO_UDP_CONNRESET behavior. // http://support.microsoft.com/kb/263823 switch fd.net { case "udp", "udp4", "udp6": ret := uint32(0) flag := uint32(0) size := uint32(unsafe.Sizeof(flag)) err := syscall.WSAIoctl(fd.sysfd, syscall.SIO_UDP_CONNRESET, (*byte)(unsafe.Pointer(&flag)), size, nil, 0, &ret, nil, 0) if err != nil { return os.NewSyscallError("WSAIoctl", err) } } fd.rop.mode = 'r' fd.wop.mode = 'w' fd.rop.fd = fd fd.wop.fd = fd fd.rop.runtimeCtx = fd.pd.runtimeCtx fd.wop.runtimeCtx = fd.pd.runtimeCtx if !canCancelIO { fd.rop.errc = make(chan error) fd.wop.errc = make(chan error) } return nil }