简体   繁体   English

判断net.Listener是否已死

[英]Tell whether net.Listener is dead

In Go, a call to the net.Listener type's Accept method returns an error. 在Go中,对net.Listener类型的Accept方法的调用将返回错误。 However, is there a way to tell the difference between a transient error (ie, this connection failed to set up) vs a permanent error (ie, the listener is dead, such as a Unix domain socket file that was forcibly removed)? 但是,有没有办法分辨出瞬时错误(即,该连接建立失败)与永久性错误(即,侦听器已死,例如被强制删除的Unix域套接字文件)之间的区别? If I can't tell the difference, I run the risk of infinite looping and spitting out errors as fast as I can since each Accept call will immediately return an error. 如果我不能分辨出差异,那么我将冒无限循环的风险,并尽可能快地吐出错误,因为每个Accept调用都会立即返回错误。

Figured it out. 弄清楚了。 Errors returned by the net package may be of the net.Error type, which defines the Temporary() bool method which reports whether the error is temporary. net程序包返回的错误可能是net.Error类型,它定义了Temporary() bool方法,该方法报告错误是否是临时的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM