我尝试用.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-.net上使用异步/等待tcp函数(如stream.ReadAsync)时,使用epoll还是普通套接字?