在普通的 Go HTTP 处理程序上,如果我在仍然写入响应的同时断开客户端的连接,http.ResponseWritter.Write将返回一个错误消息,如write tcp 127.0.0.1:60702: connection reset by peer.现在从syscall包中,我有sysca.ECONNRESET,其中包含消息connection reset by peer,所以它们并不完全相同。我怎样才能匹配它们,所以我知道如果它发生了不要惊慌?在其他场合我一直在做if err == syscall.EAGAIN { /* handle error differently */}例如,这工作得很好,但我不能用syscall.ECONNRESET.更新:因为我迫切需要一个解决方案,所以暂时我会做这个非常肮脏的黑客:if strings.Contains(err.Error(), syscall.ECONNRESET.Error()) { println("it's a connection reset by peer!") return}
3 回答
- 3 回答
- 0 关注
- 330 浏览
添加回答
举报
0/150
提交
取消