43 import java.nio.channels.*;
58 protected SocketChannel sc;
65 protected ByteBuffer requestBB;
66 static private int requestBBSize = 4096;
68 protected ChannelIO(SocketChannel sc,
boolean blocking)
71 sc.configureBlocking(blocking);
74 static ChannelIO getInstance(SocketChannel sc,
boolean blocking)
76 ChannelIO cio =
new ChannelIO(sc, blocking);
77 cio.requestBB = ByteBuffer.allocate(requestBBSize);
82 SocketChannel getSocketChannel() {
90 protected void resizeRequestBB(
int remaining) {
91 if (requestBB.remaining() < remaining) {
93 ByteBuffer bb = ByteBuffer.allocate(requestBB.capacity() * 2);
108 boolean doHandshake() throws IOException {
121 boolean doHandshake(SelectionKey sk)
throws IOException {
129 int read() throws IOException {
133 resizeRequestBB(requestBBSize/20);
134 return sc.read(requestBB);
140 ByteBuffer getReadBuf() {
147 int write(ByteBuffer src)
throws IOException {
148 return sc.write(src);
154 long transferTo(FileChannel fc,
long pos,
long len)
throws IOException {
155 return fc.transferTo(pos, len, sc);
166 boolean dataFlush() throws IOException {
178 boolean shutdown() throws IOException {
185 void close() throws IOException {