【问题标题】:.net core async/await tcp with linux.net 核心异步/等待 tcp 与 linux
【发布时间】:2018-12-02 19:38:24
【问题描述】:

我尝试用 .net 和 linux 用代码编写简单的回显服务器

    static async Task soc() {
        var listener = new TcpListener(IPAddress.Loopback, 8888);
        listener.Start();
        for (;;) {
            logger.LogInformation("Wait new connetcion");
            using(var client = await listener.AcceptTcpClientAsync())
            {
                logger.LogInformation("Get new connection");
                echo(client);
                client.Close();
            }
        }
    }

    static async void echo(TcpClient client) {
        var buf = new byte[512];
        using(var stream = client.GetStream())
        {
            var i = await stream.ReadAsync(buf, 0, 512);

            if (i < 1) {
                return;
            }

            await stream.WriteAsync(buf, 0, 512);
        }
    }

当我在 linux 上使用像 stream.ReadAsync 这样的 async/await tcp 函数时 - .net 使用 epoll 还是普通套接字?

【问题讨论】:

  • 您是在询问 .NET 运行时如何在 Linux 上实现异步套接字?运行时是开源的,何不自己去寻找呢?
  • 你是完全正确的。 .net 在 linux 上使用 epool 进行异步操作github.com/dotnet/corefx/blob/master/src/Native/Unix/…
  • 随时为您的发现添加简短的描述性答案。

标签: .net linux .net-core epoll


【解决方案1】:

.net core 在 linux 上使用 epoll 进行异步操作,you can see it in runtime sources

【讨论】:

    猜你喜欢
    • 2014-02-15
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    • 2018-03-13
    • 2021-09-19
    • 2014-02-21
    相关资源
    最近更新 更多