Beispiel #1
0
        protected SocketChannelAsyncOperation PrepareWriteOperation(ArraySegment <byte> buffer)
        {
            SocketChannelAsyncOperation operation = this.WriteOperation;

            operation.SetBuffer(buffer.Array, buffer.Offset, buffer.Count);
            return(operation);
        }
Beispiel #2
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;
            }
        }
Beispiel #3
0
        protected override void ScheduleSocketRead()
        {
            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 (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);
            }
        }