public override WebResponse GetResponse()
{
if (NetEventSource.IsEnabled)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Method: {_methodInfo.Method}");
}
try
{
CheckError();
if (_ftpWebResponse != null)
{
return _ftpWebResponse;
}
if (_getResponseStarted)
{
throw new InvalidOperationException(SR.net_repcall);
}
_getResponseStarted = true;
_startTime = DateTime.UtcNow;
_remainingTimeout = Timeout;
if (Timeout != System.Threading.Timeout.Infinite)
{
_remainingTimeout = Timeout - (int)((DateTime.UtcNow - _startTime).TotalMilliseconds);
if (_remainingTimeout <= 0)
{
throw ExceptionHelper.TimeoutException;
}
}
RequestStage prev = FinishRequestStage(RequestStage.RequestStarted);
if (prev >= RequestStage.RequestStarted)
{
if (prev < RequestStage.ReadReady)
{
lock (_syncObject)
{
if (_requestStage < RequestStage.ReadReady)
_readAsyncResult = new LazyAsyncResult(null, null, null);
}
// GetRequeststream or BeginGetRequestStream has not finished yet
if (_readAsyncResult != null)
_readAsyncResult.InternalWaitForCompletion();
CheckError();
}
}
else
{
SubmitRequest(false);
if (_methodInfo.IsUpload)
FinishRequestStage(RequestStage.WriteReady);
else
FinishRequestStage(RequestStage.ReadReady);
CheckError();
EnsureFtpWebResponse(null);
}
}
catch (Exception exception)
{
if (NetEventSource.IsEnabled) NetEventSource.Error(this, exception);
// if _exception == null, we are about to throw an exception to the user
// and we haven't saved the exception, which also means we haven't dealt
// with it. So just release the connection and log this for investigation.
if (_exception == null)
{
if (NetEventSource.IsEnabled) NetEventSource.Error(this, exception);
SetException(exception);
FinishRequestStage(RequestStage.CheckForError);
}
throw;
}
finally
{
if (NetEventSource.IsEnabled) NetEventSource.Exit(this, _ftpWebResponse);
}
return _ftpWebResponse;
}