On Saturday, January 19, 2013 1:58:42 AM UTC-5, Dave Cheney wrote:
To quote Mr Pike, can you please describe your problem, not your solution.
Yeah, I didn't really give enough context.
This part of the code is a simple proxy, copying the data between two tcp
connections. If either connection closes, I need to close the other half of
the pair. The problem is that the other connection will almost always be in
a Read() call, and will return a net.OpError with "use of closed network
connection". Though I won't need to take action on other errors, I'll need
to log them, as they'll be exceptional cases.
I could of course drop down to a lower level, do the copy myself,
SetReadDeadline on the sockets and poll for a close signal, but that's a
lot of work when to goroutines with io.Copy() works so well.
I thought it would be easier to just handle the specific error, but being
relatively new to go, figuring out how to extract and match the string was
a little bit of a challenge. Is this the best way to differentiate the
error, or is there another way to structure the problems that I'm not
thinking of?
Thanks!
On 19/01/2013, at 11:51, James Bardin <j.ba...@gmail.com <javascript:>>
wrote:
Please ignore my previous post (pending moderation), Read() on a TCPConn
does not return (0, nil).
Since I figure I have to deal with the "use of closed network connection"
in order to close a connection that's in a Read() call (unless I poll for a
closing channel in between setting SetReadDeadline).This is basically the
function I have to filter out this error:
func checkNetOpError(err error) error {
if err != nil {
netOpError, ok := err.(*net.OpError)
if ok && netOpError.Err.Error() == "use of closed network connection" {
return nil
}
}
return err
}
This seems awkward though; is this the best way to handle this?
--
--