Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8F39A3568 for ; Fri, 6 May 2011 06:36:56 +0000 (UTC) Received: (qmail 50211 invoked by uid 500); 6 May 2011 06:36:55 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 50113 invoked by uid 500); 6 May 2011 06:36:54 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 50088 invoked by uid 99); 6 May 2011 06:36:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 May 2011 06:36:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 May 2011 06:36:48 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DB05F23889EA; Fri, 6 May 2011 06:36:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1100101 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/shared/ Date: Fri, 06 May 2011 06:36:25 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110506063625.DB05F23889EA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Fri May 6 06:36:25 2011 New Revision: 1100101 URL: http://svn.apache.org/viewvc?rev=1100101&view=rev Log: Add address.next() support Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractSocketAddress.java (with props) Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/EndpointAddress.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractSocketAddress.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractSocketAddress.java?rev=1100101&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractSocketAddress.java (added) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractSocketAddress.java Fri May 6 06:36:25 2011 @@ -0,0 +1,51 @@ +/* + * 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.SocketException; +import java.net.UnknownHostException; +import org.apache.commons.runtime.Memory; +import org.apache.commons.runtime.Status; +import org.apache.commons.runtime.SystemException; +import org.apache.commons.runtime.InvalidArgumentException; + +/** + * This class represents a generic socket endpoint. + * It is used by {@link SocketAddress#next()} to create + * a next address object form internal sockaddr structure. + */ +final class AbstractSocketAddress extends SocketAddress +{ + + private AbstractSocketAddress() + { + // No instance + } + + /** + * Create a new socket address with given family. + */ + public AbstractSocketAddress(AddressFamily family) + throws SystemException, InvalidArgumentException + { + super(family); + } + +} Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractSocketAddress.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/EndpointAddress.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/EndpointAddress.java?rev=1100101&r1=1100100&r2=1100101&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/EndpointAddress.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/EndpointAddress.java Fri May 6 06:36:25 2011 @@ -33,9 +33,10 @@ public abstract class EndpointAddress ex */ private long sa; - private static native void init0(); - private static native int family0(long sa); - private static native void free0(long sa); + private static native void init0(); + private static native int family0(long sa); + private static native void free0(long sa); + private static native boolean hasnext0(long sa); static { init0(); @@ -68,6 +69,14 @@ public abstract class EndpointAddress ex } /** + * Returns {@code true} if the address has more elements. + */ + public final boolean hasNext() + { + return hasnext0(sa); + } + + /** * Called by the garbage collector when the object is destroyed. * The class will free internal resources allocated by the Operating system. * @see Object#finalize() 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=1100101&r1=1100100&r2=1100101&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 Fri May 6 06:36:25 2011 @@ -56,6 +56,8 @@ public abstract class SocketAddress exte throws InvalidArgumentException; private native int sockaddr0(String hostname, int family, int port, int flags); private native boolean equals0(SocketAddress other); + private native int next0(); + private native int next1(SocketAddress next); /** * Creates an new object @@ -159,6 +161,30 @@ public abstract class SocketAddress exte } /** + * Gets the next address. + */ + public SocketAddress next() + { + int family = next0(); + if (family == -1) + return null; + AbstractSocketAddress next; + try { + next = new AbstractSocketAddress(AddressFamily.valueOf(family)); + } catch (Exception e) { + // This should never happen. + // Throw OOM since this is the only logical reason. + throw new OutOfMemoryError(); + } + int rc = next1(next); + if (rc != 0) { + next = null; + throw new RuntimeException("internal error"); + } + return next; + } + + /** * Compares this {@code SocketAddress} to the specified object. * * @param other the reference {@code SocketAddress} with which to compare. 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=1100101&r1=1100100&r2=1100101&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c Fri May 6 06:36:25 2011 @@ -791,6 +791,15 @@ ACR_NET_EXPORT(jint, EndpointAddress, fa return 0; } +ACR_NET_EXPORT(jboolean, EndpointAddress, hasnext0)(JNI_STDARGS, jlong sa) +{ + acr_sockaddr_t *a = J2P(sa, acr_sockaddr_t *); + if (a != 0 && a->next != 0) + return JNI_TRUE; + else + return JNI_FALSE; +} + acr_sockaddr_t * AcrGetSockaddr(JNI_STDARGS) { @@ -874,7 +883,6 @@ ACR_NET_EXPORT(jint, SocketAddress, port return 0; } - ACR_NET_EXPORT(jint, SocketAddress, sockaddr0)(JNI_STDARGS, jstring hostname, jint family, jint port, jint flags) { @@ -920,3 +928,36 @@ ACR_NET_EXPORT(jboolean, SocketAddress, return JNI_FALSE; /* not equal */ } +ACR_NET_EXPORT(jint, SocketAddress, next0)(JNI_STDARGS) +{ + acr_sockaddr_t *sa = AcrGetSockaddr(env, obj); + if (sa == 0) + return -1; + switch (sa->family) { + case AF_INET: + return 1; + case AF_INET6: + return 2; + case AF_LOCAL: + return 3; + default: + break; + } + return 0; +} + +ACR_NET_EXPORT(jint, SocketAddress, next1)(JNI_STDARGS, jobject na) +{ + int rc; + acr_sockaddr_t *sa = AcrGetSockaddr(env, obj); + + if (sa == 0 || sa->next == 0) + return ACR_EBADF; + /* Detach the next address so that + * cleanup can work. + */ + rc = AcrSetSockaddr(env, na, sa->next); + if (rc == 0) + sa->next = 0; + return rc; +}