示例#1
0
        public async ValueTask <IQuickListeningSocket> GetListeningTcpSocketAsync(string hostNameOrAddresss, int bindingPort, bool overideAsLocal = false, bool verbatimAddress = false)
        {
            var key = GetSocketKey(ProtocolType.Tcp, SocketType.Stream, hostNameOrAddresss, bindingPort);

            if (ListeningSockets.ContainsKey(key))
            {
                return(ListeningSockets[key]);
            }
            else
            {
                var dnsEntry = await DnsCaching
                               .GetDnsEntryAsync(hostNameOrAddresss, bindingPort, overideAsLocal, verbatimAddress)
                               .ConfigureAwait(false);

                var quickListeningSocket = new QuickListeningSocket
                {
                    Socket   = new Socket(dnsEntry.PrimaryAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp),
                    DnsEntry = dnsEntry,
                };

                ListeningSockets[key] = quickListeningSocket;

                return(quickListeningSocket);
            }
        }
示例#2
0
        public async Task StartReceiveAsync()
        {
            await PipeLock.WaitAsync().ConfigureAwait(false);

            if (!Receive)
            {
                Receive = true;

                await QuickListeningSocket
                .BindSocketToAddressAsync(100)
                .ConfigureAwait(false);

                ReceiveLoopTask = Task.Run(ReceiveAsync);
            }

            PipeLock.Release();
        }