io.Copy:如何知道套接字是关闭还是断开连接

I have a simple program that connects a program's stdin, stdout and stderr to a socket, like this,

go func() {
    defer conn.Close();
    defer stdin.Close();

    io.Copy(stdin, conn);
}();

go func() {
    defer conn.Close();
    defer stdout.Close();
    defer stderr.Close();

    io.Copy(conn, stdout);
    io.Copy(conn, stderr);
}();

select{}

I have two problems,

  1. I have to keep these two goroutines running by doing a select{}
  2. When the socket get disconnected, there's no way to tell it. I need to terminate the select{} loop if that happens.

Any ideas?

If connection is closed, io.Copy() will return (0, io.EOF), so you can check it.