System.Net.Security.SslState.FinishWrite C# (CSharp) Method

FinishWrite() private method

private FinishWrite ( ) : void
return void
        internal void FinishWrite()
        {
            int lockState = Interlocked.CompareExchange(ref _lockWriteState, LockNone, LockWrite);
            if (lockState != LockHandshake)
            {
                return;
            }

            lock (this)
            {
                object obj = _queuedWriteStateRequest;
                if (obj == null)
                {
                    // A repeated call.
                    return;
                }

                _queuedWriteStateRequest = null;
                if (obj is LazyAsyncResult)
                {
                    // Sync handshake is waiting on other thread.
                    ((LazyAsyncResult)obj).InvokeCallback();
                }
                else
                {
                    // Async handshake is pending, start it on other thread.
                    // Consider: we could start it in on this thread but that will delay THIS write completion
                    ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncResumeHandshake), obj);
                }
            }
        }

Usage Example

Example #1
0
        //
        // Combined sync/async write method. For sync case asyncRequest==null.
        //
        private void ProcessWrite(byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            ValidateParameters(buffer, offset, count);

            if (Interlocked.Exchange(ref _NestedWrite, 1) == 1)
            {
                throw new NotSupportedException(SR.Format(SR.net_io_invalidnestedcall, (asyncRequest != null ? "BeginWrite" : "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;
                }
            }
        }
All Usage Examples Of System.Net.Security.SslState::FinishWrite