Example #1
0
        private void Initialize(IPEndPoint address, bool connect)
        {
            lock (sendLoopLock)
            {
                ClientId           = 0;
                closed             = 0;
                smoothedRtt        = MaxRetryInterval;
                smoothedRttVar     = TimeSpan.Zero;
                currentRto         = MaxRetryInterval;
                lastSentPingId     = 0;
                lastReceivedPingId = 0;
                lastMessageTimer.Restart();

                initPacketCheck = null;
                packetAckManager.Clear();
                receiveQueueCommand.Clear();
                receiveQueueCommandLow.Clear();
                receiveWindowVoice.Reset();
                receiveWindowVoiceWhisper.Reset();
                Array.Clear(packetCounter, 0, packetCounter.Length);
                Array.Clear(generationCounter, 0, generationCounter.Length);
                NetworkStats.Reset();

                socket?.Dispose();
                try
                {
                    if (connect)
                    {
                        remoteAddress = address;
                        socket        = new Socket(address.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                        socket.Bind(new IPEndPoint(address.AddressFamily == AddressFamily.InterNetwork ? IPAddress.Any : IPAddress.IPv6Any, 0));

                        var socketEventArgs = new SocketAsyncEventArgs();
                        socketEventArgs.SetBuffer(new byte[4096], 0, 4096);
                        socketEventArgs.Completed     += FetchPacketEvent;
                        socketEventArgs.UserToken      = this;
                        socketEventArgs.RemoteEndPoint = remoteAddress;
                        socket.ReceiveFromAsync(socketEventArgs);
                    }
                    else
                    {
                        remoteAddress = null;
                        socket        = new Socket(address.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                        socket.Bind(address);
                        // TODO init socketevargs stuff
                    }
                }
                catch (SocketException ex) { throw new Ts3Exception("Could not connect", ex); }

                pingCheckRunning = 0;
                pingCheck        = Util.Now;
                if (resendTimer == null)
                {
                    resendTimer = new Timer((_) => { using (MappedDiagnosticsContext.SetScoped("BotId", id)) ResendLoop(); }, null, ClockResolution, ClockResolution);
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            using (MappedDiagnosticsContext.SetScoped("order-number", 1024))
            {
                Logger.Info("Message before a trace.");

                using (var scope = Tracer.Instance.StartActive("NLog45Example - Main()"))
                {
                    Logger.Info("Message during a trace.");
                }

                Logger.Info("Message after a trace.");
            }
        }
        public void disposable_removes_item()
        {
            const string itemNotRemovedKey = "itemNotRemovedKey";
            const string itemRemovedKey    = "itemRemovedKey";

            MappedDiagnosticsContext.Clear();
            MappedDiagnosticsContext.Set(itemNotRemovedKey, "itemNotRemoved");
            using (MappedDiagnosticsContext.SetScoped(itemRemovedKey, "itemRemoved"))
            {
                Assert.Equal(MappedDiagnosticsContext.GetNames(), new[] { itemNotRemovedKey, itemRemovedKey });
            }

            Assert.Equal(MappedDiagnosticsContext.GetNames(), new[] { itemNotRemovedKey });
        }
        public void dispose_is_idempotent()
        {
            const string itemKey = "itemKey";

            MappedDiagnosticsContext.Clear();
            IDisposable disposable = MappedDiagnosticsContext.SetScoped(itemKey, "item1");

            disposable.Dispose();
            Assert.False(MappedDiagnosticsContext.Contains(itemKey));

            //This item shouldn't be removed since it is not the disposable one
            MappedDiagnosticsContext.Set(itemKey, "item2");
            disposable.Dispose();

            Assert.True(MappedDiagnosticsContext.Contains(itemKey));
        }
Example #5
0
        public static void Main(string[] args)
        {
            // Obtain the automatically registered OpenTracing.Util.GlobalTracer instance
            var tracer = GlobalTracer.Instance;

            using (MappedDiagnosticsContext.SetScoped("order-number", 1024))
            {
                Logger.Info("Message before a trace.");

                using (var scope = tracer.BuildSpan("NLog45Example - Main()").StartActive(finishSpanOnDispose: true))
                {
                    Logger.Info("Message during a trace.");
                }

                Logger.Info("Message after a trace.");
            }
        }