当前位置: 首页>>代码示例>>C#>>正文


C# AsyncProtocolRequest.?.CompleteUser方法代码示例

本文整理汇总了C#中AsyncProtocolRequest.?.CompleteUser方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncProtocolRequest.?.CompleteUser方法的具体用法?C# AsyncProtocolRequest.?.CompleteUser怎么用?C# AsyncProtocolRequest.?.CompleteUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AsyncProtocolRequest的用法示例。


在下文中一共展示了AsyncProtocolRequest.?.CompleteUser方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartFrameBody

        private int StartFrameBody(int readBytes, byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            if (readBytes == 0)
            {
                //EOF
                asyncRequest?.CompleteUser(0);
                return 0;
            }

            if (!(readBytes == _ReadHeader.Length))
            {
                NetEventSource.Fail(this, $"Frame size must be 4 but received {readBytes} bytes.");
            }

            // Replace readBytes with the body size recovered from the header content.
            readBytes = _ReadHeader[3];
            readBytes = (readBytes << 8) | _ReadHeader[2];
            readBytes = (readBytes << 8) | _ReadHeader[1];
            readBytes = (readBytes << 8) | _ReadHeader[0];

            //
            // The body carries 4 bytes for trailer size slot plus trailer, hence <=4 frame size is always an error.
            // Additionally we'd like to restrict the read frame size to 64k.
            //
            if (readBytes <= 4 || readBytes > NegoState.MaxReadFrameSize)
            {
                throw new IOException(SR.net_frame_read_size);
            }

            //
            // Always pass InternalBuffer for SSPI "in place" decryption.
            // A user buffer can be shared by many threads in that case decryption/integrity check may fail cause of data corruption.
            //
            EnsureInternalBufferSize(readBytes);
            if (asyncRequest != null)
            {
                asyncRequest.SetNextRequest(InternalBuffer, 0, readBytes, s_readCallback);

                _FrameReader.AsyncReadPacket(asyncRequest);

                if (!asyncRequest.MustCompleteSynchronously)
                {
                    return 0;
                }

                readBytes = asyncRequest.Result;
            }
            else //Sync
            {
                readBytes = _FrameReader.ReadPacket(InternalBuffer, 0, readBytes);
            }

            return ProcessFrameBody(readBytes, buffer, offset, count, asyncRequest);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:54,代码来源:InternalNegotiateStream.cs

示例2: ProcessFrameBody

        private int ProcessFrameBody(int readBytes, byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            if (readBytes == 0)
            {
                // We already checked that the frame body is bigger than 0 bytes
                // Hence, this is an EOF ... fire.
                throw new IOException(SR.net_io_eof);
            }

            // Decrypt into internal buffer, change "readBytes" to count now _Decrypted Bytes_
            int internalOffset;
            readBytes = _negoState.DecryptData(InternalBuffer, 0, readBytes, out internalOffset);

            // Decrypted data start from zero offset, the size can be shrunk after decryption.
            AdjustInternalBufferOffsetSize(readBytes, internalOffset);

            if (readBytes == 0 && count != 0)
            {
                // Read again.
                return -1;
            }

            if (readBytes > count)
            {
                readBytes = count;
            }

            Buffer.BlockCopy(InternalBuffer, InternalOffset, buffer, offset, readBytes);

            // This will adjust both the remaining internal buffer count and the offset.
            DecrementInternalBufferCount(readBytes);

            asyncRequest?.CompleteUser(readBytes);

            return readBytes;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:36,代码来源:InternalNegotiateStream.cs

示例3: ProcessRead

        //
        // Combined sync/async read method. For sync request asyncRequest==null.
        // There is a little overhead because we need to pass buffer/offset/count used only in sync.
        // Still the benefit is that we have a common sync/async code path.
        //
        private int ProcessRead(byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            ValidateParameters(buffer, offset, count);

            if (Interlocked.Exchange(ref _NestedRead, 1) == 1)
            {
                throw new NotSupportedException(SR.Format(SR.net_io_invalidnestedcall, (asyncRequest != null ? "BeginRead" : "Read"), "read"));
            }

            bool failed = false;
            try
            {
                if (InternalBufferCount != 0)
                {
                    int copyBytes = InternalBufferCount > count ? count : InternalBufferCount;
                    if (copyBytes != 0)
                    {
                        Buffer.BlockCopy(InternalBuffer, InternalOffset, buffer, offset, copyBytes);
                        DecrementInternalBufferCount(copyBytes);
                    }
                    asyncRequest?.CompleteUser(copyBytes);
                    return copyBytes;
                }

                // Performing actual I/O.
                return StartReading(buffer, offset, count, asyncRequest);
            }
            catch (Exception e)
            {
                failed = true;
                if (e is IOException)
                {
                    throw;
                }
                throw new IOException(SR.net_io_read, e);
            }
            finally
            {
                if (asyncRequest == null || failed)
                {
                    _NestedRead = 0;
                }
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:49,代码来源:InternalNegotiateStream.cs

示例4: ProcessReadErrorCode

        private int ProcessReadErrorCode(SecurityStatusPal status, byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest, byte[] extraBuffer)
        {
            ProtocolToken message = new ProtocolToken(null, status);
            if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"***Processing an error Status = {message.Status}");

            if (message.Renegotiate)
            {
                _sslState.ReplyOnReAuthentication(extraBuffer);

                // Loop on read.
                return -1;
            }

            if (message.CloseConnection)
            {
                _sslState.FinishRead(null);
                asyncRequest?.CompleteUser(0);

                return 0;
            }

            throw new IOException(SR.net_io_decrypt, message.GetException());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:23,代码来源:SslStreamInternal.cs

示例5: ProcessFrameBody

        //
        // readBytes == SSL Data Payload size on input or 0 on EOF.
        //
        private int ProcessFrameBody(int readBytes, byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            if (readBytes == 0)
            {
                // EOF
                throw new IOException(SR.net_io_eof);
            }

            // Set readBytes to total number of received bytes.
            readBytes += SecureChannel.ReadHeaderSize;

            // Decrypt into internal buffer, change "readBytes" to count now _Decrypted Bytes_.
            int data_offset = 0;

            SecurityStatusPal status = _sslState.DecryptData(InternalBuffer, ref data_offset, ref readBytes);

            if (status.ErrorCode != SecurityStatusPalErrorCode.OK)
            {
                byte[] extraBuffer = null;
                if (readBytes != 0)
                {
                    extraBuffer = new byte[readBytes];
                    Buffer.BlockCopy(InternalBuffer, data_offset, extraBuffer, 0, readBytes);
                }

                // Reset internal buffer count.
                SkipBytes(InternalBufferCount);
                return ProcessReadErrorCode(status, buffer, offset, count, asyncRequest, extraBuffer);
            }


            if (readBytes == 0 && count != 0)
            {
                // Read again since remote side has sent encrypted 0 bytes.
                SkipBytes(InternalBufferCount);
                return -1;
            }

            // Decrypted data start from "data_offset" offset, the total count can be shrunk after decryption.
            EnsureInternalBufferSize(0, data_offset + readBytes);
            SkipBytes(data_offset);

            if (readBytes > count)
            {
                readBytes = count;
            }

            Buffer.BlockCopy(InternalBuffer, InternalOffset, buffer, offset, readBytes);

            // This will adjust both the remaining internal buffer count and the offset.
            SkipBytes(readBytes);

            _sslState.FinishRead(null);
            asyncRequest?.CompleteUser(readBytes);

            return readBytes;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:60,代码来源:SslStreamInternal.cs

示例6: StartFrameBody

        private int StartFrameBody(int readBytes, byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            if (readBytes == 0)
            {
                //EOF : Reset the buffer as we did not read anything into it.
                SkipBytes(InternalBufferCount);
                asyncRequest?.CompleteUser(0);
                
                return 0;
            }

            // Now readBytes is a payload size.
            readBytes = _sslState.GetRemainingFrameSize(InternalBuffer, readBytes);

            if (readBytes < 0)
            {
                throw new IOException(SR.net_frame_read_size);
            }

            EnsureInternalBufferSize(SecureChannel.ReadHeaderSize, readBytes);

            if (asyncRequest != null)
            {
                asyncRequest.SetNextRequest(InternalBuffer, SecureChannel.ReadHeaderSize, readBytes, s_readFrameCallback);

                _reader.AsyncReadPacket(asyncRequest);

                if (!asyncRequest.MustCompleteSynchronously)
                {
                    return 0;
                }
                
                readBytes = asyncRequest.Result;
            }
            else
            {
                readBytes = _reader.ReadPacket(InternalBuffer, SecureChannel.ReadHeaderSize, readBytes);
            }
            
            return ProcessFrameBody(readBytes, buffer, offset, count, asyncRequest);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:41,代码来源:SslStreamInternal.cs

示例7: StartReading

        //
        // To avoid recursion when decrypted 0 bytes this method will loop until a decrypted result at least 1 byte.
        //
        private int StartReading(byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            int result = 0;

            if (InternalBufferCount != 0)
            {
                NetEventSource.Fail(this, $"Previous frame was not consumed. InternalBufferCount: {InternalBufferCount}");
            }

            do
            {
                if (asyncRequest != null)
                {
                    asyncRequest.SetNextRequest(buffer, offset, count, s_resumeAsyncReadCallback);
                }

                int copyBytes = _sslState.CheckEnqueueRead(buffer, offset, count, asyncRequest);
                if (copyBytes == 0)
                {
                    // Queued but not completed!
                    return 0;
                }

                if (copyBytes != -1)
                {
                    asyncRequest?.CompleteUser(copyBytes);

                    return copyBytes;
                }
            }

            // When we read -1 bytes means we have decrypted 0 bytes or rehandshaking, need looping.
            while ((result = StartFrameHeader(buffer, offset, count, asyncRequest)) == -1);

            return result;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:39,代码来源:SslStreamInternal.cs


注:本文中的AsyncProtocolRequest.?.CompleteUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。