/// <summary> /// Create a new context for a new connection. /// </summary> private void CreateContext() { // Create the buffers. _requestBuffer = new Collections.CircularBuffer <byte>(_requestBufferCapacity); _responseBuffer = new Collections.CircularBuffer <byte>(_responseBufferCapacity); // Create the streams. _requestStream = new NetRequestStream(_requestBuffer); _responseStream = new NetResponseStream(_responseBuffer); _request = new Request(); _response = new Response(); _context = new ClientContext(); }
/// <summary> /// Dispose(bool disposing) executes in two distinct scenarios. /// If disposing equals true, the method has been called directly /// or indirectly by a user's code. Managed and unmanaged resources /// can be disposed. /// If disposing equals false, the method has been called by the /// runtime from inside the finalizer and you should not reference /// other objects. Only unmanaged resources can be disposed. /// </summary> protected override void Dispose(bool disposing) { base.Dispose(disposing); // Check to see if Dispose has already been called. if (!this._disposed) { // Note disposing has been done. _disposed = true; // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { // Dispose managed resources. if (_dataAvailable != null) { _dataAvailable.Dispose(); } // Release the receive and send spin wait handler. Interlocked.Exchange(ref _exitWaitReceiveIndicator, 0); Interlocked.Exchange(ref _exitWaitSendIndicator, 0); Interlocked.Exchange(ref _isContextActive, 0); if (_requestBuffer != null) { _requestBuffer.Dispose(); } if (_responseBuffer != null) { _responseBuffer.Dispose(); } if (_requestStream != null) { _requestStream.Dispose(); } if (_responseStream != null) { _responseStream.Dispose(); } if (_context != null) { if (_context.ContextState != null) { // If the current state context // implements IDisposable then // dispose of the resources. if (_context.ContextState is IDisposable) { IDisposable disposable = (IDisposable)_context.ContextState; disposable.Dispose(); } } } } // Call the appropriate methods to clean up // unmanaged resources here. _dataAvailable = null; _requestBuffer = null; _responseBuffer = null; _requestStream = null; _responseStream = null; _request = null; _response = null; _context.ContextState = null; _context = null; } }