You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/05/31 19:30:08 UTC
svn commit: r1129813 - in
/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime:
io/Descriptor.java io/Device.java net/LocalSocketEndpoint.java
net/SocketEndpoint.java
Author: mturk
Date: Tue May 31 17:30:08 2011
New Revision: 1129813
URL: http://svn.apache.org/viewvc?rev=1129813&view=rev
Log:
Add closed method to the Device
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/io/Device.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
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=1129813&r1=1129812&r2=1129813&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 Tue May 31 17:30:08 2011
@@ -124,6 +124,19 @@ public abstract class Descriptor impleme
}
/**
+ * Check if the underlying Operating system descriptor is valid.
+ *
+ * @return {@code true} if descriptor is closed; {@code false} otherwise.
+ */
+ public final boolean closed()
+ {
+ if (fd == -1 || fd == 0)
+ return true;
+ else
+ return false;
+ }
+
+ /**
* Get underlying Operating system descriptor.
* @return operating system descriptor.
*/
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Device.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Device.java?rev=1129813&r1=1129812&r2=1129813&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Device.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Device.java Tue May 31 17:30:08 2011
@@ -36,4 +36,11 @@ public interface Device extends Closeabl
*/
public boolean valid();
+ /**
+ * Test if {@code this} device is closed.
+ *
+ * @return {@code true} if the device is closed; {@code false} otherwise.
+ */
+ public boolean closed();
+
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java?rev=1129813&r1=1129812&r2=1129813&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java Tue May 31 17:30:08 2011
@@ -49,6 +49,7 @@ public class LocalSocketEndpoint extends
private LocalSocketEndpoint()
{
super(EndpointType.LOCAL);
+ this.sd = new LocalSocketDescriptor();
}
/**
@@ -72,7 +73,7 @@ public class LocalSocketEndpoint extends
IllegalBlockingModeException,
IOException
{
- if (!sd.valid())
+ if (sd.closed())
throw new ClosedDescriptorException();
if (isRegistered())
throw new IllegalBlockingModeException();
@@ -116,8 +117,8 @@ public class LocalSocketEndpoint extends
// Ignore selector exceptions
}
}
+ sd.close();
}
- sd.close();
if (key != null) {
key.reset();
key = null;
@@ -146,7 +147,7 @@ public class LocalSocketEndpoint extends
{
AbstractSelector sel = (AbstractSelector)selector;
synchronized(this) {
- if (!sd.valid())
+ if (sd.closed())
throw new ClosedDescriptorException();
if (key == null)
key = new SelectionKeyImpl(sel, this, ops);
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=1129813&r1=1129812&r2=1129813&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 Tue May 31 17:30:08 2011
@@ -45,6 +45,7 @@ public class SocketEndpoint extends Endp
public SocketEndpoint()
{
super(EndpointType.SOCKET);
+ this.sd = new SocketDescriptor();
}
/**
@@ -79,7 +80,7 @@ public class SocketEndpoint extends Endp
IllegalBlockingModeException,
IOException
{
- if (!sd.valid())
+ if (sd.closed())
throw new ClosedDescriptorException();
if (isRegistered())
throw new IllegalBlockingModeException();
@@ -112,8 +113,8 @@ public class SocketEndpoint extends Endp
// Ignore selector exceptions
}
}
+ sd.close();
}
- sd.close();
if (key != null) {
key.reset();
key = null;
@@ -142,7 +143,7 @@ public class SocketEndpoint extends Endp
{
AbstractSelector sel = (AbstractSelector)selector;
synchronized(this) {
- if (!sd.valid())
+ if (sd.closed())
throw new ClosedDescriptorException();
if (key == null)
key = new SelectionKeyImpl(sel, this, ops);