commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1130502 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net: EndpointAddress.java LocalEndpoint.java LocalServerEndpoint.java LocalStrings.properties
Date Thu, 02 Jun 2011 11:41:33 GMT
Author: mturk
Date: Thu Jun  2 11:41:32 2011
New Revision: 1130502

URL: http://svn.apache.org/viewvc?rev=1130502&view=rev
Log:
Add LocalServerEndpoint skeleton

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.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/LocalEndpoint.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalStrings.properties

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=1130502&r1=1130501&r2=1130502&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
Thu Jun  2 11:41:32 2011
@@ -25,8 +25,8 @@ public abstract class EndpointAddress
 {
     /**
      * Native representation of {@code this} address.
-     * This is pointer to Operating System sockaddr structure and is used
-     * used internally by socket functions.
+     * This is pointer to the operating system sockaddr structure and is used
+     * used internally by implementation methods.
      */
     protected byte[] sa;
 
@@ -57,6 +57,16 @@ public abstract class EndpointAddress
     }
 
     /**
+     * Returns the raw address of this endpoint.
+     *
+     * @return the raw address of this object.
+     */
+    public final byte[] sockaddr()
+    {
+        return sa;
+    }
+
+    /**
      * Get the address family to which the endpoint belongs.
      */
     public final AddressFamily getFamily()

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java?rev=1130502&r1=1130501&r2=1130502&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
Thu Jun  2 11:41:32 2011
@@ -46,7 +46,7 @@ public class LocalEndpoint extends Endpo
     /**
      * Creates a new unconnected socket object.
      */
-    private LocalEndpoint()
+    public LocalEndpoint()
     {
         super(EndpointType.LOCAL);
         this.sd = new LocalDescriptor();

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java?rev=1130502&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
Thu Jun  2 11:41:32 2011
@@ -0,0 +1,172 @@
+/*
+ * 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.Closeable;
+import java.io.Flushable;
+import java.io.IOException;
+import java.io.SyncFailedException;
+import java.net.SocketException;
+import org.apache.commons.runtime.io.ClosedDescriptorException;
+import org.apache.commons.runtime.io.Descriptor;
+import org.apache.commons.runtime.OverflowException;
+import org.apache.commons.runtime.Status;
+
+/**
+ * This class represents a local server endpoint.
+ * <p>
+ * Local socket represents either unix domain socket or a windows pipe,
+ * depending on the operating system.
+ * </p>
+ */
+public class LocalServerEndpoint extends Endpoint
+{
+    private final LocalDescriptor       sd;
+    private SelectionKeyImpl            key;
+    private LocalEndpointAddress        sa;
+    private boolean                     blocking = false;
+    private boolean                     bound    = false;
+
+    private static native int           nonblock0(int fd, boolean block);
+
+    /**
+     * Creates a new unbound local server endpoint.
+     */
+    private LocalServerEndpoint()
+    {
+        super(EndpointType.LOCAL);
+        this.sd = new LocalDescriptor();
+    }
+
+    /**
+     * Creates a new local server endpoint from the
+     * given socket descriptor.
+     */
+    public LocalServerEndpoint(LocalDescriptor sd)
+    {
+        super(EndpointType.LOCAL);
+        if (sd == null)
+            throw new NullPointerException();
+        this.sd = sd;
+    }
+
+    @Override
+    public Descriptor descriptor()
+    {
+        return sd;
+    }
+
+    @Override
+    public boolean isBlocking()
+        throws IOException
+    {
+        return blocking;
+    }
+
+    @Override
+    public Descriptor configureBlocking(boolean block)
+        throws ClosedDescriptorException,
+               IllegalBlockingModeException,
+               IOException
+    {
+        if (sd.closed())
+            throw new ClosedDescriptorException();
+        if (key != null && key.selected)
+            throw new IllegalBlockingModeException();
+        if (blocking == block)
+            return sd;
+        int rc = nonblock0(sd.fd(), block);
+        if (rc != 0)
+            throw new SocketException(Status.describe(rc));
+        blocking = block;
+        return sd;
+    }
+
+
+    @Override
+    public void close()
+        throws IOException
+    {
+        if (sd.valid()) {
+            if (key != null && key.selected) {
+                try {
+                    key.cancel();
+                } catch (Exception e) {
+                    // Ignore selector exceptions
+                }
+            }
+            sd.close();
+        }
+        if (key != null) {
+            key.reset();
+            key = null;
+        }
+    }
+
+    @Override
+    public SelectionKey keyFor(Selector selector)
+    {
+        if (key != null && key.selector == selector && key.ievents != 0)
+            return key;
+        else
+            return null;
+    }
+
+    @Override
+    public SelectionKey register(Selector selector, int ops, Object att)
+        throws ClosedSelectorException,
+               IllegalSelectorException,
+               ClosedDescriptorException,
+               OverflowException,
+               IOException
+    {
+        ops = ops & 0x000f;
+        if (sd.closed())
+            throw new ClosedDescriptorException();
+        AbstractSelector sel = (AbstractSelector)selector;
+        //
+        // If key.ievents is zero, this means that the
+        // key was invalidated by Selector.close().
+        // In that case create a new key instance.
+        if (key == null || key.ievents == 0)
+            key = new SelectionKeyImpl(sel, this);
+        if (key.selector != sel)
+            throw new IllegalSelectorException();
+        if (att != null)
+            key.attach(att);
+        return key.queue(ops);
+    }
+
+    public void bind(LocalEndpointAddress endpoint)
+        throws IOException
+    {
+        if (bound)
+            throw new IOException(Local.sm.get("endpoint.EBOUND"));
+        // TODO: Implement bind
+    }
+
+    public LocalEndpoint accept()
+        throws IOException
+    {
+        LocalEndpoint ep = new LocalEndpoint();
+
+        // TODO: Implement accept
+        return ep;
+    }
+}

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

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalStrings.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalStrings.properties?rev=1130502&r1=1130501&r2=1130502&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalStrings.properties
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalStrings.properties
Thu Jun  2 11:41:32 2011
@@ -18,3 +18,4 @@ socketd.CLOSED=Socket is already closed
 selector.NULL=Selector can't be null
 selector.ERANGE=Selector size is outsize allowed range
 selector.ETYPE=Unknown Selector type
+endpoint.EBOUND=Endpoint is already bound



Mime
View raw message