コード例 #1
0
ファイル: StandardClient.cs プロジェクト: PokeD/PokeD.Server
        public sealed override void Update()
        {
            UpdateLock.Reset(); // Signal that the UpdateThread is alive.
            try
            {
                while (!UpdateToken.IsCancellationRequested && Stream.IsConnected)
                {
                    ConnectionLock.Reset(); // Signal that we are handling pending client data.
                    try
                    {
                        while (Stream.TryReadPacket(out var packetToReceive))
                        {
                            HandlePacket(packetToReceive);

#if DEBUG
                            Received.Enqueue(packetToReceive);
                            if (Received.Count >= QueueSize)
                            {
                                Received.Dequeue();
                            }
#endif
                        }
                        while (PacketsToSend.TryDequeue(out var packetToSend))
                        {
                            Stream.SendPacket(packetToSend);

#if DEBUG
                            Sended.Enqueue(packetToSend);
                            if (Sended.Count >= QueueSize)
                            {
                                Sended.Dequeue();
                            }
#endif
                        }
                    }
                    finally
                    {
                        ConnectionLock.Set(); // Signal that we are not handling anymore pending client data.
                    }

                    Thread.Sleep(100); // 100 calls per second should not be too often?
                }
            }
            finally
            {
                UpdateLock.Set();                                                // Signal that the UpdateThread is finished

                if (!UpdateToken.IsCancellationRequested && !Stream.IsConnected) // Leave() if the update cycle stopped unexpectedly
                {
                    LeaveAsync();
                }
            }
        }
コード例 #2
0
        /// <summary> Save lock (new or existing). </summary>
        /// <param name="cLock">The lock to save.</param>
        public int SaveLockConnection(ConnectionLock cLock)
        {
            // Check
            if (cLock == null)
            {
                throw new CoreException("No lock specified");
            }

            // Insert or update
            if (cLock.Id == 0)
            {
                cLock.Id = repository.Insert(cLock).InsertId.Value;
            }
            else
            {
                repository.Update(cLock);
            }

            return(cLock.Id);
        }