douxiuar885064 2018-09-20 03:36
浏览 25

os.File.SetReadDealine:文件类型不支持截止日期

I use win10 and go1.11 windows/amd64

deviceid, err := getdeviceid(config.PlatformSpecificParams.ComponentID)
if err != nil {
    return nil, err
}

path := "\\\\.\\Global\\" + deviceid + ".tap"
pathp, err := syscall.UTF16PtrFromString(path)
if err != nil {
    return nil, err
}

fileFd, err := syscall.CreateFile(  pathp,
                                    syscall.GENERIC_READ|syscall.GENERIC_WRITE,
                                    uint32(syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE),
                                    nil,
                                    syscall.OPEN_EXISTING,
                                    syscall.FILE_ATTRIBUTE_SYSTEM|syscall.FILE_FLAG_OVERLAPPED,
                                    0)
……

file := os.NewFile(uintptr(fileFd), "nic")

……

file.SetReadDeadline(time.Now().Add(t))   //   [ERROR] file type does not support deadline

The error occurred in the last line: file type does not support deadline

  • 写回答

1条回答 默认 最新

  • douliu1092 2018-09-20 13:28
    关注

    for Go before 1.11 SetReadDeadline seems to be defined for TCP, UDP and Unix domain (aka named) sockets, not files

    See https://golang.org/pkg/net

    But it is introduced for use on files in 1.11 (sorry I missed this), see https://golang.org/pkg/os/#File.SetReadDeadline

    I don't see a non blocking flag in your CreateFile call? I don't know how this works on MS Windows...maybe I am missing it. Deadline needs this..maybe a possible cause?

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能