moved unix socket address out of SOCKETADDRESS structure unixdomainchannels
authormichaelm
Mon, 11 Nov 2019 20:27:27 +0000
branchunixdomainchannels
changeset 59018 6d621f34e24a
parent 59013 d39e1bf999f6
child 59019 dafa6389ed47
moved unix socket address out of SOCKETADDRESS structure
src/java.base/share/native/libnet/net_util.h
src/java.base/unix/native/libnio/ch/InheritedChannel.c
src/java.base/unix/native/libnio/ch/Net.c
src/java.base/windows/native/libnio/ch/Net.c
--- a/src/java.base/share/native/libnet/net_util.h	Mon Nov 11 14:25:51 2019 +0000
+++ b/src/java.base/share/native/libnet/net_util.h	Mon Nov 11 20:27:27 2019 +0000
@@ -166,10 +166,10 @@
 NET_SockaddrToInetAddress(JNIEnv *env, SOCKETADDRESS *sa, int *port);
 
 JNIEXPORT jobject JNICALL
-NET_SockaddrToUnixAddress(JNIEnv *env, SOCKETADDRESS *sa);
+NET_SockaddrToUnixAddress(JNIEnv *env, struct sockaddr_un *sa);
 
 JNIEXPORT jint JNICALL
-NET_UnixSocketAddressToSockaddr(JNIEnv *env, jobject uaddr, SOCKETADDRESS *sa, int *len);
+NET_UnixSocketAddressToSockaddr(JNIEnv *env, jobject uaddr, struct sockaddr_un *sa, int *len);
 
 void platformInit();
 
--- a/src/java.base/unix/native/libnio/ch/InheritedChannel.c	Mon Nov 11 14:25:51 2019 +0000
+++ b/src/java.base/unix/native/libnio/ch/InheritedChannel.c	Mon Nov 11 20:27:27 2019 +0000
@@ -71,12 +71,12 @@
 JNIEXPORT jobject JNICALL
 Java_sun_nio_ch_InheritedChannel_peerAddressUnix(JNIEnv *env, jclass cla, jint fd)
 {
-    SOCKETADDRESS sa;
-    socklen_t len = sizeof(SOCKETADDRESS);
+    struct sockaddr_un sa;
+    socklen_t len = sizeof(struct sockaddr_un);
     jobject remote_sa = NULL;
 
-    if (getpeername(fd, &sa.sa, &len) == 0) {
-        if (sa.sa.sa_family == AF_UNIX) {
+    if (getpeername(fd, (struct sockaddr *)&sa, &len) == 0) {
+        if (sa.sun_family == AF_UNIX) {
             remote_sa = NET_SockaddrToUnixAddress(env, &sa);
         }
     }
@@ -90,7 +90,7 @@
     socklen_t len = sizeof(SOCKETADDRESS);
     jint remote_port = -1;
 
-    if (getpeername(fd, &sa.sa, &len) == 0) {
+    if (getpeername(fd, (struct sockaddr *)&sa.sa, &len) == 0) {
         if (matchFamilyInet(&sa)) {
             NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
         }
--- a/src/java.base/unix/native/libnio/ch/Net.c	Mon Nov 11 14:25:51 2019 +0000
+++ b/src/java.base/unix/native/libnio/ch/Net.c	Mon Nov 11 20:27:27 2019 +0000
@@ -52,10 +52,10 @@
 extern jfieldID udsa_pathID;
 
 JNIEXPORT jobject JNICALL
-NET_SockaddrToUnixAddress(JNIEnv *env, SOCKETADDRESS *sa) {
+NET_SockaddrToUnixAddress(JNIEnv *env, struct sockaddr_un *sa) {
 
-    if (sa->sa.sa_family == AF_UNIX) {
-        char *name = sa->saun.sun_path;
+    if (sa->sun_family == AF_UNIX) {
+        char *name = sa->sun_path;
 
         jstring nstr = JNU_NewStringPlatform(env, name);
         return (*env)->NewObject(env, udsa_class, udsa_ctorID, nstr);
@@ -64,21 +64,21 @@
 }
 
 JNIEXPORT jint JNICALL
-NET_UnixSocketAddressToSockaddr(JNIEnv *env, jobject uaddr, SOCKETADDRESS *sa, int *len)
+NET_UnixSocketAddressToSockaddr(JNIEnv *env, jobject uaddr, struct sockaddr_un *sa, int *len)
 {
     jstring path = (*env)->GetObjectField(env, uaddr, udsa_pathID);
     jboolean isCopy;
     int ret;
     const char* pname = JNU_GetStringPlatformChars(env, path, &isCopy);
-    memset(sa, 0, sizeof(SOCKETADDRESS));
-    sa->saun.sun_family = AF_UNIX;
+    memset(sa, 0, sizeof(struct sockaddr_un));
+    sa->sun_family = AF_UNIX;
     int name_len = strlen(pname) + 1; /* includes null termination */
     if (name_len > MAX_UNIX_DOMAIN_PATH_LEN) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "unix domain path too long");
         ret = 1;
         goto finish;
     }
-    strncpy(&sa->saun.sun_path[0], pname, name_len);
+    strncpy(&sa->sun_path[0], pname, name_len);
     *len = offsetof(struct sockaddr_un, sun_path) + name_len;
     ret = 0;
   finish:
@@ -106,7 +106,7 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_ch_Net_unixDomainBind(JNIEnv *env, jclass clazz, jobject fdo, jobject uaddr)
 {
-    SOCKETADDRESS sa;
+    struct sockaddr_un sa;
     int sa_len = 0;
     int rv = 0;
 
@@ -115,7 +115,7 @@
 
     int fd = fdval(env, fdo);
 
-    rv = NET_Bind(fdval(env, fdo), &sa, sa_len);
+    rv = bind(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
     if (rv != 0) {
         handleSocketError(env, errno);
     }
@@ -124,7 +124,7 @@
 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_Net_unixDomainConnect(JNIEnv *env, jclass clazz, jobject fdo, jobject usa)
 {
-    SOCKETADDRESS sa;
+    struct sockaddr_un sa;
     int sa_len = 0;
     int rv;
 
@@ -132,7 +132,7 @@
         return IOS_THROWN;
     }
 
-    rv = connect(fdval(env, fdo), &sa.sa, sa_len);
+    rv = connect(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
     if (rv != 0) {
         if (errno == EINPROGRESS) {
             return IOS_UNAVAILABLE;
@@ -150,13 +150,13 @@
 {
     jint fd = fdval(env, fdo);
     jint newfd;
-    SOCKETADDRESS sa;
-    socklen_t sa_len = sizeof(SOCKETADDRESS);
+    struct sockaddr_un sa;
+    socklen_t sa_len = sizeof(struct sockaddr_un);
     jobject usa;
 
     /* accept connection but ignore ECONNABORTED */
     for (;;) {
-        newfd = accept(fd, &sa.sa, &sa_len);
+        newfd = accept(fd, (struct sockaddr *)&sa, &sa_len);
         if (newfd >= 0) {
             break;
         }
@@ -188,10 +188,10 @@
 JNIEXPORT jobject JNICALL
 Java_sun_nio_ch_Net_localUnixAddress(JNIEnv *env, jclass clazz, jobject fdo)
 {
-    SOCKETADDRESS sa;
-    socklen_t sa_len = sizeof(SOCKETADDRESS);
+    struct sockaddr_un sa;
+    socklen_t sa_len = sizeof(struct sockaddr_un);
     int port;
-    if (getsockname(fdval(env, fdo), &sa.sa, &sa_len) < 0) {
+    if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
         handleSocketError(env, errno);
         return NULL;
     }
--- a/src/java.base/windows/native/libnio/ch/Net.c	Mon Nov 11 14:25:51 2019 +0000
+++ b/src/java.base/windows/native/libnio/ch/Net.c	Mon Nov 11 20:27:27 2019 +0000
@@ -91,10 +91,10 @@
 extern jfieldID udsa_pathID;
 
 JNIEXPORT jobject JNICALL
-NET_SockaddrToUnixAddress(JNIEnv *env, SOCKETADDRESS *sa) {
+NET_SockaddrToUnixAddress(JNIEnv *env, struct sockaddr_un *sa) {
 
-    if (sa->sa.sa_family == AF_UNIX) {
-        char *name = sa->saun.sun_path;
+    if (sa->sun_family == AF_UNIX) {
+        char *name = sa->sun_path;
 
         jstring nstr = JNU_NewStringPlatform(env, name);
         return (*env)->NewObject(env, udsa_class, udsa_ctorID, nstr);
@@ -103,21 +103,21 @@
 }
 
 JNIEXPORT jint JNICALL
-NET_UnixSocketAddressToSockaddr(JNIEnv *env, jobject uaddr, SOCKETADDRESS *sa, int *len)
+NET_UnixSocketAddressToSockaddr(JNIEnv *env, jobject uaddr, struct sockaddr_un *sa, int *len)
 {
     jstring path = (*env)->GetObjectField(env, uaddr, udsa_pathID);
     jboolean isCopy;
     int ret;
     const char* pname = JNU_GetStringPlatformChars(env, path, &isCopy);
-    memset(sa, 0, sizeof(SOCKETADDRESS));
-    sa->saun.sun_family = AF_UNIX;
+    memset(sa, 0, sizeof(struct sockaddr_un));
+    sa->sun_family = AF_UNIX;
     size_t name_len = strlen(pname)+1;
     if (name_len > MAX_UNIX_DOMAIN_PATH_LEN) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "unix domain path too long");
         ret = 1;
         goto finish;
     }
-    strncpy(sa->saun.sun_path, pname, name_len);
+    strncpy(sa->sun_path, pname, name_len);
     *len = (int)(offsetof(struct sockaddr_un, sun_path) + name_len);
     ret = 0;
   finish:
@@ -150,7 +150,7 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_ch_Net_unixDomainBind(JNIEnv *env, jclass clazz, jobject fdo, jobject uaddr)
 {
-    SOCKETADDRESS sa;
+    struct sockaddr_un sa;
     int sa_len = 0;
     int rv = 0;
 
@@ -159,7 +159,7 @@
 
     int fd = fdval(env, fdo);
 
-    rv = NET_Bind(fdval(env, fdo), &sa, sa_len);
+    rv = bind(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
     if (rv != 0) {
         int err = WSAGetLastError();
         NET_ThrowNew(env, err, "bind");
@@ -169,7 +169,7 @@
 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_Net_unixDomainConnect(JNIEnv *env, jclass clazz, jobject fdo, jobject usa)
 {
-    SOCKETADDRESS sa;
+    struct sockaddr_un sa;
     int sa_len = 0;
     int rv;
 
@@ -177,7 +177,7 @@
         return IOS_THROWN;
     }
 
-    rv = connect(fdval(env, fdo), (const struct sockaddr *)&sa.saun, sa_len);
+    rv = connect(fdval(env, fdo), (const struct sockaddr *)&sa, sa_len);
     if (rv != 0) {
         int err = WSAGetLastError();
         if (err == WSAEINPROGRESS || err == WSAEWOULDBLOCK) {
@@ -195,13 +195,13 @@
 {
     jint fd = fdval(env, fdo);
     jint newfd;
-    SOCKETADDRESS sa;
-    socklen_t sa_len = sizeof(SOCKETADDRESS);
+    struct sockaddr_un sa;
+    socklen_t sa_len = sizeof(sa);
     jobject usa;
 
     /* accept connection but ignore ECONNABORTED */
     for (;;) {
-        newfd = (jint)accept(fd, &sa.sa, &sa_len);
+        newfd = (jint)accept(fd, (struct sockaddr_un *)&sa, &sa_len);
         if (newfd >= 0) {
             break;
         }
@@ -233,9 +233,9 @@
 JNIEXPORT jobject JNICALL
 Java_sun_nio_ch_Net_localUnixAddress(JNIEnv *env, jclass clazz, jobject fdo)
 {
-    SOCKETADDRESS sa;
-    socklen_t sa_len = sizeof(SOCKETADDRESS);
-    if (getsockname(fdval(env, fdo), &sa.sa, &sa_len) < 0) {
+    struct sockaddr_un sa;
+    socklen_t sa_len = sizeof(sa);
+    if (getsockname(fdval(env, fdo), (struct sockaddr_un *)&sa, &sa_len) < 0) {
         handleSocketError(env, errno);
         return NULL;
     }