forked from jnr/jnr-enxio
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make NativeSelectableChannel an interface and reparent NativeSocketCh…
…annel and NativeDeviceChannel
- Loading branch information
1 parent
5213fb6
commit e2bebc3
Showing
7 changed files
with
99 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,8 @@ | ||
package enxio.nio.channels; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.ByteChannel; | ||
import java.nio.channels.SelectionKey; | ||
import java.nio.channels.spi.AbstractSelectableChannel; | ||
import java.nio.channels.spi.SelectorProvider; | ||
import java.nio.channels.Channel; | ||
|
||
public class NativeSelectableChannel extends AbstractSelectableChannel | ||
implements ByteChannel { | ||
public interface NativeSelectableChannel extends Channel { | ||
|
||
private final int fd; | ||
private final int validOps; | ||
|
||
public NativeSelectableChannel(SelectorProvider provider, int fd, int ops) { | ||
super(provider); | ||
this.fd = fd; | ||
this.validOps = ops; | ||
} | ||
public static NativeSelectableChannel forSocket(int fd) { | ||
return new NativeSelectableChannel(NativeSelectorProvider.getInstance(), fd, | ||
SelectionKey.OP_READ | SelectionKey.OP_WRITE | SelectionKey.OP_CONNECT | SelectionKey.OP_ACCEPT); | ||
} | ||
public static NativeSelectableChannel forServerSocket(int fd) { | ||
return forSocket(fd); | ||
} | ||
public static NativeSelectableChannel forDevice(int fd) { | ||
return new NativeSelectableChannel(NativeSelectorProvider.getInstance(), fd, | ||
SelectionKey.OP_READ | SelectionKey.OP_WRITE); | ||
} | ||
|
||
@Override | ||
protected void implCloseSelectableChannel() throws IOException { | ||
Native.close(fd); | ||
} | ||
|
||
@Override | ||
protected void implConfigureBlocking(boolean block) throws IOException { | ||
Native.setBlocking(fd, block); | ||
} | ||
|
||
@Override | ||
public final int validOps() { | ||
return validOps; | ||
} | ||
public final int getFD() { | ||
return fd; | ||
} | ||
public int read(ByteBuffer dst) throws IOException { | ||
return Native.read(fd, dst); | ||
} | ||
|
||
public int write(ByteBuffer src) throws IOException { | ||
return Native.write(fd, src); | ||
} | ||
public int getFD(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
package enxio.nio.channels; | ||
|
||
import java.io.IOException; | ||
import java.nio.channels.SelectionKey; | ||
import java.nio.channels.spi.AbstractSelectableChannel; | ||
import java.nio.channels.spi.SelectorProvider; | ||
|
||
public class NativeServerSocketChannel extends AbstractSelectableChannel implements NativeSelectableChannel { | ||
|
||
private final int fd; | ||
private final int validOps; | ||
|
||
public NativeServerSocketChannel(int fd) { | ||
this(NativeSelectorProvider.getInstance(), fd, SelectionKey.OP_ACCEPT); | ||
} | ||
public NativeServerSocketChannel(SelectorProvider provider, int fd, int ops) { | ||
super(provider); | ||
this.fd = fd; | ||
this.validOps = ops; | ||
} | ||
|
||
@Override | ||
protected void implCloseSelectableChannel() throws IOException { | ||
Native.close(fd); | ||
} | ||
|
||
@Override | ||
protected void implConfigureBlocking(boolean block) throws IOException { | ||
Native.setBlocking(fd, block); | ||
} | ||
|
||
@Override | ||
public final int validOps() { | ||
return validOps; | ||
} | ||
public final int getFD() { | ||
return fd; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters