Author: mturk
Date: Wed Jul 13 18:11:52 2011
New Revision: 1146181
URL: http://svn.apache.org/viewvc?rev=1146181&view=rev
Log:
Implement endpoint shudown
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.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
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServerEndpoint.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/native/os/unix/inetsock.c
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java?rev=1146181&r1=1146180&r2=1146181&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
Wed Jul 13 18:11:52 2011
@@ -227,10 +227,21 @@ public abstract class Endpoint implement
* </pre>
* @param timeout
* timeout value in milliseconds.
- * @throws SocketException
+ * @throws IOException
* if an error occurs while setting the option.
*/
public abstract void setTimeout(int timeout)
throws IOException;
-
+
+ /**
+ * Shutdown a part of full-duplex connection.
+ *
+ * @param how How to shutdown the enpoint
+ *
+ * @throws IOException
+ * if an error occurs while shutting down the endpoint.
+ */
+ public abstract void shutdown(ShutdownHow how)
+ throws IOException;
+
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java?rev=1146181&r1=1146180&r2=1146181&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java
Wed Jul 13 18:11:52 2011
@@ -42,6 +42,7 @@ final class LocalDescriptor extends Desc
throws IOException;
private static native int block0(long fd, boolean block);
private static native int tmset0(long fd, int timeout);
+ private static native int shutdown0(long fd, int how);
private static native boolean isBlocking0(long fd)
throws IOException;
@@ -129,5 +130,15 @@ final class LocalDescriptor extends Desc
if (rc != 0)
throw new SocketException(Status.describe(rc));
}
-
+
+ public void shutdown(ShutdownHow how)
+ throws IOException
+ {
+ if (closed())
+ throw new ClosedDescriptorException();
+ int rc = shutdown0(fd, how.valueOf());
+ if (rc != 0)
+ throw new SocketException(Status.describe(rc));
+ }
+
}
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=1146181&r1=1146180&r2=1146181&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
Wed Jul 13 18:11:52 2011
@@ -185,4 +185,11 @@ public class LocalEndpoint extends Endpo
sd.setTimeout(timeout);
}
+ @Override
+ public void shutdown(ShutdownHow how)
+ throws IOException
+ {
+ sd.shutdown(how);
+ }
+
}
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=1146181&r1=1146180&r2=1146181&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
Wed Jul 13 18:11:52 2011
@@ -20,3 +20,4 @@ selector.ERANGE=Selector size is outsize
selector.ETYPE=Unknown Selector type
endpoint.EBOUND=Endpoint is already bound
endpoint.ECONNECTED=Endpoint is already connected
+endpoint.ENOTCONN=Endpoint is not connected
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServerEndpoint.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServerEndpoint.java?rev=1146181&r1=1146180&r2=1146181&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServerEndpoint.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServerEndpoint.java
Wed Jul 13 18:11:52 2011
@@ -57,5 +57,13 @@ public abstract class ServerEndpoint<E>
{
bind(endpoint, 0);
}
-
+
+ @Override
+ public final void shutdown(ShutdownHow how)
+ throws IOException
+ {
+ // Shutdown is valid for connection oriented endpoints
+ // Throw an exception.
+ throw new IOException(Local.sm.get("endpoint.ENOTCONN"));
+ }
}
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=1146181&r1=1146180&r2=1146181&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
Wed Jul 13 18:11:52 2011
@@ -39,6 +39,7 @@ final class SocketDescriptor extends Des
throws IOException;
private static native int block0(long fd, boolean block);
private static native int tmset0(long fd, int timeout);
+ private static native int shutdown0(long fd, int how);
private static native boolean isBlocking0(long fd)
throws IOException;
@@ -127,4 +128,14 @@ final class SocketDescriptor extends Des
throw new SocketException(Status.describe(rc));
}
+ public void shutdown(ShutdownHow how)
+ throws IOException
+ {
+ if (closed())
+ throw new ClosedDescriptorException();
+ int rc = shutdown0(fd, how.valueOf());
+ if (rc != 0)
+ throw new SocketException(Status.describe(rc));
+ }
+
}
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=1146181&r1=1146180&r2=1146181&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
Wed Jul 13 18:11:52 2011
@@ -163,5 +163,12 @@ public class SocketEndpoint extends Endp
{
sd.setTimeout(timeout);
}
-
+
+ @Override
+ public void shutdown(ShutdownHow how)
+ throws IOException
+ {
+ sd.shutdown(how);
+ }
+
}
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=1146181&r1=1146180&r2=1146181&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 Wed Jul 13
18:11:52 2011
@@ -125,6 +125,25 @@ ACR_NET_EXPORT(jint, SocketDescriptor, s
return 0;
}
+ACR_NET_EXPORT(jint, SocketDescriptor, shutdown0)(JNI_STDARGS, jlong fp,
+ jint how)
+{
+ int rc = 0;
+ acr_fd_t *fd = J2P(fp, acr_fd_t *);
+
+ if (fd == 0)
+ return ACR_EBADF;
+ if (how == 0)
+ how = SHUT_RD;
+ else if (how == 1)
+ how = SHUT_WR;
+ else
+ how = SHUT_RDWR;
+ if (shutdown(fd->u.s, how) == -1)
+ rc = ACR_GET_NETOS_ERROR();
+ return rc;
+}
+
ACR_NET_EXPORT(jint, SocketDescriptor, block0)(JNI_STDARGS, jlong fp, jboolean
on)
{
int rc = 0;