commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1128654 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/io/ java/org/apache/commons/runtime/net/ native/os/unix/
Date Sat, 28 May 2011 14:47:21 GMT
Author: mturk
Date: Sat May 28 14:47:20 2011
New Revision: 1128654

URL: http://svn.apache.org/viewvc?rev=1128654&view=rev
Log:
Add descriptor configureBlocking api

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IllegalBlockingModeException.java
  (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketDescriptor.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelectorFactory.java
    commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java?rev=1128654&r1=1128653&r2=1128654&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java
Sat May 28 14:47:20 2011
@@ -124,6 +124,22 @@ public abstract class Descriptor impleme
     }
 
     /**
+     * Sets the blocking mode of this descriptor.
+     *
+     * @param block
+     *          {@code true} for setting this descriptor's mode to blocking,
+     *          {@code false} to set it to non-blocking.
+     * @return this descriptor.
+     * @throws ClosedChannelException
+     *          if this descriptr is closed.
+     * @throws IOException
+     *         if an I/O error occurs.
+     */
+    public abstract Descriptor configureBlocking(boolean block)
+        throws ClosedDescriptorException,
+               IOException;
+
+    /**
      * Test wather or not every I/O operation on {@code this} descriptor will
      * block until it completes.
      *

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IllegalBlockingModeException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IllegalBlockingModeException.java?rev=1128654&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IllegalBlockingModeException.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IllegalBlockingModeException.java
Sat May 28 14:47:20 2011
@@ -0,0 +1,38 @@
+/* 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;
+
+/**
+ * An {@code IllegalBlockingModeException} is thrown when an operation that
+ * requires a specific blocking mode is invoked on a endpoint that is in a
+ * different blocking mode.
+ *
+ * @since Runtime 1.0
+ */
+public class IllegalBlockingModeException extends IllegalStateException
+{
+
+    public IllegalBlockingModeException()
+    {
+        super();
+    }
+
+    public IllegalBlockingModeException(String msg)
+    {
+        super(msg);
+    }
+}

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

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketDescriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketDescriptor.java?rev=1128654&r1=1128653&r2=1128654&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketDescriptor.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketDescriptor.java
Sat May 28 14:47:20 2011
@@ -40,6 +40,7 @@ final class LocalSocketDescriptor extend
 
     private static native int close0(int fd);
     private static native int sendz0(int fd);
+    private static native int nonblock0(int fd, boolean block);
 
     public LocalSocketDescriptor()
     {
@@ -79,6 +80,22 @@ final class LocalSocketDescriptor extend
     }
 
     @Override
+    public Descriptor configureBlocking(boolean block)
+        throws ClosedDescriptorException,
+               IOException
+    {
+        if (fd == -1)
+            throw new ClosedDescriptorException();
+        if (blocking == block)
+            return this;
+        int rc = nonblock0(fd, block);
+        if (rc != 0)
+            throw new SocketException(Status.describe(rc));
+        blocking = block;
+        return this;
+    }
+
+    @Override
     public boolean isBlocking()
         throws IOException
     {

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java?rev=1128654&r1=1128653&r2=1128654&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
Sat May 28 14:47:20 2011
@@ -21,13 +21,14 @@ import org.apache.commons.runtime.io.Des
 import org.apache.commons.runtime.net.Endpoint;
 
 /**
- * Selection key.
+ * A {@code SelectionKey} represents the relationship between a endpoint and a
+ * selector for which the endpoint is registered.
  */
 public abstract class SelectionKey
 {
 
     /**
-     * Constructs an instance of this class.
+     * Constructs a new {@code SelectionKey}.
      */
     protected SelectionKey()
     {
@@ -35,15 +36,39 @@ public abstract class SelectionKey
 
     /**
      * Retrieves this key's event set.
+     * The returned set has only those bits set that are valid for
+     * this key's endpoint.
+     *
+     * @return the event set of this key.
      */
     public abstract EnumSet<SelectionEvent> events();
 
     /**
      * Returns the selector for which this key was created.
+     *
+     * @return the related selector.
      */
     public abstract Selector selector();
 
+    /**
+     * Attaches an object to this key.
+     * It is acceptable to attach {@code null}, this discards the
+     * old attachment.
+     *
+     * @param ep
+     *          the endpoint to attach, or {@code null} to discard the current
+     *          attachment.
+     * @return the last attached object or {@code null} if no object has been
+     *         attached.
+     */
     public abstract Endpoint attach(Endpoint ep);
+
+    /**
+     * Gets the attached endpoint.
+     *
+     * @return the attached endpoint or {@code null} if no endpoint has been
+     *         attached.
+     */
     public abstract Endpoint attachment();
     
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java?rev=1128654&r1=1128653&r2=1128654&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
Sat May 28 14:47:20 2011
@@ -36,6 +36,7 @@ final class SocketDescriptor extends Des
 
     private static native int close0(int fd);
     private static native int sendz0(int fd);
+    private static native int nonblock0(int fd, boolean block);
 
     public SocketDescriptor()
     {
@@ -54,7 +55,7 @@ final class SocketDescriptor extends Des
             throw new ClosedDescriptorException(Local.sm.get("socketd.CLOSED"));
         int rc = close0(fd);
         if (rc != 0)
-            throw new SocketException(Status.describe(fd));
+            throw new SocketException(Status.describe(rc));
     }
 
     @Override
@@ -65,7 +66,7 @@ final class SocketDescriptor extends Des
             throw new ClosedDescriptorException();
         int rc = sendz0(fd);
         if (rc != 0)
-            throw new SocketException(Status.describe(fd));
+            throw new SocketException(Status.describe(rc));
     }
 
     @Override
@@ -75,6 +76,23 @@ final class SocketDescriptor extends Des
     }
 
     @Override
+    public Descriptor configureBlocking(boolean block)
+        throws ClosedDescriptorException,
+               IllegalBlockingModeException,
+               IOException
+    {
+        if (fd == -1)
+            throw new ClosedDescriptorException();
+        if (blocking == block)
+            return this;
+        int rc = nonblock0(fd, block);
+        if (rc != 0)
+            throw new SocketException(Status.describe(rc));
+        blocking = block;
+        return this;
+    }
+
+    @Override
     public boolean isBlocking()
         throws IOException
     {

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java?rev=1128654&r1=1128653&r2=1128654&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
Sat May 28 14:47:20 2011
@@ -32,11 +32,20 @@ import org.apache.commons.runtime.io.Des
 public class SocketEndpoint extends Endpoint
 {
     private SocketDescriptor  sd;
+
     /**
      * Creates a new unconnected socket object.
      */
-    private SocketEndpoint()
+    public SocketEndpoint()
+    {
+    }
+
+    /**
+     * Creates a new socket object from socket descriptor.
+     */
+    public SocketEndpoint(SocketDescriptor sd)
     {
+        this.sd = sd;
     }
 
     @Override

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelectorFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelectorFactory.java?rev=1128654&r1=1128653&r2=1128654&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelectorFactory.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelectorFactory.java
Sat May 28 14:47:20 2011
@@ -37,7 +37,9 @@ public final class SocketSelectorFactory
     }
 
     /**
-     * Creates a new selector instance.
+     * Creates a new {@code SocketSelector} instance.
+     *
+     * @return the new selector.
      */
     public static SocketSelector createSelector(int size)
         throws OutOfMemoryError

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=1128654&r1=1128653&r2=1128654&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 Sat May 28 14:47:20 2011
@@ -52,3 +52,8 @@ ACR_NET_EXPORT(jboolean, SocketAddress, 
     else
         return JNI_FALSE;
 }
+
+ACR_NET_EXPORT(jint, SocketDescriptor, nonblock0)(JNI_STDARGS, jint fd, jboolean on)
+{
+    return AcrNonblock(fd, on);
+}

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=1128654&r1=1128653&r2=1128654&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 Sat May 28 14:47:20 2011
@@ -42,3 +42,8 @@ ACR_NET_EXPORT(jint, LocalSocketDescript
     else
         return 0;
 }
+
+ACR_NET_EXPORT(jint, LocakSocketDescriptor, nonblock0)(JNI_STDARGS, jint fd, jboolean on)
+{
+    return AcrNonblock(fd, on);
+}



Mime
View raw message