Skip to content

Commit 1bca5d4

Browse files
committed
JSON RPC control connection is working now
1 parent 6061b81 commit 1bca5d4

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

samples/FtpServer/FtpClientInactivityJob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task Execute(IJobExecutionContext context)
2222
{
2323
var client = clientInfo.Client;
2424
// clientInfo.ConnectionContext.ConnectionId;
25-
var inactivity = await client.Control.GetInactivityAsync(context.CancellationToken);
25+
var inactivity = await client.Control.GetInactivity(context.CancellationToken);
2626
if (inactivity >= _inactivityTimeSpan)
2727
{
2828
clientInfo.ConnectionContext.Abort();

src/FubarDev.FtpServer.Abstractions/IFtpClientControl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace FubarDev.FtpServer.Abstractions;
66

77
public interface IFtpClientControl
88
{
9-
Task PingAsync(CancellationToken cancellationToken = default);
10-
Task<DateTimeOffset> GetLastActivityAsync(CancellationToken cancellationToken = default);
11-
Task<TimeSpan> GetInactivityAsync(CancellationToken cancellationToken = default);
9+
Task Ping(CancellationToken cancellationToken = default);
10+
Task<DateTimeOffset> GetLastActivity(CancellationToken cancellationToken = default);
11+
Task<TimeSpan> GetInactivity(CancellationToken cancellationToken = default);
1212
}

src/FubarDev.FtpServer.Client.Embedded/EmbeddedFtpClientControl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ public EmbeddedFtpClientControl(FtpConnection connection)
1616
_connection = connection;
1717
}
1818

19-
public Task PingAsync(CancellationToken cancellationToken = default)
19+
public Task Ping(CancellationToken cancellationToken = default)
2020
{
2121
_connection.Ping();
2222
return Task.CompletedTask;
2323
}
2424

25-
public Task<DateTimeOffset> GetLastActivityAsync(CancellationToken cancellationToken = default)
25+
public Task<DateTimeOffset> GetLastActivity(CancellationToken cancellationToken = default)
2626
{
2727
return Task.FromResult(_connection.GetLastActivity());
2828
}
2929

30-
public Task<TimeSpan> GetInactivityAsync(CancellationToken cancellationToken = default)
30+
public Task<TimeSpan> GetInactivity(CancellationToken cancellationToken = default)
3131
{
3232
return Task.FromResult(_connection.GetInactivity());
3333
}

src/FubarDev.FtpServer.Client.External/ExternalFtpClientData.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using FubarDev.FtpServer.Abstractions;
1010

1111
using Microsoft.AspNetCore.Connections;
12+
using Microsoft.Extensions.Logging;
1213

1314
using Nerdbank.Streams;
1415

@@ -19,6 +20,7 @@ namespace FubarDev.FtpServer.Client.External;
1920
internal class ExternalFtpClientData : IAsyncDisposable
2021
{
2122
private readonly ExternalFtpClientFactory _clientFactory;
23+
private readonly ILogger _logger;
2224
private Stream? _clientTransportStream;
2325
private Stream? _serverTransportStream;
2426
private MultiplexingStream? _multiplexer;
@@ -29,10 +31,12 @@ internal class ExternalFtpClientData : IAsyncDisposable
2931

3032
public ExternalFtpClientData(
3133
ConnectionContext connectionContext,
32-
ExternalFtpClientFactory clientFactory)
34+
ExternalFtpClientFactory clientFactory,
35+
ILogger logger)
3336
{
3437
ConnectionContext = connectionContext;
3538
_clientFactory = clientFactory;
39+
_logger = logger;
3640
}
3741

3842
public ConnectionContext ConnectionContext { get; }
@@ -84,7 +88,9 @@ public async ValueTask InitializeAsync(CancellationToken cancellationToken)
8488
// new LengthHeaderMessageHandler(clientControlPipe, new MessagePackFormatter());
8589
IJsonRpcMessageHandler handler =
8690
new HeaderDelimitedMessageHandler(clientControlPipe, new JsonMessageFormatter());
87-
_clientControl = JsonRpc.Attach<IFtpClientControl>(handler);
91+
var rpc = new JsonRpc(handler);
92+
_clientControl = rpc.Attach<IFtpClientControl>();
93+
rpc.StartListening();
8894
}
8995

9096
public async ValueTask DisposeAsync()

src/FubarDev.FtpServer.Client.External/ExternalFtpClientFactory.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@
1111

1212
using Microsoft.AspNetCore.Connections;
1313
using Microsoft.Extensions.DependencyInjection;
14+
using Microsoft.Extensions.Logging;
1415

1516
namespace FubarDev.FtpServer.Client.External;
1617

1718
public class ExternalFtpClientFactory : IFtpClientFactory
1819
{
1920
private readonly IServiceProvider _serviceProvider;
21+
private readonly ILogger<ExternalFtpClientFactory> _logger;
2022
private readonly Assembly _clientAssembly;
2123
private readonly string _clientExecutable;
2224
private readonly bool _startedWithDotnetTool;
2325

2426
public ExternalFtpClientFactory(
25-
IServiceProvider serviceProvider)
27+
IServiceProvider serviceProvider,
28+
ILogger<ExternalFtpClientFactory> logger)
2629
{
2730
_serviceProvider = serviceProvider;
31+
_logger = logger;
2832
var startExecutable = Path.GetFileName(Environment.ProcessPath)
2933
?? throw new InvalidOperationException();
3034
_startedWithDotnetTool = startExecutable.ToLowerInvariant() switch
@@ -49,7 +53,7 @@ public async ValueTask<IFtpClient> CreateClientAsync(
4953
ConnectionContext connectionContext,
5054
CancellationToken cancellationToken = default)
5155
{
52-
var data = new ExternalFtpClientData(connectionContext, this);
56+
var data = new ExternalFtpClientData(connectionContext, this, _logger);
5357
await data.InitializeAsync(cancellationToken);
5458
var ftpClient = ActivatorUtilities.CreateInstance<ExternalFtpClient>(_serviceProvider, data);
5559
return ftpClient;

src/FubarDev.FtpServer.Client.External/HostedFtpConnection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
3939
new HeaderDelimitedMessageHandler(serverControlPipe, new JsonMessageFormatter());
4040

4141
using var rpc = new JsonRpc(handler, _connection);
42+
rpc.StartListening();
43+
4244
await _connection.RunAsync(stoppingToken);
4345
}
4446
}

0 commit comments

Comments
 (0)