Ejemplo n.º 1
0
        protected SocketChannelAsyncOperation PrepareWriteOperation(ArraySegment <byte> buffer)
        {
            SocketChannelAsyncOperation operation = this.WriteOperation;

            operation.SetBuffer(buffer.Array, buffer.Offset, buffer.Count);
            return(operation);
        }
Ejemplo n.º 2
0
        protected void ResetWriteOperation()
        {
            SocketChannelAsyncOperation operation = this.writeOperation;

            Contract.Requires(operation != null);
            operation.SetBuffer(null, 0, 0);
        }
Ejemplo n.º 3
0
        protected override void ScheduleSocketRead()
        {
            try
            {
                SocketChannelAsyncOperation operation = this.ReadOperation;
                operation.RemoteEndPoint = this.anyRemoteEndPoint;

                IRecvByteBufAllocatorHandle handle = this.Unsafe.RecvBufAllocHandle;
                IByteBuffer buffer = handle.Allocate(this.config.Allocator);
                handle.AttemptedBytesRead = buffer.WritableBytes;
                operation.UserToken       = buffer;

                ArraySegment <byte> bytes = buffer.GetIoBuffer(0, buffer.WritableBytes);
                operation.SetBuffer(bytes.Array, bytes.Offset, bytes.Count);

                bool pending;
#if NETSTANDARD1_3
                pending = this.Socket.ReceiveFromAsync(operation);
#else
                if (this.isConnected)
                {
                    if (ExecutionContext.IsFlowSuppressed())
                    {
                        pending = this.Socket.ReceiveAsync(operation);
                    }
                    else
                    {
                        using (ExecutionContext.SuppressFlow())
                        {
                            pending = this.Socket.ReceiveAsync(operation);
                        }
                    }
                }
                else
                {
                    if (ExecutionContext.IsFlowSuppressed())
                    {
                        pending = this.Socket.ReceiveFromAsync(operation);
                    }
                    else
                    {
                        using (ExecutionContext.SuppressFlow())
                        {
                            pending = this.Socket.ReceiveFromAsync(operation);
                        }
                    }
                }
#endif
                if (!pending)
                {
                    this.EventLoop.Execute(ReceiveFromCompletedSyncCallback, this.Unsafe, operation);
                }
            }
            catch (Exception e)
            {
                this.Pipeline.FireExceptionCaught(e);
            }
        }
Ejemplo n.º 4
0
        protected SocketChannelAsyncOperation PrepareWriteOperation(IByteBuffer buffer)
        {
            SocketChannelAsyncOperation operation = this.writeOperation ?? (this.writeOperation = new SocketChannelAsyncOperation(this, false));

            if (!buffer.HasArray)
            {
                throw new NotImplementedException("IByteBuffer implementations not backed by array are currently not supported.");
            }
            operation.SetBuffer(buffer.Array, buffer.ArrayOffset + buffer.WriterIndex, buffer.WritableBytes);
            return(operation);
        }
Ejemplo n.º 5
0
        protected void ResetWriteOperation()
        {
            SocketChannelAsyncOperation operation = this.writeOperation;

            Contract.Assert(operation != null);

            if (operation.BufferList == null)
            {
                operation.SetBuffer(null, 0, 0);
            }
            else
            {
                operation.BufferList = null;
            }
        }