Ejemplo n.º 1
0
        private static void queueLoop(List <QueueMessageRecv> queue)
        {
            // Prepare an special message object to use while receiving and parsing, without locking up the queue messages
            QueueMessageRecv active_message = new QueueMessageRecv();

            while (!shouldStop)
            {
                TLC.Report();
                bool message_found = false;
                lock (queue)
                {
                    if (queue.Count > 0)
                    {
                        // Pick the oldest message
                        active_message = queue[0];
                        message_found  = true;
                        // Remove it from the queue
                        queue.RemoveAt(0);
                    }
                }

                if (message_found)
                {
                    Logging.trace("Received {0} ({1}B) - {2}...", active_message.code, active_message.data.Length, Crypto.hashToString(active_message.data.Take(60).ToArray()));
                    // Active message set, attempt to parse it
                    IxianHandler.parseProtocolMessage(active_message.code, active_message.data, active_message.endpoint);
                }
                else
                {
                    // Sleep for 10ms to prevent cpu waste
                    Thread.Sleep(10);
                }
            }
            Logging.info("Network queue thread stopped.");
        }
Ejemplo n.º 2
0
        // Actual tx network queue logic
        public static void txqueueThreadLoop()
        {
            // Prepare an special message object to use while receiving and parsing, without locking up the queue messages
            QueueMessageRecv active_message = new QueueMessageRecv();
            QueueMessageRecv candidate      = new QueueMessageRecv();

            while (!shouldStop)
            {
                TLC.Report();
                bool message_found = false;
                lock (txqueueMessages)
                {
                    if (txqueueMessages.Count > 0)
                    {
                        // Pick the oldest message
                        candidate               = txqueueMessages[0];
                        active_message.code     = candidate.code;
                        active_message.data     = candidate.data;
                        active_message.checksum = candidate.checksum;
                        active_message.endpoint = candidate.endpoint;
                        message_found           = true;
                    }
                }

                if (message_found)
                {
                    // Active message set, attempt to parse it
                    IxianHandler.parseProtocolMessage(active_message.code, active_message.data, active_message.endpoint);
                    lock (txqueueMessages)
                    {
                        // Remove it from the queue
                        txqueueMessages.Remove(candidate);
                    }
                    // Sleep a bit to allow other threads to do their thing
                    Thread.Yield();
                }
                else
                {
                    // Sleep for 10ms to prevent cpu waste
                    Thread.Sleep(10);
                }
            }
            Logging.info("Network Tx queue thread stopped.");
        }