8198372: API to create a SelectableChannel to a FileDescriptor
David Lloyd
david.lloyd at redhat.com
Wed Jun 20 13:16:35 UTC 2018
A few comments...
+ public interface SelectableChannelCloser {
I wonder if some basic implementation should be provided for this. I
can't think of a case where a user would be able to implement this
interface without native code of some sort (is this the intention?).
+ public static SelectableChannel
readWriteSelectableChannel(FileDescriptor fd,
+
SelectableChannelCloser closer) {
+ Objects.requireNonNull(fd);
+ Objects.requireNonNull(closer);
+ if (!fd.valid())
+ throw new IllegalArgumentException("file descriptor is not valid");
+
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkRead(fd);
+ sm.checkWrite(fd);
+ }
I disagree with these security checks. Nothing in this API allows the
caller to actually read or write the FD; that would have to be
provided separately. Given that each of the checks are relatively
expensive, IMO they should be deferred to the point where an object is
constructed that actually has read and/or write capability.
On Wed, Jun 20, 2018 at 7:24 AM Alan Bateman <Alan.Bateman at oracle.com> wrote:
>
>
> A requirement that comes up periodically is some way to create a
> SelectableChannel implementation that can be used with the built-in
> Selector implementations. It's a project in itself because the
> FileDescriptor representation is not exposed and because it requires
> bidirectional translations of events. An alternative approach for the
> common case of just read and write operations is to provide a simple API
> to create a SelectableChannel to a file descriptor.
>
> The proposal here is to extend the JDK-specific jdk.net module with
> support for creating a SelectableChannel to an existing file descriptor.
> The resulting channel is associated with the default SelectorProvider
> and supports an operation-set of OP_READ and OP_WRITE. The API is as
> minimal ass possible, the only complexity is closing when the channel is
> registered with a Selector.
>
> The webrev with the proposed API is here:
> http://cr.openjdk.java.net/~alanb/8198372/webrev/index.html
>
> -Alan
>
>
--
- DML
More information about the nio-dev
mailing list