doumor942473 2018-01-08 15:39
浏览 85
已采纳

Windows XP SP3上的Accept()超时设置

I faced a critical issue while using go1.9.2 windows/386 on Windows XP SP3.

The Accept() blocks forever, even if I set a timeout using SetDeadline(), until the program exits.

I consider it critical because I can't stop listeners when I need to. Additionally, conn.Read() blocks forever as well, but I didn't include it to the example to make is simpler.

package main

import (
    "fmt"
    "net"
    "time"
)

func main() {

    listener, err := net.Listen("tcp", ":8888")
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    tcplistener := listener.(*net.TCPListener)
    tcplistener.SetDeadline(time.Now().Add(time.Second * 2))

    fmt.Println("Listener started")

    go func() {

        defer func() {
            tcplistener.Close()
            fmt.Println("Listener closed")
        }()

        for {

            conn, err := listener.Accept()
            if err != nil {
                fmt.Println(err.Error())
                return
            }

            conn.Write([]byte("OK
"))
            conn.Close()

        }

    }()

    time.Sleep(time.Second * 10)

    fmt.Println("Exit")
}

Terminal output:

Listener started
Exit

In contrast, when I run this program on Windows 7 under VirtualBox (on the same Windows XP SP3), Accept() successfully unblocks after a timeout period.

Terminal output:

Listener started
accept tcp [::]:8888 i/o timeout
Listener closed
Exit
  • 写回答

1条回答 默认 最新

  • dp815292 2018-01-13 11:20
    关注

    I've found a solution: reinstall Windows XP SP3.

    I've tried to check how the app works on another installation of Windows XP SP3 and Windows XP SP2 and found that there were no issue.

    Obviously, this means my XP works in a different way. Unfortunately, I have no ideas what is wrong.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?