protected Stream ContinueCommandPipeline()
{
// In async case, The BeginWrite can actually result in a
// series of synchronous completions that eventually close
// the connection. So we need to save the members that
// we need to access, since they may not be valid after
// BeginWrite returns
bool isAsync = _isAsync;
while (_index < _commands.Length)
{
if (_doSend)
{
if (_index < 0)
throw new InternalException();
byte[] sendBuffer = Encoding.GetBytes(_commands[_index].Command);
if (NetEventSource.Log.IsEnabled())
{
string sendCommand = _commands[_index].Command.Substring(0, _commands[_index].Command.Length - 2);
if (_commands[_index].HasFlag(PipelineEntryFlags.DontLogParameter))
{
int index = sendCommand.IndexOf(' ');
if (index != -1)
sendCommand = sendCommand.Substring(0, index) + " ********";
}
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Sending command {sendCommand}");
}
try
{
if (isAsync)
{
BeginWrite(sendBuffer, 0, sendBuffer.Length, s_writeCallbackDelegate, this);
}
else
{
Write(sendBuffer, 0, sendBuffer.Length);
}
}
catch (IOException)
{
MarkAsRecoverableFailure();
throw;
}
catch
{
throw;
}
if (isAsync)
{
return null;
}
}
Stream stream = null;
bool isReturn = PostSendCommandProcessing(ref stream);
if (isReturn)
{
return stream;
}
}
lock (this)
{
Close();
}
return null;
}