Skip to content

Commit

Permalink
Revert "Dispose of FtpDataStream Now Reads Control Reply"
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh Gupta authored Aug 26, 2017
1 parent 34a7786 commit 9f1ef6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 58 deletions.
49 changes: 11 additions & 38 deletions FluentFTP/Stream/FtpDataStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,55 +139,28 @@ public void SetPosition(long pos) {
m_position = pos;
}

private FtpReply m_closedDataStreamReply;

/// <summary>
/// Disconnects (if necessary) and releases associated resources
/// </summary>
/// <param name="disposing">Disposing</param>
protected override void Dispose(bool disposing)
{
if (disposing)
{
// If we were connected then we need to handle the response
// from the control connection after closing the data
// connection
var wasConnected = IsConnected;

// Calling base dispose first to actually terminate the
// network streams before we handle the reply from the control
// connection
base.Dispose(true);

if (wasConnected)
{
m_closedDataStreamReply = HandleClosedDataStreamReply();
}
protected override void Dispose(bool disposing) {
if (disposing) {
if (IsConnected)
Close();

m_control = null;
}
else
{
base.Dispose(false);
}

base.Dispose(disposing);
}

/// <summary>
/// Closes the connection and reads the server's reply
/// </summary>
public new FtpReply Close()
{
// This will eventually invoke our Dispose(bool) method
// and assign m_closedDataStreamReply
/// <summary>
/// Closes the connection and reads the server's reply
/// </summary>
public new FtpReply Close() {
base.Close();

return m_closedDataStreamReply;
}

private FtpReply HandleClosedDataStreamReply()
{
try
{
try {
if (ControlConnection != null)
return ControlConnection.CloseDataStream(this);
} finally {
Expand Down
24 changes: 4 additions & 20 deletions FluentFTP/Stream/FtpSocketStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,36 +656,18 @@ public async Task WriteLineAsync(System.Text.Encoding encoding, string buf) {
public new void Dispose()
{
FtpTrace.WriteStatus(FtpTraceLevel.Verbose, "Disposing FtpSocketStream...");
base.Dispose();
Close();
}

/// <summary>
/// Disconnects from server
/// </summary>
#if CORE
public void Close() {
// We only implement Close for .NET Core so the API surface does not change
// The full .NET framework already has Close defined on Stream
Dispose();
}
#else
public override void Close()
{
base.Close();
}
#endif

/// <summary>
/// Disposes the stream
/// </summary>
protected override void Dispose(bool disposing)
{
if (!disposing)
{
base.Dispose(false);
return;
}

if (m_socket != null)
{
try
Expand Down Expand Up @@ -751,7 +733,9 @@ protected override void Dispose(bool disposing)
}
#endif

base.Dispose(true);
#if CORE
base.Dispose();
#endif
}

/// <summary>
Expand Down

0 comments on commit 9f1ef6d

Please sign in to comment.