socket-util: Remove DSCP_INVALID.
[sliver-openvswitch.git] / lib / socket-util.c
index 6554e97..3b21256 100644 (file)
@@ -546,8 +546,7 @@ exit:
  * If 'sinp' is non-null, then on success the target address is stored into
  * '*sinp'.
  *
- * 'dscp'  If not DSCP_INVALID, its value becomes the DSCP bits in the IP
- * headers for the new connection. */
+ * 'dscp' becomes the DSCP bits in the IP headers for the new connection. */
 int
 inet_open_active(int style, const char *target, uint16_t default_port,
                  struct sockaddr_in *sinp, int *fdp, uint8_t dscp)
@@ -571,42 +570,33 @@ inet_open_active(int style, const char *target, uint16_t default_port,
     }
     error = set_nonblocking(fd);
     if (error) {
-        goto exit_close;
+        goto exit;
     }
 
     /* The socket options set here ensure that the TOS bits are set during
      * the connection establishment.  If set after connect(), the handshake
      * SYN frames will be sent with a TOS of 0. */
-    if (dscp != DSCP_INVALID) {
-        if (setsockopt(fd, IPPROTO_IP, IP_TOS, &dscp, sizeof dscp)) {
-            VLOG_ERR("%s: socket: %s", target, strerror(errno));
-            error = errno;
-            goto exit;
-        }
+    if (setsockopt(fd, IPPROTO_IP, IP_TOS, &dscp, sizeof dscp)) {
+        VLOG_ERR("%s: socket: %s", target, strerror(errno));
+        error = errno;
+        goto exit;
     }
 
     /* Connect. */
     error = connect(fd, (struct sockaddr *) &sin, sizeof sin) == 0 ? 0 : errno;
     if (error == EINPROGRESS) {
         error = EAGAIN;
-    } else if (error && error != EAGAIN) {
-        goto exit_close;
     }
 
-    /* Success: error is 0 or EAGAIN. */
-    goto exit;
-
-exit_close:
-    close(fd);
 exit:
     if (!error || error == EAGAIN) {
         if (sinp) {
             *sinp = sin;
         }
-        *fdp = fd;
-    } else {
-        *fdp = -1;
+    } else if (fd >= 0) {
+        close(fd);
     }
+    *fdp = fd;
     return error;
 }
 
@@ -679,8 +669,7 @@ exit:
  * If 'sinp' is non-null, then on success the bound address is stored into
  * '*sinp'.
  *
- * 'dscp'  If not DSCP_INVALID, its value becomes the DSCP bits in the IP
- * headers for the new connection. */
+ * 'dscp' becomes the DSCP bits in the IP headers for the new connection. */
 int
 inet_open_passive(int style, const char *target, int default_port,
                   struct sockaddr_in *sinp, uint8_t dscp)
@@ -721,12 +710,10 @@ inet_open_passive(int style, const char *target, int default_port,
     /* The socket options set here ensure that the TOS bits are set during
      * the connection establishment.  If set after connect(), the handshake
      * SYN frames will be sent with a TOS of 0. */
-    if (dscp != DSCP_INVALID) {
-        if (setsockopt(fd, IPPROTO_IP, IP_TOS, &dscp, sizeof dscp)) {
-            VLOG_ERR("%s: socket: %s", target, strerror(errno));
-            error = errno;
-            goto error;
-        }
+    if (setsockopt(fd, IPPROTO_IP, IP_TOS, &dscp, sizeof dscp)) {
+        VLOG_ERR("%s: socket: %s", target, strerror(errno));
+        error = errno;
+        goto error;
     }
 
     /* Listen. */