Instead of breaking out of the loop, we may as well return the
appropriate value directly.
close(sockfd);
PARA_ERROR_LOG("can not set SO_REUSEADDR: %s\n",
para_strerror(-ret));
- break;
+ return ret;
}
if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
close(sockfd);
continue;
}
- /* bind completed successfully */
- break;
+ return sockfd;
} else {
if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == 0)
- break; /* connection completed successfully */
+ return sockfd;
+ close(sockfd);
}
- close(sockfd);
}
- if (!ai)
- return ret < 0? ret : -E_MAKESOCK;
- return sockfd;
+ return -E_MAKESOCK;
}
/**