public override void FinishRead(SocketChannelAsyncOperation operation) { AbstractSocketByteChannel ch = this.Channel; if ((ch.ResetState(StateFlags.ReadScheduled) & StateFlags.Active) == 0) { return; // read was signaled as a result of channel closure } IChannelConfiguration config = ch.Configuration; IChannelPipeline pipeline = ch.Pipeline; IByteBufferAllocator allocator = config.Allocator; IRecvByteBufAllocatorHandle allocHandle = this.RecvBufAllocHandle; allocHandle.Reset(config); IByteBuffer byteBuf = null; bool close = false; try { operation.Validate(); do { byteBuf = allocHandle.Allocate(allocator); //int writable = byteBuf.WritableBytes; allocHandle.LastBytesRead = ch.DoReadBytes(byteBuf); if (allocHandle.LastBytesRead <= 0) { // nothing was read -> release the buffer. byteBuf.Release(); byteBuf = null; close = allocHandle.LastBytesRead < 0; break; } allocHandle.IncMessagesRead(1); this.Channel.ReadPending = false; pipeline.FireChannelRead(byteBuf); byteBuf = null; }while (allocHandle.ContinueReading()); allocHandle.ReadComplete(); pipeline.FireChannelReadComplete(); if (close) { this.CloseOnRead(); } } catch (Exception t) { this.HandleReadException(pipeline, byteBuf, t, close, allocHandle); } finally { // Check if there is a readPending which was not processed yet. // This could be for two reasons: // /// The user called Channel.read() or ChannelHandlerContext.read() input channelRead(...) method // /// The user called Channel.read() or ChannelHandlerContext.read() input channelReadComplete(...) method // // See https://github.com/netty/netty/issues/2254 if (!close && (ch.ReadPending || config.AutoRead)) { ch.DoBeginRead(); } } }
public SocketByteChannelUnsafe(AbstractSocketByteChannel channel) : base(channel) { }