public void TearDown() { _reader.Dispose(); _reader = null; _pipe.Close(); _pipe = null; }
public void TearDown() { _reader.Dispose(); _reader = null; _stream.Dispose(); _stream = null; }
private void ConnectToConfigurationStream() { if (_linesStreamReader != null) { _linesStreamReader.Dispose(); _linesStreamReader = null; } // Start loop at 1 to make sure we always try a server different from the last one upon (re)connecting. var connecting = false; for (var i = 1; !connecting && i <= _configurationHosts.Length; i++) { connecting = true; _currentConfigurationHost = (_currentConfigurationHost + i) % _configurationHosts.Length; var url = string.Format( "http://{0}:{1}/pools/default/bucketsStreaming/{2}", _configurationHosts[_currentConfigurationHost].Address, _configurationHosts[_currentConfigurationHost].Port, _bucket); var request = WebRequest.Create(url); try { request.BeginGetResponse(ConfigurationStreamRequestEndGetResponse, request); } catch (Exception e) { // Try the next host connecting = false; if (OnError != null) { OnError(e); } } } // In case no host can be reached, try again in 30s if (!connecting) { RetryConnectingToConfigurationStream(30); } }
private void KillCurrentConnection() { if (_linesStreamReader != null) { _linesStreamReader.Dispose(); _linesStreamReader = null; } if (_webResponse != null) { _webResponse.Dispose(); _webResponse = null; } }
private void ConfigurationStreamRequestEndGetResponse(IAsyncResult ar) { if (_linesStreamReader != null) { OnError(new MemcacheException("Sanity check: The previous AsyncLinesStreamReader was not disposed")); return; } if (_webResponse != null) { OnError(new MemcacheException("Sanity check: The previous WebResponse was not disposed")); return; } WebResponse response = null; AsyncLinesStreamReader linesStreamReader = null; try { var request = (WebRequest)ar.AsyncState; response = request.EndGetResponse(ar); // Allocate new string reader and start reading linesStreamReader = new AsyncLinesStreamReader(response.GetResponseStream()); linesStreamReader.OnError += HandleLinesStreamError; linesStreamReader.OnChunk += HandleConfigurationUpdate; lock (this) if (!_isDisposed) { _webResponse = response; _linesStreamReader = linesStreamReader; } else { response.Dispose(); linesStreamReader.Dispose(); return; } _linesStreamReader.StartReading(); } catch (Exception e) { if (OnError != null) { OnError(e); } if (response != null) { response.Dispose(); } _webResponse = null; if (linesStreamReader != null) { linesStreamReader.Dispose(); } _linesStreamReader = null; // Handle HTTP query errors by trying another host RetryConnectingToConfigurationStream(delaySeconds: 1.0); } }