I am using the conn.SetReadDeadline
method to set the read timeout for conn
, When conn.Read
waits for more than the specified time, it will return and return an error of type *net.OpError
. This error is returned by the net
package after wrapping all non-io.EOF
errors.
I can get the error before wrapping with Unwrap()
. A timeout error is an error of type *poll.DeadlineExceededError
. I use statements like this in my code to handle timeout errors precisely.
import "internal/poll"
_, err = conn.Read(p)
if err != nil {
if pe, ok := err.(*net.OpError); ok {
err = pe.Unwrap()
if timeout, ok := err.(*poll.DeadlineExceededError); ok {
log.Error(fmt.Sprintf("%T, %s", timeout, timeout))
}
}
return
}
I received an use of internal package internal/poll not allowed
error while running the program. The compiler tells me that internal packages cannot be used.
I googled and found a solution to delete the internal
folder, is this the final solution? Will there be a better solution?