Comments (3)
The resources (TcpListener) held by FtpServer should be released when the CancellationToken in FtpServer.RunAsync() has a cancel request. There will be nothing to dispose.
from ftpserver.
@taoyouh how do you think, which code is more clean and obvious?
[Fact]
public async Task Test()
{
// arrange
var endPoint = new IPEndPoint(IPAddress.Loopback, 21);
var ftpServer = new FtpServer(endPoint, Directory.GetCurrentDirectory());
var cancellationTokenSource = new CancellationTokenSource();
await ftpServer.RunAsync(cancellationTokenSource.Token);
var ftpServerCaller = new FtpServerCaller();
// act
try
{
await ftpServerCaller.CallFtpServer();
}
finally
{
cancellationTokenSource.Cancel();
}
// assert
ftpServerCaller.CheckResult();
}
or
[Fact]
public async Task Test()
{
// arrange
var endPoint = new IPEndPoint(IPAddress.Loopback, 21);
using var ftpServer = new FtpServer(endPoint, Directory.GetCurrentDirectory());
await ftpServer.RunAsync();
var ftpServerCaller = new FtpServerCaller();
// act
await ftpServerCaller.CallFtpServer();
// assert
ftpServerCaller.CheckResult();
}
from ftpserver.
Both version of your code will not work. You have to be running RunAsync to accept a connection. You cannot just await it (it will not complete unless you cancel it).
Maybe you prefer a .Start() and .StopAsync() pattern rather than the current Run() pattern, but that will need a new thread be created to run the main server loop. A simple wrapper could be written on the client side to implement this.
If we must use IDisposable pattern, we need to find a way to stop all existing connections synchronously (because Dispose is not async).
from ftpserver.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ftpserver.