예제 #1
0
        void receiver_thread_main()
        {
            Connection conn = vm.Connection;

            while (true)
            {
                byte[] packet = conn.ReadPacket();

                if (packet.Length == 0)
                {
                    disconnected = true;

                    VMDisconnectEventImpl ev = new VMDisconnectEventImpl(vm, null);
                    add_event_set(new EventSetImpl(vm, new Event [] { ev }, SuspendPolicy.SuspendNone));
                    break;
                }

                if (WireProtocol.IsReplyPacket(packet))
                {
                    /* Reply packet */
                    int id = WireProtocol.GetPacketId(packet);
                    lock (reply_packets_monitor)
                    {
                        reply_packets [id] = packet;
                        Monitor.PulseAll(reply_packets_monitor);
                    }
                }
                else
                {
                    WireProtocol.Packet decoded = WireProtocol.DecodePacket(packet);
                    if (decoded is WireProtocol.Event.CompositePacket)
                    {
                        WireProtocol.Event.CompositePacket p = (WireProtocol.Event.CompositePacket)decoded;
                        Event[] events = new Event [p.events.Length];
                        for (int i = 0; i < p.events.Length; ++i)
                        {
                            events [i] = DecodeEventInfo(p.events [i]);
                        }

                        add_event_set(new EventSetImpl(vm, events, p.suspendPolicy));
                    }
                }
            }
        }