2012-06-12 19:42


  • io

I'm getting an error returned from an io.Copy call, to which I've passed a socket (TCPConn) as the destination. It's expected that the remote host will simply drop the connection when they've had enough, and I'm not receiving anything from them.

When the drop occurs, I get this error:

write tcp broken pipe

But all I have is an error interface. How can I differentiate broken pipe errors from other kinds of error?

if err.Errno == EPIPE...
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanmao1919 duanmao1919 9年前

    The broken pipe error is defined in the syscall package. You can use the equality operator to compare the error to the one in syscall. Check http://golang.org/pkg/syscall/#constants for a complete list of syscall errors. Search "EPIPE" on the page and you will find all the defined errors grouped together.

    if err == syscall.EPIPE {
        /* ignore */

    If you wish to get the actual errno number (although it is pretty useless) you can use a type assertion:

    if e, ok := err.(syscall.Errno); ok {
        errno = uintptr(e)
    点赞 评论 复制链接分享
  • douqulv6059 douqulv6059 9年前

    Having all but an error interface is enough to perform a type assertion or a type switch to reveal the concrete type held by the interface.

    点赞 评论 复制链接分享