Created
March 13, 2019 11:44
-
-
Save sata/0c54ffb09c0fa97f8c9db0a05776bc96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func selfConnect(fd *netFD, err error) bool { | |
// If the connect failed, we clearly didn't connect to ourselves. | |
if err != nil { | |
return false | |
} | |
// The socket constructor can return an fd with raddr nil under certain | |
// unknown conditions. The errors in the calls there to Getpeername | |
// are discarded, but we can't catch the problem there because those | |
// calls are sometimes legally erroneous with a "socket not connected". | |
// Since this code (selfConnect) is already trying to work around | |
// a problem, we make sure if this happens we recognize trouble and | |
// ask the DialTCP routine to try again. | |
// TODO: try to understand what's really going on. | |
if fd.laddr == nil || fd.raddr == nil { | |
return true | |
} | |
l := fd.laddr.(*TCPAddr) | |
r := fd.raddr.(*TCPAddr) | |
return l.Port == r.Port && l.IP.Equal(r.IP) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment