Golang,net.TCPConn,SetReadTimeout?

huangapple go评论98阅读模式
英文:

Golang, net.TCPConn, SetReadTimeout?

问题

我在Mac上创建了一个简单的Go应用程序,用于在TCP连接上读写数据。我使用了GAE Go版本。后来,我将该程序移植到Windows上,然后出现了这个错误:

Connection.SetReadTimeout undefined (type *net.TCPConn has no field or method SetReadTimeout)

我猜测Golang网站上的net包信息只描述了GAE版本的包。在非GAE Go版本中,我应该如何正确设置超时时间?

英文:

I've created a simple Go application on a Mac for writing and reading data to and from a TCP connection. I've used the GAE Go version. Later, I ported that program to Windows, and I got this error :

Connection.SetReadTimeout undefined (type *net.TCPConn has no field or method SetReadTimeout)

I guess the net package information on the Golang website describes the package only for the GAE version. How would I properly set the timeout in a non-GAE Go version?

答案1

得分: 1

使用最新的每周版本(也称为Go 1 RC2),需要使用net.Conn类型的各种Set*Deadline方法。请注意,旧的超时是相对于某个事件的,而截止时间是绝对时间。这个更改的背景大致是:在某些情况下,设置一个相对超时时间为1秒似乎是一个好主意,但它适用于每个事件,比如接收一个字节,因此允许精心设计的传输永远避免超时(附近的DOS攻击)。

英文:

With latest weekly (aka Go 1 RC2) one has to use the various Set*Deadline methods of the net.Conn type. Note that the old timeouts were relative to some event, deadlines are absolute times. The background for this change is roughly: setting a [relative] timeout of 1 s seems like a good idea in some scenario, but it applied to every event, like receiving a single byte, thus allowing crafted transfers to avoid timeouts forever (with the respective DOS nearby).

huangapple
  • 本文由 发表于 2012年3月28日 17:44:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/9904935.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定