commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1099790 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/ native/include/acr/ native/os/unix/ native/os/win32/ native/shared/
Date Thu, 05 May 2011 13:39:10 GMT
Author: mturk
Date: Thu May  5 13:39:09 2011
New Revision: 1099790

URL: http://svn.apache.org/viewvc?rev=1099790&view=rev
Log:
Debug version of Service class

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/netdefs.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c
    commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c

Modified: 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=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
Thu May  5 13:39:09 2011
@@ -47,7 +47,7 @@ public final class LocalSocketAddress ex
         super(AddressFamily.LOCAL);
         if (name == null)
             throw new IllegalArgumentException("name can't be null");
-        init(name, AddressFamily.LOCAL);
+        sockaddr(name, AddressFamily.LOCAL);
     }
 
     /**
@@ -60,7 +60,7 @@ public final class LocalSocketAddress ex
         String host = path.getPath();
         if (host == null)
             throw new IllegalArgumentException("path can't be null");
-        init(host, AddressFamily.LOCAL);
+        sockaddr(host, AddressFamily.LOCAL);
     }
 
 }

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java?rev=1099790&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java
Thu May  5 13:39:09 2011
@@ -0,0 +1,93 @@
+/* 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;
+
+/**
+ * Represents tje Internet network service.
+ */
+public final class Service
+{
+    private String      name;
+    private String      proto;
+    private int         port;
+    private String[]    aliases;
+
+    private static native void   init0();
+
+    private native int  getservbyname(String name, String proto);
+    private native int  getservbyport(int port, String proto);
+
+    static {
+        init0();
+    }
+    
+    private Service()
+    {
+        // No instance
+    }
+
+    public Service(String name)
+    {
+        if (name == null)
+            throw new NullPointerException();
+        int rc = getservbyname(name, null);
+    }
+    
+    public Service(String name, String protocol)
+    {
+        if (name == null || protocol == null)
+            throw new NullPointerException();
+        int rc = getservbyname(name, protocol);
+    }
+
+    public Service(int port)
+    {
+        int rc = getservbyport(port, null);
+    }
+
+    public Service(int port, String protocol)
+    {
+        if (protocol == null)
+            throw new NullPointerException();
+        int rc = getservbyport(port, protocol);
+    }
+
+    /**
+     * Gets the service official name.
+     */
+    public String getName()
+    {
+        return name;
+    }
+
+    /**
+     * Gets the protocol to use.
+     */
+    public String getProtocol()
+    {
+        return proto;
+    }
+
+    /**
+     * Gets the service port number.
+     */
+    public int getPort()
+    {
+        return port;
+    }
+
+}

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

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java?rev=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java
Thu May  5 13:39:09 2011
@@ -21,8 +21,10 @@ package org.apache.commons.runtime.net;
 import java.io.File;
 import java.net.SocketException;
 import java.net.UnknownHostException;
+import org.apache.commons.runtime.Errno;
 import org.apache.commons.runtime.Status;
 import org.apache.commons.runtime.SystemException;
+import org.apache.commons.runtime.InvalidArgumentException;
 
 /**
  * This class represents a socket endpoint described by a IP address and a port
@@ -50,8 +52,9 @@ public abstract class SocketAddress exte
     private native String  servname0();
     private native int     port0();
 
-    private native String  ipaddr0();
-    private native int     geti0(String hostname, int family, int port, int flags);
+    private native String  ipaddr0()
+        throws InvalidArgumentException;
+    private native int     sockaddr0(String hostname, int family, int port, int flags);
     private native boolean equals0(SocketAddress other);
 
     /**
@@ -69,20 +72,28 @@ public abstract class SocketAddress exte
         super(family);
     }
 
-    protected void init(String host, AddressFamily family, int port, int flags)
+    protected void sockaddr(String host, AddressFamily family, int port, int flags)
         throws SystemException
     {
-        int rc = geti0(host, family.valueOf(), port, flags);
-        if (rc != 0)
-            throw new SystemException(Status.describe(rc));
+        int rc = sockaddr0(host, family.valueOf(), port, flags);
+        if (rc != 0) {
+            if (rc == Errno.ENOMEM)
+                throw new OutOfMemoryError();
+            else
+                throw new SystemException(Status.describe(rc));
+        }
     }
 
-    protected void init(String host, AddressFamily family)
+    protected void sockaddr(String host, AddressFamily family)
         throws SystemException
     {
-        int rc = geti0(host, family.valueOf(), 0, 0);
-        if (rc != 0)
-            throw new SystemException(Status.describe(rc));
+        int rc = sockaddr0(host, family.valueOf(), 0, 0);
+        if (rc != 0) {
+            if (rc == Errno.ENOMEM)
+                throw new OutOfMemoryError();
+            else
+                throw new SystemException(Status.describe(rc));
+        }
     }
 
     /**

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=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Thu May  5 13:39:09 2011
@@ -119,6 +119,7 @@ LIBSOURCES=\
 	$(TOPDIR)\shared\memory.c \
 	$(TOPDIR)\shared\native.c \
 	$(TOPDIR)\shared\netaddr.c \
+	$(TOPDIR)\shared\netserv.c \
 	$(TOPDIR)\shared\pointer.c \
 	$(TOPDIR)\shared\psock.c \
 	$(TOPDIR)\shared\psockimpl.c \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Thu May  5 13:39:09 2011
@@ -112,6 +112,7 @@ LIBSOURCES=\
 	$(TOPDIR)/shared/memory.c \
 	$(TOPDIR)/shared/native.c \
 	$(TOPDIR)/shared/netaddr.c \
+	$(TOPDIR)/shared/netserv.c \
 	$(TOPDIR)/shared/pointer.c \
 	$(TOPDIR)/shared/psock.c \
 	$(TOPDIR)/shared/psockimpl.c \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h?rev=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h Thu May  5 13:39:09
2011
@@ -126,28 +126,28 @@
 
 #define SET_IFIELD_S(I, O, V)  \
     if ((V)) {                                                              \
-        jstring _str = ACR_NewJavaStringA(env, (V));                        \
+        jstring _str = AcrNewJavaStringA(env, (V));                         \
         (*env)->SetObjectField(env, (O), _f##I##n.i, _str);                 \
         (*env)->DeleteLocalRef(env, _str);                                  \
     } else (void)(0)
 
 #define SET_IFIELD_N(I, O, V)  \
     if ((V) && *(V)) {                                                      \
-        jstring _str = ACR_NewJavaStringA(env, (V));                        \
+        jstring _str = AcrNewJavaStringA(env, (V));                         \
         (*env)->SetObjectField(env, (O), _f##I##n.i, _str);                 \
         (*env)->DeleteLocalRef(env, _str);                                  \
     } else (void)(0)
 
 #define SET_IFIELD_W(I, O, V)  \
     if ((V)) {                                                              \
-        jstring _str = ACR_NewJavaStringW(env, (V));                        \
+        jstring _str = AcrNewJavaStringW(env, (V));                         \
         (*env)->SetObjectField(env, (O), _f##I##n.i, _str);                 \
         (*env)->DeleteLocalRef(env, _str);                                  \
     } else (void)(0)
 
 #define SET_IFIELD_C(I, O, V)  \
     if ((V) && *(V)) {                                                      \
-        jstring _str = ACR_NewJavaStringW(env, (V));                        \
+        jstring _str = AcrNewJavaStringW(env, (V));                         \
         (*env)->SetObjectField(env, (O), _f##I##n.i, _str);                 \
         (*env)->DeleteLocalRef(env, _str);                                  \
     } else (void)(0)
@@ -208,14 +208,14 @@
 
 #define SET_SARRAY_A(A, I, V)                               \
     if ((A) && (V)) {                                       \
-        jstring _str = ACR_NewJavaStringA(env, (V));        \
+        jstring _str = AcrNewJavaStringA(env, (V));         \
         (*env)->SetObjectArrayElement(env, (A), (I), _str); \
         (*env)->DeleteLocalRef(env, _str);                  \
     } else (void)(0)
 
 #define SET_SARRAY_W(A, I, V)                               \
     if ((A) && (V)) {                                       \
-        jstring _str = ACR_NewJavaStringW(env, (V));        \
+        jstring _str = AcrNewJavaStringW(env, (V));         \
         (*env)->SetObjectArrayElement(env, (A), (I), _str); \
         (*env)->DeleteLocalRef(env, _str);                  \
     } else (void)(0)

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h?rev=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h Thu May  5 13:39:09
2011
@@ -18,6 +18,7 @@
 #define _ACR_NETAPI_H_
 
 #include "acr/stdtypes.h"
+#include "acr/jnidefs.h"
 #include "acr/netdefs.h"
 
 typedef struct acr_sockaddr_t acr_sockaddr_t;
@@ -65,6 +66,10 @@ struct acr_sockaddr_t {
 extern "C" {
 #endif
 
+acr_sockaddr_t *AcrGetSockaddr(JNI_STDARGS);
+int     AcrSetSockaddr(JNI_STDARGS, acr_sockaddr_t *sa);
+
+
 #ifdef __cplusplus
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/netdefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/netdefs.h?rev=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/netdefs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/netdefs.h Thu May  5 13:39:09
2011
@@ -60,5 +60,4 @@
 #define ACR_IPV4_ADDR_OK  0x01
 #define ACR_IPV6_ADDR_OK  0x02
 
-
 #endif /* _ACR_IODEFS_H */

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h?rev=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h Thu May  5 13:39:09
2011
@@ -191,6 +191,13 @@ AcrNewJavaStringA(JNI_STDENV, const char
 jstring
 AcrNewJavaStringU(JNI_STDENV, const char *s);
 
+/** Convert platform string array to java string array.
+ * @param env Current JNI environment.
+ * @param s String array to convert. It must be NULL terminated!
+ */
+jobjectArray
+AcrNewStringArrayA(JNI_STDENV, const char **str);
+
 /**
  * Convert the multipart string to Java String array.
  * @param env Current JNI environment.

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c?rev=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c Thu May  5 13:39:09 2011
@@ -17,6 +17,7 @@
 #include "acr/jnitypes.h"
 #include "acr/error.h"
 #include "acr/memory.h"
+#include "acr/netapi.h"
 #include "acr/unsafe.h"
 #include "acr/port.h"
 #include "arch_opts.h"
@@ -38,3 +39,16 @@ ACR_NET_EXPORT(jint, SocketDescriptor, s
     else
         return 0;
 }
+
+ACR_NET_EXPORT(jboolean, SocketAddress, haveipv6)(JNI_STDARGS)
+{
+    int sock;
+
+    sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
+    if (sock != -1) {
+        close(sock);
+        return JNI_TRUE;
+    }
+    else
+        return JNI_FALSE;
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c?rev=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c Thu May  5 13:39:09
2011
@@ -17,6 +17,7 @@
 #include "acr/jnitypes.h"
 #include "acr/error.h"
 #include "acr/memory.h"
+#include "acr/netapi.h"
 #include "acr/unsafe.h"
 #include "acr/port.h"
 #include "arch_opts.h"
@@ -36,3 +37,16 @@ ACR_NET_EXPORT(jint, SocketDescriptor, s
     else
         return 0;
 }
+
+ACR_NET_EXPORT(jboolean, SocketAddress, haveipv6)(JNI_STDARGS)
+{
+    SOCKET sock;
+
+    sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
+    if (sock != INVALID_SOCKET) {
+        closeocket(sock);
+        return JNI_TRUE;
+    }
+    else
+        return JNI_FALSE;
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c?rev=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c Thu May  5 13:39:09 2011
@@ -248,13 +248,16 @@ inet_pton4(const char *src, unsigned cha
                     return 0;
                 saw_digit = 1;
             }
-        } else if (ch == '.' && saw_digit) {
+        }
+        else if (ch == '.' && saw_digit) {
             if (octets == 4)
                 return 0;
             *++tp = 0;
             saw_digit = 0;
-        } else
-                return 0;
+        }
+        else {
+            return 0;
+        }
     }
     if (octets < 4)
         return 0;
@@ -280,7 +283,7 @@ static int
 inet_pton6(const char *src, unsigned char *dst)
 {
     static const char xdigits_l[] = "0123456789abcdef",
-                        xdigits_u[] = "0123456789ABCDEF";
+                      xdigits_u[] = "0123456789ABCDEF";
     unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
     const char *xdigits, *curtok;
     int ch, saw_xdigit;
@@ -305,8 +308,10 @@ inet_pton6(const char *src, unsigned cha
         if (pch != 0) {
             val <<= 4;
             val |= (pch - xdigits);
-            if (val > 0xffff)
-                    return 0;
+            if (val > 0xffff) {
+                /* Invalid range */
+                return 0;
+            }
             saw_xdigit = 1;
             continue;
         }
@@ -401,7 +406,7 @@ int
 AcrGetSockaddrIp(char *buf, int buflen, acr_sockaddr_t *sockaddr)
 {
     if (AcrInetNtop(sockaddr->family, sockaddr->ipaddr, buf, buflen) == 0)
-        return ACR_ENOSPC;
+        return ACR_GET_OS_ERROR();
     if (sockaddr->family == AF_INET6 &&
         IN6_IS_ADDR_V4MAPPED((struct in6_addr *)sockaddr->ipaddr) &&
         buflen > 7) {
@@ -770,6 +775,9 @@ ACR_NET_EXPORT(void, EndpointAddress, fr
 ACR_NET_EXPORT(jint, EndpointAddress, family0)(JNI_STDARGS, jlong sa)
 {
     acr_sockaddr_t *a = J2P(sa, acr_sockaddr_t *);
+
+    if (a == 0)
+        return 0;
     switch (a->family) {
         case AF_INET:
             return 1;
@@ -783,7 +791,8 @@ ACR_NET_EXPORT(jint, EndpointAddress, fa
     return 0;
 }
 
-static acr_sockaddr_t *ea_sockaddr(JNI_STDARGS)
+acr_sockaddr_t *
+AcrGetSockaddr(JNI_STDARGS)
 {
     jlong sa = 0;
 
@@ -800,7 +809,8 @@ static acr_sockaddr_t *ea_sockaddr(JNI_S
     return J2P(sa, acr_sockaddr_t *);
 }
 
-static int set_sockaddr(JNI_STDARGS, acr_sockaddr_t *sa)
+int
+AcrSetSockaddr(JNI_STDARGS, acr_sockaddr_t *sa)
 {
     int rc = ACR_EBADF;
 
@@ -822,7 +832,7 @@ static int set_sockaddr(JNI_STDARGS, acr
 
 ACR_NET_EXPORT(jstring, SocketAddress, hostname0)(JNI_STDARGS)
 {
-    acr_sockaddr_t *sa = ea_sockaddr(env, obj);  
+    acr_sockaddr_t *sa = AcrGetSockaddr(env, obj);
     if (sa != 0 && sa->hostname != '\0')
         return AcrNewJavaStringA(env, sa->hostname);
     else
@@ -831,7 +841,7 @@ ACR_NET_EXPORT(jstring, SocketAddress, h
 
 ACR_NET_EXPORT(jstring, SocketAddress, servname0)(JNI_STDARGS)
 {
-    acr_sockaddr_t *sa = ea_sockaddr(env, obj);
+    acr_sockaddr_t *sa = AcrGetSockaddr(env, obj);
     if (sa != 0 && sa->servname != '\0')
         return AcrNewJavaStringA(env, sa->servname);
     else
@@ -841,23 +851,23 @@ ACR_NET_EXPORT(jstring, SocketAddress, s
 ACR_NET_EXPORT(jstring, SocketAddress, ipaddr0)(JNI_STDARGS)
 {
     char buf[256];
-    acr_sockaddr_t *sa = ea_sockaddr(env, obj);
+    acr_sockaddr_t *sa = AcrGetSockaddr(env, obj);
 
     if (sa == 0) {
-        ACR_THROW(ACR_EX_EINVAL, 0);
+        ACR_THROW(ACR_EX_ENULL, 0);
         return 0;
     }
     if (AcrGetSockaddrIp(buf, 256, sa) == 0)
         return AcrNewJavaStringA(env, buf);
     else {
-        ACR_THROW(ACR_EX_ENOMEM, ACR_ENOSPC);
+        ACR_THROW_OS_ERROR(ACR_EX_EINVAL);
         return 0;
     }
 }
 
 ACR_NET_EXPORT(jint, SocketAddress, port0)(JNI_STDARGS)
 {
-    acr_sockaddr_t *sa = ea_sockaddr(env, obj);
+    acr_sockaddr_t *sa = AcrGetSockaddr(env, obj);
     if (sa != 0)
         return sa->port;
     else
@@ -865,8 +875,8 @@ ACR_NET_EXPORT(jint, SocketAddress, port
 }
 
 
-ACR_NET_EXPORT(jint, SocketAddress, geti0)(JNI_STDARGS, jstring hostname,
-                                           jint family, jint port, jint flags)
+ACR_NET_EXPORT(jint, SocketAddress, sockaddr0)(JNI_STDARGS, jstring hostname,
+                                               jint family, jint port, jint flags)
 {
     acr_sockaddr_t *sa = 0;
     int ffamily = AF_UNSPEC;
@@ -888,14 +898,14 @@ ACR_NET_EXPORT(jint, SocketAddress, geti
     } DONE_WITH_STR(hostname);
 
     if (rc == 0)
-        rc = set_sockaddr(env, obj, sa);
+        rc = AcrSetSockaddr(env, obj, sa);
     return rc;
 }
 
 ACR_NET_EXPORT(jboolean, SocketAddress, equals0)(JNI_STDARGS, jobject sa2)
 {
-    acr_sockaddr_t *addr1 = ea_sockaddr(env, obj);
-    acr_sockaddr_t *addr2 = ea_sockaddr(env, sa2);
+    acr_sockaddr_t *addr1 = AcrGetSockaddr(env, obj);
+    acr_sockaddr_t *addr2 = AcrGetSockaddr(env, sa2);
 
     if (addr1 == 0 || addr2 == 0)
         return JNI_FALSE;
@@ -909,3 +919,4 @@ ACR_NET_EXPORT(jboolean, SocketAddress, 
         return JNI_TRUE;
     return JNI_FALSE; /* not equal */
 }
+

Added: commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c?rev=1099790&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c Thu May  5 13:39:09 2011
@@ -0,0 +1,125 @@
+/* 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.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr/netapi.h"
+#include "acr/memory.h"
+#include "acr/string.h"
+#include "acr/port.h"
+#include "acr/unsafe.h"
+
+J_DECLARE_CLAZZ = {
+    INVALID_FIELD_OFFSET,
+    0,
+    0,
+    0,
+    ACR_NET_CP "Service"
+};
+
+J_DECLARE_F_ID(0000) = {
+    INVALID_FIELD_OFFSET,
+    INVALID_FIELD_OFFSET,
+    0,
+    "name",
+    "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0001) = {
+    INVALID_FIELD_OFFSET,
+    INVALID_FIELD_OFFSET,
+    0,
+    "proto",
+    "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0002) = {
+    INVALID_FIELD_OFFSET,
+    INVALID_FIELD_OFFSET,
+    0,
+    "aliases",
+    "[Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0003) = {
+    INVALID_FIELD_OFFSET,
+    INVALID_FIELD_OFFSET,
+    0,
+    "port",
+    "I"
+};
+
+ACR_NET_EXPORT(void, Service, init0)(JNI_STDARGS)
+{
+    _clazzn.i = (jclass)(*env)->NewGlobalRef(env, obj);
+    if (_clazzn.i == 0)
+        return;
+    V_LOAD_IFIELD(0000);
+    V_LOAD_IFIELD(0001);
+    V_LOAD_IFIELD(0002);
+    V_LOAD_IFIELD(0003);
+    _clazzn.u = 1;
+}
+
+ACR_NET_EXPORT(jint, Service, getservbyname)(JNI_STDARGS, jstring name, jstring proto)
+{
+    int rc = 0;
+    struct servent *se;
+
+    WITH_CSTR(name) {
+    WITH_CSTR(proto) {
+        if ((se = getservbyname(J2S(name), J2S(proto))) == 0)
+            rc = ACR_GET_NETOS_ERROR();
+        else {
+            printf("Found1 http %d\n", (int)se->s_port);
+            fflush(stdout);
+            SET_IFIELD_S(0000, obj, se->s_name);
+            SET_IFIELD_S(0001, obj, se->s_proto);
+            SET_IFIELD_O(0002, obj, AcrNewStringArrayA(env, (const char **)se->s_aliases));
+            SET_IFIELD_I(0003, obj, se->s_port);
+        }
+    } DONE_WITH_STR(proto);
+    } DONE_WITH_STR(name);
+
+    return rc;
+}
+
+ACR_NET_EXPORT(jint, Service, getservbyport)(JNI_STDARGS, jint port, jstring proto)
+{
+    int rc = 0;
+    struct servent *se;
+
+    WITH_CSTR(proto) {
+        if ((se = getservbyport(port, J2S(proto))) == 0) {
+            rc = ACR_GET_NETOS_ERROR();
+            printf("Failed for port %d %d %s\n", port, rc, J2S(proto));
+            fflush(stdout);
+        }
+        else {
+            printf("Found2 http %s for %d  %s\n", se->s_name, port, J2S(proto));
+            fflush(stdout);
+            SET_IFIELD_S(0000, obj, se->s_name);
+            SET_IFIELD_S(0001, obj, se->s_proto);
+            SET_IFIELD_O(0002, obj, AcrNewStringArrayA(env, (const char **)se->s_aliases));
+            SET_IFIELD_I(0003, obj, se->s_port);
+        }
+    } DONE_WITH_STR(proto);
+
+    return rc;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1099790&r1=1099789&r2=1099790&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Thu May  5 13:39:09 2011
@@ -1184,6 +1184,36 @@ AcrNewJavaStringU(JNI_STDENV, const char
         return new_string_utf_8(env, str);
 }
 
+jobjectArray
+AcrNewStringArrayA(JNI_STDENV, const char **str)
+{
+    jobjectArray arr = 0;
+    jsize n = 0;
+    const char **sa = str;
+
+    if (str != 0 && *str != 0) {
+        while (*(sa++) != 0) {
+            n++;
+        }
+        arr = AcrNewCoreObjectArray(env, ACR_CC_STRING, n);
+    }
+    if (arr == 0)
+        return 0;
+
+    n  = 0;
+    sa = str;
+    while (*sa != 0) {
+        jstring s = AcrNewJavaStringA(env, *sa);
+        if (s != 0) {
+            (*env)->SetObjectArrayElement(env, arr, n, s);
+            (*env)->DeleteLocalRef(env, s);
+        }
+        n++;
+        sa++;
+    }
+    return arr;
+}
+
 void AcrFreeStringArray(void **arr)
 {
     if (arr != 0) {



Mime
View raw message