commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1098507 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ java/org/apache/commons/runtime/net/ native/ native/os/unix/ native/os/win32/
Date Mon, 02 May 2011 08:09:34 GMT
Author: mturk
Date: Mon May  2 08:09:34 2011
New Revision: 1098507

URL: http://svn.apache.org/viewvc?rev=1098507&view=rev
Log:
Add local socket address implementation"

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java?rev=1098507&r1=1098506&r2=1098507&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java Mon
May  2 08:09:34 2011
@@ -158,6 +158,6 @@ final class Platform
      */
     public static final long    SHMMAX;
 
-    
+
 }
 

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java?rev=1098507&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
Mon May  2 08:09:34 2011
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.runtime.net;
+
+import java.io.File;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import org.apache.commons.runtime.Memory;
+import org.apache.commons.runtime.Status;
+
+public final class LocalSocketAddress extends SocketAddress
+{
+
+    private static native String prefix0();
+    private static final  String prefix;
+    static {
+        prefix = prefix0();
+
+    }
+    private LocalSocketAddress()
+    {
+        // No instance
+    }
+
+    private long    addr;
+    private String  path;
+    public LocalSocketAddress(String name)
+    {
+        if (name == null)
+            throw new NullPointerException();
+        StringBuilder pn = new StringBuilder(prefix);
+        // Normalize the pipe or unix socket name
+        //
+        for (int i = 0; i < name.length(); i++) {
+            char c = name.charAt(i);
+            if (c == '\\' || c == '/')
+                c = '_';
+            pn.append(c);
+        }
+        path = pn.toString();
+    }
+
+    public LocalSocketAddress(File path)
+    {
+        if (path == null)
+            throw new NullPointerException();
+        // path is presumed to be correctly
+        // formatted.
+        this.path = path.getPath();
+    }
+
+    /**
+     * Called by the garbage collector when the object is destroyed.
+     * The class will free internal resources allocated by the Operating system.
+     * @see Object#finalize()
+     * @throws Throwable the {@code Exception} raised by this method.
+     */
+    @Override
+    protected final void finalize()
+        throws Throwable
+    {
+        if (addr != 0)
+            Memory.free(addr);
+    }
+    
+
+    @Override
+    public String toString()
+    {
+        return this.path;
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=1098507&r1=1098506&r2=1098507&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Mon May  2 08:09:34 2011
@@ -90,7 +90,8 @@ WIN32_SOURCES=\
 	$(TOPDIR)\os\win32\shmem.c \
 	$(TOPDIR)\os\win32\time.c \
 	$(TOPDIR)\os\win32\util.c \
-	$(TOPDIR)\os\win32\winapi.c
+	$(TOPDIR)\os\win32\winapi.c \
+	$(TOPDIR)\os\win32\wpipe.c
 
 
 LIBSOURCES=\

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h?rev=1098507&r1=1098506&r2=1098507&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h Mon May  2 08:09:34
2011
@@ -99,6 +99,9 @@ typedef struct stat         struct_stat_
 #ifndef SHELL_PATH
 # define SHELL_PATH         "/bin/sh"
 #endif
+#ifndef VAR_RUN_PATH
+# define VAR_RUN_PATH       "/var/run"
+#endif
 
 #if defined(F_DUPFD)
 #define FD_ABOVE_STDFILENO(D)           \

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c?rev=1098507&r1=1098506&r2=1098507&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c Mon May  2 08:09:34 2011
@@ -18,8 +18,39 @@
 #include "acr/iodefs.h"
 #include "acr/socks.h"
 #include "acr/clazz.h"
+#include "acr/string.h"
+#include "acr/memory.h"
 #include "acr/iofd.h"
 #include "acr/unsafe.h"
+#include "acr/port.h"
 #include "arch_opts.h"
 #include <poll.h>
+#include <sys/un.h>
 
+#if !HAVE_SYS_UN_H
+# error Missing sys/un.h header
+#endif
+
+ACR_NET_EXPORT(jstring, LocalSocketAddress, prefix0)(JNI_STDARGS)
+{
+    return CSTR_TO_JSTRING(VAR_RUN_PATH "/");
+}
+
+ACR_NET_EXPORT(jlong, LocalSocketAddress, addr0)(JNI_STDARGS, jstring name)
+{
+    struct sockaddr_un *un = 0;
+
+    un = ACR_TALLOC(struct sockaddr_un);
+    if (un == 0)
+        return 0;
+    WITH_CSTR(name) {
+        size_t len = strlcpy(un->sun_path, J2S(name), sizeof(un->sun_path));
+        if (len >= sizeof(un->sun_path)) {
+            AcrFree(un);
+            un = 0;
+            ACR_THROW(ACR_EX_ERANGE, 0);
+        }
+
+    } DONE_WITH_STR(name);
+    return P2J(un);
+}

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c?rev=1098507&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c Mon May  2 08:09:34 2011
@@ -0,0 +1,43 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/error.h"
+#include "acr/iodefs.h"
+#include "acr/socks.h"
+#include "acr/clazz.h"
+#include "acr/string.h"
+#include "acr/iofd.h"
+#include "acr/unsafe.h"
+#include "arch_opts.h"
+
+ACR_NET_EXPORT(jstring, LocalSocketAddress, prefix0)(JNI_STDARGS)
+{
+    return WSTR_TO_JSTRING(L"\\\\.\\PIPE\\");
+}
+
+ACR_NET_EXPORT(jlong, LocalSocketAddress, addr0)(JNI_STDARGS, jstring name)
+{
+    wchar_t *addr = 0;
+
+    WITH_WSTR(name) {
+        addr = wcsdup(J2S(name));
+        if (addr == 0) {
+            ACR_THROW(ACR_EX_ENOMEM, 0);
+        }
+
+    } DONE_WITH_STR(name);
+    return P2J(addr);
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message