src/solaris/native/java/net/PlainSocketImpl.c

Print this page

        

@@ -109,12 +109,12 @@
 
     /*
      * Finally shutdown sv[0] (any reads to this fd will get
      * EOF; any writes will get an error).
      */
-    JVM_SocketShutdown(sv[0], 2);
-    JVM_SocketClose(sv[1]);
+    shutdown(sv[0], 2);
+    close(sv[1]);
 
     return sv[0];
 }
 
 /*

@@ -203,11 +203,11 @@
     if (fdObj == NULL) {
         (*env)->ThrowNew(env, socketExceptionCls, "null fd object");
         return;
     }
 
-    if ((fd = JVM_Socket(domain, type, 0)) == JVM_IO_ERR) {
+    if ((fd = socket(domain, type, 0)) == -1) {
         /* note: if you run out of fds, you may not be able to load
          * the exception class, and get a NoClassDefFoundError
          * instead.
          */
         NET_ThrowNew(env, errno, "can't create socket");

@@ -233,11 +233,11 @@
      */
     ssObj = (*env)->GetObjectField(env, this, psi_serverSocketID);
     if (ssObj != NULL) {
         int arg = 1;
         SET_NONBLOCKING(fd);
-        if (JVM_SetSockOpt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,
+        if (NET_SetSockOpt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,
                            sizeof(arg)) < 0) {
             NET_ThrowNew(env, errno, "cannot set SO_REUSEADDR");
             close(fd);
             return;
         }

@@ -301,11 +301,11 @@
     }
 #endif /* AF_INET6 */
     if (timeout <= 0) {
         connect_rv = NET_Connect(fd, (struct sockaddr *)&him, len);
 #ifdef __solaris__
-        if (connect_rv == JVM_IO_ERR && errno == EINPROGRESS ) {
+        if (connect_rv == -1 && errno == EINPROGRESS ) {
 
             /* This can happen if a blocking connect is interrupted by a signal.
              * See 6343810.
              */
             while (1) {

@@ -328,30 +328,30 @@
 
                     connect_rv = NET_Select(fd+1, 0, &wr, &ex, 0);
                 }
 #endif
 
-                if (connect_rv == JVM_IO_ERR) {
+                if (connect_rv == -1) {
                     if (errno == EINTR) {
                         continue;
                     } else {
                         break;
                     }
                 }
                 if (connect_rv > 0) {
-                    int optlen;
+                    socklen_t optlen;
                     /* has connection been established */
                     optlen = sizeof(connect_rv);
-                    if (JVM_GetSockOpt(fd, SOL_SOCKET, SO_ERROR,
+                    if (getsockopt(fd, SOL_SOCKET, SO_ERROR,
                                         (void*)&connect_rv, &optlen) <0) {
                         connect_rv = errno;
                     }
 
                     if (connect_rv != 0) {
                         /* restore errno */
                         errno = connect_rv;
-                        connect_rv = JVM_IO_ERR;
+                        connect_rv = -1;
                     }
                     break;
                 }
             }
         }

@@ -367,11 +367,11 @@
         /* no need to use NET_Connect as non-blocking */
         connect_rv = connect(fd, (struct sockaddr *)&him, len);
 
         /* connection not established immediately */
         if (connect_rv != 0) {
-            int optlen;
+            socklen_t optlen;
             jlong prevTime = JVM_CurrentTimeMillis(env, 0);
 
             if (errno != EINPROGRESS) {
                 NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
                              "connect failed");

@@ -444,17 +444,17 @@
                  * At the high level it should be closed immediately but
                  * just in case we make the socket blocking again and
                  * shutdown input & output.
                  */
                 SET_BLOCKING(fd);
-                JVM_SocketShutdown(fd, 2);
+                shutdown(fd, 2);
                 return;
             }
 
             /* has connection been established */
             optlen = sizeof(connect_rv);
-            if (JVM_GetSockOpt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
+            if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
                                &optlen) <0) {
                 connect_rv = errno;
             }
         }
 

@@ -462,11 +462,11 @@
         SET_BLOCKING(fd);
 
         /* restore errno */
         if (connect_rv != 0) {
             errno = connect_rv;
-            connect_rv = JVM_IO_ERR;
+            connect_rv = -1;
         }
     }
 
     /* report the appropriate exception */
     if (connect_rv < 0) {

@@ -480,25 +480,24 @@
          * fail with EADDRNOTAVAIL. In addition the Linux kernel
          * returns the wrong error in this case - it returns EINVAL
          * instead of EADDRNOTAVAIL. We handle this here so that
          * a more descriptive exception text is used.
          */
-        if (connect_rv == JVM_IO_ERR && errno == EINVAL) {
+        if (connect_rv == -1 && errno == EINVAL) {
             JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
                 "Invalid argument or cannot assign requested address");
             return;
         }
 #endif
-        if (connect_rv == JVM_IO_INTR) {
-            JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
-                            "operation interrupted");
 #if defined(EPROTO)
-        } else if (errno == EPROTO) {
+        if (errno == EPROTO) {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ProtocolException",
                            "Protocol error");
+            return;
+        }
 #endif
-        } else if (errno == ECONNREFUSED) {
+        if (errno == ECONNREFUSED) {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
                            "Connection refused");
         } else if (errno == ETIMEDOUT) {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
                            "Connection timed out");

@@ -530,12 +529,12 @@
      */
     if (localport == 0) {
         /* Now that we're a connected socket, let's extract the port number
          * that the system chose for us and store it in the Socket object.
          */
-        len = SOCKADDR_LEN;
-        if (JVM_GetSockName(fd, (struct sockaddr *)&him, &len) == -1) {
+        socklen_t slen = SOCKADDR_LEN;
+        if (getsockname(fd, (struct sockaddr *)&him, &slen) == -1) {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
                            "Error getting socket name");
         } else {
             localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
             (*env)->SetIntField(env, this, psi_localportID, localport);

@@ -592,14 +591,15 @@
     /* set the address */
     (*env)->SetObjectField(env, this, psi_addressID, iaObj);
 
     /* initialize the local port */
     if (localport == 0) {
+        socklen_t slen = sizeof(him);
         /* Now that we're a connected socket, let's extract the port number
          * that the system chose for us and store it in the Socket object.
          */
-        if (JVM_GetSockName(fd, (struct sockaddr *)&him, &len) == -1) {
+        if (getsockname(fd, (struct sockaddr *)&him, &slen) == -1) {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
                            "Error getting socket name");
             return;
         }
         localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);

@@ -636,11 +636,11 @@
      * If listen backlog is Integer.MAX_VALUE then subtract 1.
      */
     if (count == 0x7fffffff)
         count -= 1;
 
-    if (JVM_Listen(fd, count) == JVM_IO_ERR) {
+    if (listen(fd, count) == -1) {
         NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
                        "Listen failed");
     }
 }
 

@@ -669,13 +669,11 @@
 
     /* accepted fd */
     jint newfd;
 
     SOCKADDR him;
-    int len;
-
-    len = SOCKADDR_LEN;
+    socklen_t slen = SOCKADDR_LEN;
 
     if (IS_NULL(fdObj)) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
                         "Socket closed");
         return;

@@ -714,24 +712,20 @@
 
         if (ret == 0) {
             JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
                             "Accept timed out");
             return;
-        } else if (ret == JVM_IO_ERR) {
+        } else if (ret == -1) {
             if (errno == EBADF) {
                JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
             } else {
                NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Accept failed");
             }
             return;
-        } else if (ret == JVM_IO_INTR) {
-            JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
-                            "operation interrupted");
-            return;
         }
 
-        newfd = NET_Accept(fd, (struct sockaddr *)&him, (jint*)&len);
+        newfd = NET_Accept(fd, (struct sockaddr *)&him, &slen);
 
         /* connection accepted */
         if (newfd >= 0) {
             SET_BLOCKING(newfd);
             break;

@@ -814,12 +808,12 @@
                         "Socket closed");
         return -1;
     } else {
         fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
     }
-    /* JVM_SocketAvailable returns 0 for failure, 1 for success */
-    if (!JVM_SocketAvailable(fd, &ret)){
+    /* NET_SocketAvailable returns 0 for failure, 1 for success */
+    if (NET_SocketAvailable(fd, &ret) == 0){
         if (errno == ECONNRESET) {
             JNU_ThrowByName(env, "sun/net/ConnectionResetException", "");
         } else {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
                                          "ioctl FIONREAD failed");

@@ -879,11 +873,11 @@
                         "socket already closed");
         return;
     } else {
         fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
     }
-    JVM_SocketShutdown(fd, howto);
+    shutdown(fd, howto);
 }
 
 
 /*
  * Class:     java_net_PlainSocketImpl

@@ -1099,15 +1093,10 @@
             JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
             return;
         }
 
     }
-    n = JVM_Send(fd, (char *)&d, 1, MSG_OOB);
-    if (n == JVM_IO_ERR) {
+    n = NET_Send(fd, (char *)&d, 1, MSG_OOB);
+    if (n == -1) {
         NET_ThrowByNameWithLastError(env, "java/io/IOException", "Write failed");
-        return;
-    }
-    if (n == JVM_IO_INTR) {
-        JNU_ThrowByName(env, "java/io/InterruptedIOException", 0);
-        return;
     }
 }