Asp.netCore 是用的Socket 嗎?


Asp.netCore 是用的Socket 的krestrel 用的是Socket!

public static IWebHostBuilder CreateDefaultBuilder(string[] args)
        {
            IWebHostBuilder webHostBuilder = new WebHostBuilder().UseKestrel(delegate (WebHostBuilderContext builderContext, KestrelServerOptions options)
            {
                options.Configure(builderContext.Configuration.GetSection("Kestrel"));
            })

  

        public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder)
        {
            return hostBuilder.ConfigureServices(delegate (IServiceCollection services)
            {
                services.TryAddSingleton<ITransportFactory, SocketTransportFactory>();
                services.AddTransient<IConfigureOptions<KestrelServerOptions>, KestrelServerOptionsSetup>();
                services.AddSingleton<IServer, KestrelServer>();
            });
        }

  再進去,終於看到了:

public Task BindAsync()
        {
            if (_listenSocket != null)
            {
                throw new InvalidOperationException(SocketsStrings.TransportAlreadyBound);
            }
            IPEndPoint iPEndPoint = _endPointInformation.IPEndPoint;
            Socket socket = new Socket(iPEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            EnableRebinding(socket);
            if (iPEndPoint.Address == IPAddress.IPv6Any)
            {
                socket.DualMode = true;
            }
            try
            {
                socket.Bind(iPEndPoint);
            }
            catch (SocketException ex) when (ex.SocketErrorCode == SocketError.AddressAlreadyInUse)
            {
                throw new AddressInUseException(((Exception)ex).Message, (Exception)ex);
            }
            if (_endPointInformation.IPEndPoint.Port == 0)
            {
                _endPointInformation.IPEndPoint = (IPEndPoint)socket.LocalEndPoint;
            }
            socket.Listen(512);
            _listenSocket = socket;
            _listenTask = Task.Run(() => RunAcceptLoopAsync());
            return Task.CompletedTask;
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM