Giter Club home page Giter Club logo

Comments (3)

taoyouh avatar taoyouh commented on August 16, 2024

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.

govorovvs avatar govorovvs commented on August 16, 2024

@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.

taoyouh avatar taoyouh commented on August 16, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.