- sockfd = ret;
- flowopt_setopts(sockfd, fo);
- if (passive) {
- /*
- * Reuse the address on passive sockets to avoid
- * failure on restart (protocols using listen()) and
- * when creating multiple listener instances (UDP
- * multicast).
- */
- if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on,
- sizeof(on)) == -1) {
- ret = -ERRNO_TO_PARA_ERROR(errno);
- close(sockfd);
- PARA_ERROR_LOG("can not set SO_REUSEADDR: %s\n",
- para_strerror(-ret));
- break;
- }
- if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
- close(sockfd);
- continue;
- }
- /* bind completed successfully */
- break;
- } else {
- if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == 0)
- break; /* connection completed successfully */
+ fd = ret;
+ flowopt_setopts(fd, fo);
+ if (!passive) {
+ if (connect(fd, ai->ai_addr, ai->ai_addrlen) == 0)
+ return fd;
+ close(fd);
+ continue;
+ }
+ /*
+ * Reuse the address on passive sockets to avoid failure on
+ * restart (protocols using listen()) and when creating
+ * multiple listener instances (UDP multicast).
+ */
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on,
+ sizeof(on)) == -1) {
+ close(fd);
+ continue;
+ }
+ if (bind(fd, ai->ai_addr, ai->ai_addrlen) < 0) {
+ close(fd);
+ continue;