Esempio n. 1
0
        public async ValueTask <IQuickSocket> GetUdpSocketAsync(string hostNameOrAddresss, int bindingPort, bool overideAsLocal = false, bool verbatimAddress = false)
        {
            var key = GetSocketKey(ProtocolType.Udp, SocketType.Stream, hostNameOrAddresss, bindingPort);

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

                var quickSocket = new QuickSocket
                {
                    Socket   = new Socket(dnsEntry.PrimaryAddress.AddressFamily, SocketType.Stream, ProtocolType.Udp),
                    DnsEntry = dnsEntry,
                };

                Sockets[key] = quickSocket;

                return(quickSocket);
            }
        }
Esempio n. 2
0
        public async Task StartWritingAsync()
        {
            await PipeLock.WaitAsync().ConfigureAwait(false);

            if (!Write)
            {
                Write = true;
            }

            await QuickSocket
            .ConnectToPrimaryAddressAsync()
            .ConfigureAwait(false);

            WriteLoopTask = Task.Run(WriteAsync);

            PipeLock.Release();
        }