CheckThrow() private method

private CheckThrow ( bool authSucessCheck ) : void
authSucessCheck bool
return void
Example #1
0
        private ValueTask WriteAsyncInternal <TWriteAdapter>(TWriteAdapter writeAdapter, ReadOnlyMemory <byte> buffer)
            where TWriteAdapter : struct, ISslWriteAdapter
        {
            _sslState.CheckThrow(authSuccessCheck: true, shutdownCheck: true);

            if (buffer.Length == 0 && !SslStreamPal.CanEncryptEmptyMessage)
            {
                // If it's an empty message and the PAL doesn't support that, we're done.
                return(default);
        private Task WriteAsyncInternal <TWriteAdapter>(TWriteAdapter writeAdapter, ReadOnlyMemory <byte> buffer)
            where TWriteAdapter : struct, ISslWriteAdapter
        {
            _sslState.CheckThrow(authSuccessCheck: true, shutdownCheck: true);

            if (buffer.Length == 0 && !SslStreamPal.CanEncryptEmptyMessage)
            {
                // If it's an empty message and the PAL doesn't support that, we're done.
                return(Task.CompletedTask);
            }

            if (Interlocked.Exchange(ref _nestedWrite, 1) == 1)
            {
                throw new NotSupportedException(SR.Format(SR.net_io_invalidnestedcall, nameof(WriteAsync), "write"));
            }

            Task t = buffer.Length < _sslState.MaxDataSize ?
                     WriteSingleChunk(writeAdapter, buffer) :
                     WriteAsyncChunked(writeAdapter, buffer);

            if (t.IsCompletedSuccessfully)
            {
                _nestedWrite = 0;
                return(t);
            }
            return(ExitWriteAsync(t));

            async Task ExitWriteAsync(Task task)
            {
                try
                {
                    await task.ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    _sslState.FinishWrite();

                    if (e is IOException)
                    {
                        throw;
                    }

                    throw new IOException(SR.net_io_write, e);
                }
                finally
                {
                    _nestedWrite = 0;
                }
            }
        }
Example #3
0
        //
        // Sync write method.
        //
        private void ProcessWrite(byte[] buffer, int offset, int count, LazyAsyncResult asyncResult)
        {
            _sslState.CheckThrow(authSuccessCheck: true, shutdownCheck: true);
            ValidateParameters(buffer, offset, count);

            if (Interlocked.Exchange(ref _nestedWrite, 1) == 1)
            {
                throw new NotSupportedException(SR.Format(SR.net_io_invalidnestedcall, "Write", "write"));
            }

            // If this is an async operation, get the AsyncProtocolRequest to use.
            // We do this only after we verify we're the sole write operation in flight.
            AsyncProtocolRequest asyncRequest = GetOrCreateProtocolRequest(ref _writeProtocolRequest, asyncResult);

            bool failed = false;

            try
            {
                StartWriting(buffer, offset, count, asyncRequest);
            }
            catch (Exception e)
            {
                _sslState.FinishWrite();

                failed = true;
                if (e is IOException)
                {
                    throw;
                }

                throw new IOException(SR.net_io_write, e);
            }
            finally
            {
                if (asyncRequest == null || failed)
                {
                    _nestedWrite = 0;
                }
            }
        }
Example #4
0
        //
        // Sync write method.
        //
        private void ProcessWrite(byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            _sslState.CheckThrow(authSuccessCheck: true, shutdownCheck: true);
            ValidateParameters(buffer, offset, count);

            if (Interlocked.Exchange(ref _nestedWrite, 1) == 1)
            {
                throw new NotSupportedException(SR.Format(SR.net_io_invalidnestedcall, "Write", "write"));
            }

            bool failed = false;

            try
            {
                StartWriting(buffer, offset, count, asyncRequest);
            }
            catch (Exception e)
            {
                _sslState.FinishWrite();

                failed = true;
                if (e is IOException)
                {
                    throw;
                }

                throw new IOException(SR.net_io_write, e);
            }
            finally
            {
                if (asyncRequest == null || failed)
                {
                    _nestedWrite = 0;
                }
            }
        }