package org.glassfish.grizzly.nio.transport;
import java.io.IOException;
import java.net.SocketAddress;
import org.glassfish.grizzly.Buffer;
import org.glassfish.grizzly.ReadResult;
import org.glassfish.grizzly.nio.NIOConnection;
import org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorReader;
public final class TCPNIOTemporarySelectorReader extends TemporarySelectorReader {
public TCPNIOTemporarySelectorReader(TCPNIOTransport transport) {
super(transport);
}
@Override
protected int readNow0(final NIOConnection connection, Buffer buffer, final ReadResult<Buffer, SocketAddress> currentResult) throws IOException {
final int oldPosition = buffer != null ? buffer.position() : 0;
if ((buffer = ((TCPNIOTransport) transport).read(connection, buffer)) != null) {
final int readBytes = buffer.position() - oldPosition;
currentResult.setMessage(buffer);
currentResult.setReadSize(currentResult.getReadSize() + readBytes);
currentResult.setSrcAddressHolder(((TCPNIOConnection) connection).peerSocketAddressHolder);
return readBytes;
}
return 0;
}
}