Share some more code

This commit is contained in:
norman 2012-08-01 09:00:13 +02:00
parent 9f285d1819
commit e0a88a0f15

View File

@ -214,38 +214,16 @@ final class SocketSendBufferPool {
} }
} }
final class PooledSendBuffer implements SendBuffer { final class PooledSendBuffer extends UnpooledSendBuffer {
private final Preallocation parent; private final Preallocation parent;
final ByteBuffer buffer;
final int initialPos;
PooledSendBuffer(Preallocation parent, ByteBuffer buffer) { PooledSendBuffer(Preallocation parent, ByteBuffer buffer) {
super(buffer);
this.parent = parent; this.parent = parent;
this.buffer = buffer;
initialPos = buffer.position();
}
public boolean finished() {
return !buffer.hasRemaining();
}
public long writtenBytes() {
return buffer.position() - initialPos;
}
public long totalBytes() {
return buffer.limit() - initialPos;
}
public long transferTo(WritableByteChannel ch) throws IOException {
return ch.write(buffer);
}
public long transferTo(DatagramChannel ch, SocketAddress raddr) throws IOException {
return ch.send(buffer, raddr);
} }
@Override
public void release() { public void release() {
final Preallocation parent = this.parent; final Preallocation parent = this.parent;
if (-- parent.refCnt == 0) { if (-- parent.refCnt == 0) {