当前位置: 首页>>代码示例>>C#>>正文


C# ConnectionMultiplexer.LogLocked方法代码示例

本文整理汇总了C#中StackExchange.Redis.ConnectionMultiplexer.LogLocked方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionMultiplexer.LogLocked方法的具体用法?C# ConnectionMultiplexer.LogLocked怎么用?C# ConnectionMultiplexer.LogLocked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StackExchange.Redis.ConnectionMultiplexer的用法示例。


在下文中一共展示了ConnectionMultiplexer.LogLocked方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolveEndPointsAsync

#pragma warning disable 1998 // NET40 is sync, not async, currently
        internal async Task ResolveEndPointsAsync(ConnectionMultiplexer multiplexer, TextWriter log)
        {
            Dictionary<string, IPAddress> cache = new Dictionary<string, IPAddress>(StringComparer.OrdinalIgnoreCase);
            for (int i = 0; i < endpoints.Count; i++)
            {
                var dns = endpoints[i] as DnsEndPoint;
                if (dns != null)
                {
                    try
                    {
                        IPAddress ip;
                        if (dns.Host == ".")
                        {
                            endpoints[i] = new IPEndPoint(IPAddress.Loopback, dns.Port);
                        }
                        else if (cache.TryGetValue(dns.Host, out ip))
                        { // use cache
                            endpoints[i] = new IPEndPoint(ip, dns.Port);
                        }
                        else
                        {
                            multiplexer.LogLocked(log, "Using DNS to resolve '{0}'...", dns.Host);
#if NET40
                            var ips = Dns.GetHostAddresses(dns.Host);
#else
                            var ips = await Dns.GetHostAddressesAsync(dns.Host).ObserveErrors().ForAwait();
#endif
                            if (ips.Length == 1)
                            {
                                ip = ips[0];
                                multiplexer.LogLocked(log, "'{0}' => {1}", dns.Host, ip);
                                cache[dns.Host] = ip;
                                endpoints[i] = new IPEndPoint(ip, dns.Port);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        multiplexer.OnInternalError(ex);
                        multiplexer.LogLocked(log, ex.Message);
                    }
                }
            }
        }
开发者ID:ltines,项目名称:StackExchange.Redis,代码行数:45,代码来源:ConfigurationOptions.cs

示例2: BeginConnect

        internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log)
        {
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            SetFastLoopbackOption(socket);
            socket.NoDelay = true;
            try
            {
                CompletionType connectCompletionType = CompletionType.Any;
                this.ShouldForceConnectCompletionType(ref connectCompletionType);

                var formattedEndpoint = Format.ToString(endpoint);
                if (endpoint is DnsEndPoint)
                {
                    // A work-around for a Mono bug in BeginConnect(EndPoint endpoint, AsyncCallback callback, object state)
                    DnsEndPoint dnsEndpoint = (DnsEndPoint)endpoint;
                    CompletionTypeHelper.RunWithCompletionType(
                        (cb) =>
                        {
                            multiplexer.LogLocked(log, "BeginConnect: {0}", formattedEndpoint);
                            return socket.BeginConnect(dnsEndpoint.Host, dnsEndpoint.Port, cb, Tuple.Create(socket, callback));
                        },
                        (ar) =>
                        {
                            multiplexer.LogLocked(log, "EndConnect: {0}", formattedEndpoint);
                            EndConnectImpl(ar, multiplexer, log);
                            multiplexer.LogLocked(log, "Connect complete: {0}", formattedEndpoint);
                        },
                        connectCompletionType);
                }
                else
                {
                    CompletionTypeHelper.RunWithCompletionType(
                        (cb) => {
                            multiplexer.LogLocked(log, "BeginConnect: {0}", formattedEndpoint);
                            return socket.BeginConnect(endpoint, cb, Tuple.Create(socket, callback));
                        },
                        (ar) => {
                            multiplexer.LogLocked(log, "EndConnect: {0}", formattedEndpoint);
                            EndConnectImpl(ar, multiplexer, log);
                            multiplexer.LogLocked(log, "Connect complete: {0}", formattedEndpoint);
                        },
                        connectCompletionType);
                }
            } 
            catch (NotImplementedException ex)
            {
                if (!(endpoint is IPEndPoint))
                {
                    throw new InvalidOperationException("BeginConnect failed with NotImplementedException; consider using IP endpoints, or enable ResolveDns in the configuration", ex);
                }
                throw;
            }
            var token = new SocketToken(socket);
            return token;
        }
开发者ID:liweisx,项目名称:StackExchange.Redis,代码行数:55,代码来源:SocketManager.cs

示例3: EndConnectImpl

 private void EndConnectImpl(IAsyncResult ar, ConnectionMultiplexer multiplexer, TextWriter log)
 {
     Tuple<Socket, ISocketCallback> tuple = null;
     try
     {
         tuple = (Tuple<Socket, ISocketCallback>)ar.AsyncState;
         bool ignoreConnect = false;
         ShouldIgnoreConnect(tuple.Item2, ref ignoreConnect);
         if (ignoreConnect) return;
         var socket = tuple.Item1;
         var callback = tuple.Item2;
         socket.EndConnect(ar);
         var netStream = new NetworkStream(socket, false);
         var socketMode = callback == null ? SocketMode.Abort : callback.Connected(netStream, log);
         switch (socketMode)
         {
             case SocketMode.Poll:
                 multiplexer.LogLocked(log, "Starting poll");
                 OnAddRead(socket, callback);
                 break;
             case SocketMode.Async:
                 multiplexer.LogLocked(log, "Starting read");
                 try
                 { callback.StartReading(); }
                 catch (Exception ex)
                 {
                     ConnectionMultiplexer.TraceWithoutContext(ex.Message);
                     Shutdown(socket);
                 }
                 break;
             default:
                 ConnectionMultiplexer.TraceWithoutContext("Aborting socket");
                 Shutdown(socket);
                 break;
         }
     }
     catch(ObjectDisposedException)
     {
         multiplexer.LogLocked(log, "(socket shutdown)");
         if (tuple != null)
         {
             try
             { tuple.Item2.Error(); }
             catch (Exception inner)
             {
                 ConnectionMultiplexer.TraceWithoutContext(inner.Message);
             }
         }
     }
     catch(Exception outer)
     {
         ConnectionMultiplexer.TraceWithoutContext(outer.Message);
         if (tuple != null)
         {
             try
             { tuple.Item2.Error(); }
             catch (Exception inner)
             {
                 ConnectionMultiplexer.TraceWithoutContext(inner.Message);
             }
         }
     }
 }
开发者ID:liweisx,项目名称:StackExchange.Redis,代码行数:63,代码来源:SocketManager.cs

示例4: EndConnectImpl

        private void EndConnectImpl(IAsyncResult ar, ConnectionMultiplexer multiplexer, TextWriter log, Tuple<Socket, ISocketCallback> tuple)
        {
            try
            {
                bool ignoreConnect = false;
                ShouldIgnoreConnect(tuple.Item2, ref ignoreConnect);
                if (ignoreConnect) return;
                var socket = tuple.Item1;
                var callback = tuple.Item2;
#if CORE_CLR
                multiplexer.Wait((Task)ar); // make it explode if invalid (note: already complete at this point)
#else
                socket.EndConnect(ar);
#endif
                var netStream = new NetworkStream(socket, false);
                var socketMode = callback?.Connected(netStream, log) ?? SocketMode.Abort;
                switch (socketMode)
                {
                    case SocketMode.Poll:
                        multiplexer.LogLocked(log, "Starting poll");
                        OnAddRead(socket, callback);
                        break;
                    case SocketMode.Async:
                        multiplexer.LogLocked(log, "Starting read");
                        try
                        { callback.StartReading(); }
                        catch (Exception ex)
                        {
                            ConnectionMultiplexer.TraceWithoutContext(ex.Message);
                            Shutdown(socket);
                        }
                        break;
                    default:
                        ConnectionMultiplexer.TraceWithoutContext("Aborting socket");
                        Shutdown(socket);
                        break;
                }
            }
            catch (ObjectDisposedException)
            {
                multiplexer.LogLocked(log, "(socket shutdown)");
                if (tuple != null)
                {
                    try
                    { tuple.Item2.Error(); }
                    catch (Exception inner)
                    {
                        ConnectionMultiplexer.TraceWithoutContext(inner.Message);
                    }
                }
            }
            catch(Exception outer)
            {
                ConnectionMultiplexer.TraceWithoutContext(outer.Message);
                if (tuple != null)
                {
                    try
                    { tuple.Item2.Error(); }
                    catch (Exception inner)
                    {
                        ConnectionMultiplexer.TraceWithoutContext(inner.Message);
                    }
                }
            }
        }
开发者ID:491134648,项目名称:StackExchange.Redis,代码行数:65,代码来源:SocketManager.cs


注:本文中的StackExchange.Redis.ConnectionMultiplexer.LogLocked方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。