Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix long standing SYNC/ASYNC method interface mixup #1422

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions FluentFTP/Client/AsyncFtpClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using FluentFTP.Client.BaseClient;

namespace FluentFTP {
Expand Down Expand Up @@ -93,11 +94,11 @@ public partial class AsyncFtpClient : BaseFtpClient, IInternalFtpClient, IDispos

#endregion

void IInternalFtpClient.ConnectInternal(bool reConnect, CancellationToken token) {
Connect(reConnect, token).GetAwaiter().GetResult();
async Task IInternalFtpClient.ConnectInternal(bool reConnect, CancellationToken token) {
await ((IAsyncFtpClient)this).Connect(reConnect, token);
}
void IInternalFtpClient.DisconnectInternal(CancellationToken token) {
Disconnect(token).GetAwaiter().GetResult();
async Task IInternalFtpClient.DisconnectInternal(CancellationToken token) {
await ((IAsyncFtpClient)this).Disconnect(token);
}

#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
Expand Down
14 changes: 9 additions & 5 deletions FluentFTP/Client/BaseFtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Threading;
using System.Threading.Tasks;

namespace FluentFTP.Client.BaseClient {
public partial class BaseFtpClient : IDisposable, IInternalFtpClient {
Expand Down Expand Up @@ -155,14 +156,17 @@ public partial class BaseFtpClient : IDisposable, IInternalFtpClient {

#endregion

void IInternalFtpClient.DisconnectInternal() {
void IInternalFtpClient.ConnectInternal(bool reConnect) {
((IFtpClient)this).Connect(reConnect);
}
void IInternalFtpClient.DisconnectInternal(CancellationToken token) {
async Task IInternalFtpClient.ConnectInternal(bool reConnect, CancellationToken token) {
await ((IAsyncFtpClient)this).Connect(reConnect, token);
}

void IInternalFtpClient.ConnectInternal(bool reConnect) {
void IInternalFtpClient.DisconnectInternal() {
((IFtpClient)this).Disconnect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or this #1461

}
void IInternalFtpClient.ConnectInternal(bool reConnect, CancellationToken token) {
async Task IInternalFtpClient.DisconnectInternal(CancellationToken token) {
await ((IAsyncFtpClient)this).Disconnect(token);
}

#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
Expand Down
6 changes: 4 additions & 2 deletions FluentFTP/Client/FtpClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Net;
using System.Threading.Tasks;
using FluentFTP.Client.BaseClient;

namespace FluentFTP {
Expand Down Expand Up @@ -93,10 +94,11 @@ public partial class FtpClient : BaseFtpClient, IInternalFtpClient, IDisposable,
#endregion

void IInternalFtpClient.ConnectInternal(bool reConnect) {
Connect(reConnect);
((IFtpClient)this).Connect(reConnect);
}

void IInternalFtpClient.DisconnectInternal() {
Disconnect();
((IFtpClient)this).Disconnect();
Copy link
Contributor

@kmgallahan kmgallahan Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the cause of #1461 as dispose doesn't use an async disconnect

Copy link
Collaborator Author

@FanDjango FanDjango Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trouble is, it should, as it (often) invokes an Execute to issue a QUIT command, which should also run async on an async client.

So, it needs a little more finesse - the entire Dispose method would need asyncification, so to speak, in case the client is of type AsyncFtpClient.

}

#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
Expand Down
4 changes: 2 additions & 2 deletions FluentFTP/Client/Interfaces/IInternalFtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace FluentFTP {
public interface IInternalFtpClient {

void ConnectInternal(bool reConnect);
void ConnectInternal(bool reConnect, CancellationToken token);
Task ConnectInternal(bool reConnect, CancellationToken token);

void DisconnectInternal();
void DisconnectInternal(CancellationToken token);
Task DisconnectInternal(CancellationToken token);

FtpReply ExecuteInternal(string command);

Expand Down