This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat-native.git


The following commit(s) were added to refs/heads/master by this push:
     new a3498fa  BZ 64942: Expose support for Unix Domain Sockets in APR v1.6 
and up
a3498fa is described below

commit a3498fa0992ac37c7358e00d1555395b52762e9b
Author: minfrin <minf...@users.noreply.github.com>
AuthorDate: Sun Nov 29 17:31:57 2020 +0000

    BZ 64942: Expose support for Unix Domain Sockets in APR v1.6 and up
    
    This closes #8
---
 java/org/apache/tomcat/jni/Address.java |  5 +++--
 java/org/apache/tomcat/jni/Library.java |  8 ++++++++
 java/org/apache/tomcat/jni/Socket.java  |  1 +
 native/include/tcn.h                    |  9 +++++++++
 native/src/info.c                       |  3 +++
 native/src/jnilib.c                     |  5 +++++
 native/src/network.c                    | 26 ++++++++++++++++++++++++++
 xdocs/index.xml                         | 25 +++++++++++++++++--------
 xdocs/miscellaneous/changelog.xml       |  3 +++
 9 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/java/org/apache/tomcat/jni/Address.java 
b/java/org/apache/tomcat/jni/Address.java
index 2310367..38a08f8 100644
--- a/java/org/apache/tomcat/jni/Address.java
+++ b/java/org/apache/tomcat/jni/Address.java
@@ -40,8 +40,9 @@ public class Address {
 
     /**
      * Create apr_sockaddr_t from hostname, address family, and port.
-     * @param hostname The hostname or numeric address string to 
resolve/parse, or
-     *               NULL to build an address that corresponds to 0.0.0.0 or ::
+     * @param hostname The hostname or numeric address string to 
resolve/parse, the
+     *                 path of the Unix Domain Socket, or NULL to build an 
address
+     *                 that corresponds to 0.0.0.0 or ::
      * @param family The address family to use, or APR_UNSPEC if the system 
should
      *               decide.
      * @param port The port number.
diff --git a/java/org/apache/tomcat/jni/Library.java 
b/java/org/apache/tomcat/jni/Library.java
index c6c1398..a9849d3 100644
--- a/java/org/apache/tomcat/jni/Library.java
+++ b/java/org/apache/tomcat/jni/Library.java
@@ -177,6 +177,12 @@ public final class Library {
     /* Is the O_NONBLOCK flag inherited from listening sockets?
      */
     public static boolean APR_O_NONBLOCK_INHERITED  = false;
+    /* Poll operations are interruptable by apr_pollset_wakeup().
+     */
+    public static boolean APR_POLLSET_WAKEABLE      = false;
+    /* Support for Unix Domain Sockets.
+     */
+    public static boolean APR_HAVE_UNIX             = false;
 
 
     public static int APR_SIZEOF_VOIDP;
@@ -244,6 +250,8 @@ public final class Library {
             APR_CHARSET_EBCDIC      = has(18);
             APR_TCP_NODELAY_INHERITED = has(19);
             APR_O_NONBLOCK_INHERITED  = has(20);
+            APR_POLLSET_WAKEABLE      = has(21);
+            APR_HAVE_UNIX             = has(22);
             if (APR_MAJOR_VERSION < 1) {
                 throw new UnsatisfiedLinkError("Unsupported APR Version (" +
                                                aprVersionString() + ")");
diff --git a/java/org/apache/tomcat/jni/Socket.java 
b/java/org/apache/tomcat/jni/Socket.java
index 976dd38..8882f3b 100644
--- a/java/org/apache/tomcat/jni/Socket.java
+++ b/java/org/apache/tomcat/jni/Socket.java
@@ -79,6 +79,7 @@ public class Socket {
     public static final int APR_UNSPEC = 0;
     public static final int APR_INET   = 1;
     public static final int APR_INET6  = 2;
+    public static final int APR_UNIX   = 3;
 
     public static final int APR_PROTO_TCP  =   6; /** TCP  */
     public static final int APR_PROTO_UDP  =  17; /** UDP  */
diff --git a/native/include/tcn.h b/native/include/tcn.h
index d2f316b..168549f 100644
--- a/native/include/tcn.h
+++ b/native/include/tcn.h
@@ -281,11 +281,20 @@ typedef struct {
 #define APR_INET6 APR_INET
 #endif
 
+#ifdef APR_UNIX
 #define GET_S_FAMILY(T, F)           \
     if (F == 0) T = APR_UNSPEC;      \
     else if (F == 1) T = APR_INET;   \
     else if (F == 2) T = APR_INET6;  \
+    else if (F == 3) T = APR_UNIX;   \
     else T = F
+#else
+#define GET_S_FAMILY(T, F)           \
+    if (F == 0) T = APR_UNSPEC;      \
+    else if (F == 1) T = APR_INET;   \
+    else if (F == 2) T = APR_INET6;  \
+    else T = F
+#endif
 
 #define GET_S_TYPE(T, F)             \
     if (F == 0) T = SOCK_STREAM;     \
diff --git a/native/src/info.c b/native/src/info.c
index 23afa31..4734e54 100644
--- a/native/src/info.c
+++ b/native/src/info.c
@@ -198,6 +198,9 @@ static void fill_ainfo(JNIEnv *e, jobject obj, 
apr_sockaddr_t *info)
     if (info->family == APR_UNSPEC) f = 0;
     else if (info->family == APR_INET) f = 1;
     else if (info->family == APR_INET6) f = 2;
+#ifdef APR_UNIX
+    else if (info->family == APR_UNIX) f = 3;
+#endif
     else f = info->family;
 
     SET_AINFO_J(pool, P2J(info->pool));
diff --git a/native/src/jnilib.c b/native/src/jnilib.c
index 670a311..32f5151 100644
--- a/native/src/jnilib.c
+++ b/native/src/jnilib.c
@@ -431,6 +431,11 @@ TCN_IMPLEMENT_CALL(jboolean, Library, has)(TCN_STDARGS, 
jint what)
             rv = JNI_TRUE;
 #endif
         break;
+        case 22:
+#ifdef APR_UNIX
+            rv = JNI_TRUE;
+#endif
+        break;
     }
     return rv;
 }
diff --git a/native/src/network.c b/native/src/network.c
index 1914ef0..05f0fd2 100644
--- a/native/src/network.c
+++ b/native/src/network.c
@@ -19,6 +19,7 @@
 #ifdef TCN_DO_STATISTICS
 
 #include "apr_atomic.h"
+#include "apr_file_io.h"
 
 static volatile apr_uint32_t sp_created  = 0;
 static volatile apr_uint32_t sp_closed   = 0;
@@ -70,6 +71,26 @@ void sp_network_dump_statistics()
 
 #endif /* TCN_DO_STATISTICS */
 
+static apr_status_t sp_socket_remove(void *data)
+{
+#ifdef APR_UNIX
+    tcn_socket_t *s = (tcn_socket_t *)data;
+
+    if (s->sock) {
+        apr_sockaddr_t *sa = NULL;
+        apr_socket_addr_get(&sa, APR_LOCAL, s->sock);
+        if (sa && sa->family == APR_UNIX) {
+            char *path = NULL;
+            apr_getnameinfo(&path, sa, 0);
+            if (path) {
+                apr_file_remove(path, s->pool);
+            }
+        }
+    }
+#endif
+    return APR_SUCCESS;
+}
+
 extern apr_pool_t *tcn_global_pool;
 static apr_status_t sp_socket_cleanup(void *data)
 {
@@ -316,6 +337,11 @@ TCN_IMPLEMENT_CALL(jint, Socket, bind)(TCN_STDARGS, jlong 
sock,
     TCN_ASSERT(sock != 0);
     TCN_ASSERT(s->sock != NULL);
     rv = (jint)apr_socket_bind(s->sock, a);
+
+    apr_pool_cleanup_register(s->pool, (const void *)s,
+                              sp_socket_remove,
+                              apr_pool_cleanup_null);
+
     return rv;
 }
 
diff --git a/xdocs/index.xml b/xdocs/index.xml
index 518973a..9844af2 100644
--- a/xdocs/index.xml
+++ b/xdocs/index.xml
@@ -52,6 +52,7 @@
     <li>Non-blocking I/O for Keep-Alive requests (between requests)</li>
     <li>Uses OpenSSL for TLS/SSL capabilities (if supported by linked APR 
library)</li>
     <li>FIPS 140-2 support for TLS/SSL (if supported by linked OpenSSL 
library)</li>
+    <li>Support for IPv4, IPv6 and Unix Domain Sockets</li>
   </ul>
 
 </section>
@@ -174,6 +175,14 @@ list of changes.
     <p>
       Please see the Apache Tomcat documentation for configuration specifics.
     </p>
+
+    <p>
+      When using Unix Domain Sockets a cleanup is registered to delete the
+      socket on destruction of the socket, or shutdown of the application.
+      Should the application terminate abnormally, the socket deletion will
+      need to be handled by the caller or by the administrator.
+    </p>
+
   </subsection>
 
 <subsection name="UNIX">
@@ -187,11 +196,11 @@ export LD_LIBRARY_PATH</source>
    Start tomcat and check for the messages like this ones:
   </p>
    <source wrapped="true"
->Feb 8, 2015 12:27:41 PM org.apache.catalina.core.AprLifecycleListener init
+>Nov 29, 2020 12:27:41 PM org.apache.catalina.core.AprLifecycleListener init
 INFO: Loaded APR based Apache Tomcat Native library 1.x.y.
-Feb 8, 2015 12:27:41 PM org.apache.catalina.core.AprLifecycleListener init
-INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], 
random [true].
-Feb 8, 2015 12:27:41 PM org.apache.coyote.http11.Http11AprProtocol init
+Nov 29, 2020 12:27:41 PM org.apache.catalina.core.AprLifecycleListener init
+INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], 
random [true], UDS [true].
+Nov 29, 2020 12:27:41 PM org.apache.coyote.http11.Http11AprProtocol init
 INFO: Initializing Coyote HTTP/1.1 on http-8080</source>
 
   <p>
@@ -214,11 +223,11 @@ INFO: Initializing Coyote HTTP/1.1 on http-8080</source>
     Start tomcat and check for the messages like this ones:
   </p>
   <source wrapped="true"
->Feb 8, 2015 2:48:17 PM org.apache.catalina.core.AprLifecycleListener init
+>Nov 29, 2020 2:48:17 PM org.apache.catalina.core.AprLifecycleListener init
 INFO: Loaded APR based Apache Tomcat Native library 1.x.y.
-Feb 8, 2015 2:48:17 PM org.apache.catalina.core.AprLifecycleListener init
-INFO: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], 
random [true].
-Feb 8, 2015 2:48:18 PM org.apache.coyote.http11.Http11AprProtocol init
+Nov 29, 2020 2:48:17 PM org.apache.catalina.core.AprLifecycleListener init
+INFO: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], 
random [true], UDS [false].
+Nov 29, 2020 2:48:18 PM org.apache.coyote.http11.Http11AprProtocol init
 INFO: Initializing Coyote HTTP/1.1 on http-8080</source>
 
 </subsection>
diff --git a/xdocs/miscellaneous/changelog.xml 
b/xdocs/miscellaneous/changelog.xml
index f607e81..d477712 100644
--- a/xdocs/miscellaneous/changelog.xml
+++ b/xdocs/miscellaneous/changelog.xml
@@ -39,6 +39,9 @@
     <fix>
       Enable building to continue against OpenSSL 3.x and 1.1.1. (markt)
     </fix>
+    <add>
+      <bug>64942<bug>: Expose support for Unix Domain Sockets in APR v1.6 and 
up. (minfrin)
+    </add>
   </changelog>
 </section>
 <section name="Changes in 1.2.25">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to