Ejemplo n.º 1
0
        private void ReceiveLoop()
        {
            bool success;

            if (scheduler.Verbose)
            {
                Console.WriteLine("Starting receive loop with remote identified as {0}", IoScheduler.CertificateToString(remoteCert));
            }

            while (true)
            {
                // Read the next message's size.

                UInt64 messageSize;
                success = IoEncoder.ReadUInt64(stream, out messageSize);
                if (!success)
                {
                    if (scheduler.Verbose)
                    {
                        Console.Error.WriteLine("Failed to receive message size from {0}", IoScheduler.CertificateToString(remoteCert));
                    }
                    return;
                }
                if (scheduler.Verbose)
                {
                    Console.WriteLine("Received message size {0} from {1}", messageSize, IoScheduler.CertificateToString(remoteCert));
                }

                byte[] messageBuf = new byte[messageSize];
                success = IoEncoder.ReadBytes(stream, messageBuf, 0, messageSize);
                if (!success)
                {
                    if (scheduler.Verbose)
                    {
                        Console.Error.WriteLine("Failed to receive message of size {0} from {1}",
                                                messageSize, IoScheduler.CertificateToString(remoteCert));
                    }
                    return;
                }
                if (scheduler.Verbose)
                {
                    Console.WriteLine("Received message of size {0} from {1}", messageSize, IoScheduler.CertificateToString(remoteCert));
                }

                ReceivedPacket packet = new ReceivedPacket(remoteCert, messageBuf);
                scheduler.NoteReceivedPacket(packet);
            }
        }
Ejemplo n.º 2
0
        /////////////////////////////////////
        // RECEIVING
        /////////////////////////////////////

        public void NoteReceivedPacket(ReceivedPacket packet)
        {
            receiveQueue.Post(packet);
        }