Actually do loop...

This commit is contained in:
Peter Anvin 2005-10-13 15:20:41 -07:00
parent 4187af0e6f
commit ccb6289984

View file

@ -288,10 +288,12 @@ pick_port_bind(int sockfd, struct sockaddr_in *myaddr)
myaddr->sin_port = htons(port); myaddr->sin_port = htons(port);
if (bind(sockfd, (struct sockaddr *)myaddr, sizeof *myaddr) < 0) { if (bind(sockfd, (struct sockaddr *)myaddr, sizeof *myaddr) < 0) {
if ( portrange && (errno == EINVAL || errno == EADDRINUSE) ) /* Some versions of Linux return EINVAL instead of EADDRINUSE */
continue; /* Should not happen in normal operation, but try again */ if ( !portrange || !(errno != EINVAL && errno != EADDRINUSE) )
return -1;
return -1; /* Normally, we shouldn't have to loop, but some situations involving
aborted transfers make it possible. */
} else { } else {
return 0; return 0;
} }