zoukankan      html  css  js  c++  java
  • 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;
            }
    气功波(18037675651)
  • 相关阅读:
    Leetcode-113 Path Sum II(路径总和 II)
    Leetcode-946 验证栈序列(Validate Stack Sequences)
    Leetcode-945 Minimum Increment to Make Array Unique(使数组唯一的最小增量)
    UVa-10129 Play on Words
    UVa-10305 Ordering Tasks
    UVa-816 Abbott's Revenge
    UVa-1103 Ancient Messages
    种子填充(flood fill)
    内存池
    Leetcode-942 DI String Match(增减字符串匹配)
  • 原文地址:https://www.cnblogs.com/qgbo/p/11978220.html
Copyright © 2011-2022 走看看