joshlf
joshlf

Reputation: 23607

Tell whether net.Listener is dead

In Go, a call to the net.Listener type's Accept method returns an error. However, is there a way to tell the difference between a transient error (ie, this connection failed to set up) vs a permanent error (ie, the listener is dead, such as a Unix domain socket file that was forcibly removed)? If I can't tell the difference, I run the risk of infinite looping and spitting out errors as fast as I can since each Accept call will immediately return an error.

Upvotes: 1

Views: 44

Answers (1)

joshlf
joshlf

Reputation: 23607

Figured it out. Errors returned by the net package may be of the net.Error type, which defines the Temporary() bool method which reports whether the error is temporary.

Upvotes: 2

Related Questions