fn read_event(&mut self, event_loop: &mut EventLoop<QApiConnection>) -> io::Result<()> {
        println!("Socket readable");

        // TODO: This returns None sometimes?  Why
        // let mut buf = self.mut_buf.take().unwrap();
        let mut buf = ByteBuf::mut_with_capacity(4096);

        match self.sock.try_read_buf(&mut buf) {
            Ok(None) => {
                println!("CONN : spurious read wakeup");
                self.mut_buf = Some(buf);
            }
            Ok(Some(r)) => {
                println!("CONN : we read {} bytes!", r);

                match self.state {
                    ClientState::ReadyForGreeting => {
                        self.parse_greeting(buf.bytes());

                        self.interest.remove(EventSet::readable());
                        self.interest.insert(EventSet::writable());

                        let reply = ByteBuf::from_slice("{ \"execute\": \"qmp_capabilities\" }"
                            .as_bytes());
                        self.buf = Some(reply);
                        // Update our state
                        // Lets ask for the capabilities set
                        self.state = ClientState::ReadyForCapabilities;
                    }
                    ClientState::ReadyForCapabilities => {
                        self.parse_capabilities(buf.bytes());

                        let reply = ByteBuf::from_slice("{ \"execute\": \"query-commands\" }"
                            .as_bytes());
                        self.buf = Some(reply);
                        // Update our state
                        // Lets ask for the capabilities set
                        self.state = ClientState::ReadyForCommands;
                        self.interest.remove(EventSet::readable());
                        self.interest.insert(EventSet::writable());
                    }
                    ClientState::ReadyForCommands => {
                        self.parse_commands(buf.bytes());

                        // Update our state
                        // Lets ask for the capabilities set
                        self.state = ClientState::Ready;

                        // Wait for user input now
                    }
                    ClientState::Ready => {
                        // Ready to receive events and user input
                        self.interest.remove(EventSet::readable());
                        self.interest.insert(EventSet::writable());
                    }
                }
            }
            Err(e) => {
                println!("not implemented; client err={:?}", e);
                self.interest.remove(EventSet::readable());
            }
        };

        event_loop.reregister(&self.sock, self.token, self.interest, PollOpt::edge())
    }
/// There's an initial ping/pong type communication going on between the client and the
/// qemu server to figure out what version we're talking and what the server is capable of.
/// Once the ClientState settles into ClientState::Ready then we're ready to take
/// user commands.
There's an initial ping/pong type communication going on between the client and the
qemu server to figure out what version we're talking and what the server is capable of.
Once the ClientState settles into ClientState::Ready then we're ready to take
user commands.
There ' s an initial ping / pong type communication going on between the client and the qemu server to figure out what version we ' re talking and what the server is capable of . Once the ClientState settles into ClientState :: Ready then we ' re ready to take user commands .
fn read_event(&mut self, event_loop: &mut EventLoop<QApiConnection>) -> io::Result<()> {
        println!("Socket readable");
        // TODO: This returns None sometimes?  Why
        // let mut buf = self.mut_buf.take().unwrap();
        let mut buf = ByteBuf::mut_with_capacity(4096);
        match self.sock.try_read_buf(&mut buf) {
            Ok(None) => {
                println!("CONN : spurious read wakeup");
                self.mut_buf = Some(buf);
            }
            Ok(Some(r)) => {
                println!("CONN : we read {} bytes!", r);
                match self.state {
                    ClientState::ReadyForGreeting => {
                        self.parse_greeting(buf.bytes());
                        self.interest.remove(EventSet::readable());
                        self.interest.insert(EventSet::writable());
                        let reply = ByteBuf::from_slice("{ \"execute\": \"qmp_capabilities\" }"
                            .as_bytes());
                        self.buf = Some(reply);
                        // Update our state
                        // Lets ask for the capabilities set
                        self.state = ClientState::ReadyForCapabilities;
                    }
                    ClientState::ReadyForCapabilities => {
                        self.parse_capabilities(buf.bytes());
                        let reply = ByteBuf::from_slice("{ \"execute\": \"query-commands\" }"
                            .as_bytes());
                        self.buf = Some(reply);
                        // Update our state
                        // Lets ask for the capabilities set
                        self.state = ClientState::ReadyForCommands;
                        self.interest.remove(EventSet::readable());
                        self.interest.insert(EventSet::writable());
                    }
                    ClientState::ReadyForCommands => {
                        self.parse_commands(buf.bytes());
                        // Update our state
                        // Lets ask for the capabilities set
                        self.state = ClientState::Ready;
                        // Wait for user input now
                    }
                    ClientState::Ready => {
                        // Ready to receive events and user input
                        self.interest.remove(EventSet::readable());
                        self.interest.insert(EventSet::writable());
                    }
                }
            }
            Err(e) => {
                println!("not implemented; client err={:?}", e);
                self.interest.remove(EventSet::readable());
            }
        };
        event_loop.reregister(&self.sock, self.token, self.interest, PollOpt::edge())
    }
fn read_event ( & mut self , event_loop : & mut EventLoop < QApiConnection > ) -> io :: Result < ( ) > { println ! ( " " ) ; // TODO: This returns None sometimes?  Why // let mut buf = self.mut_buf.take().unwrap(); let mut buf = ByteBuf :: mut_with_capacity ( 4096 ) ; match self . sock . try_read_buf ( & mut buf ) { Ok ( None ) => { println ! ( " " ) ; self . mut_buf = Some ( buf ) ; } Ok ( Some ( r ) ) => { println ! ( " " r ) ; match self . state { ClientState :: ReadyForGreeting => { self . parse_greeting ( buf . bytes ( ) ) ; self . interest . remove ( EventSet :: readable ( ) ) ; self . interest . insert ( EventSet :: writable ( ) ) ; let reply = ByteBuf :: from_slice ( " \" \" \" \" " . as_bytes ( ) ) ; self . buf = Some ( reply ) ; // Update our state // Lets ask for the capabilities set self . state = ClientState :: ReadyForCapabilities ; } ClientState :: ReadyForCapabilities => { self . parse_capabilities ( buf . bytes ( ) ) ; let reply = ByteBuf :: from_slice ( " \" \" \" \" " . as_bytes ( ) ) ; self . buf = Some ( reply ) ; // Update our state // Lets ask for the capabilities set self . state = ClientState :: ReadyForCommands ; self . interest . remove ( EventSet :: readable ( ) ) ; self . interest . insert ( EventSet :: writable ( ) ) ; } ClientState :: ReadyForCommands => { self . parse_commands ( buf . bytes ( ) ) ; // Update our state // Lets ask for the capabilities set self . state = ClientState :: Ready ; // Wait for user input now } ClientState :: Ready => { // Ready to receive events and user input self . interest . remove ( EventSet :: readable ( ) ) ; self . interest . insert ( EventSet :: writable ( ) ) ; } } } Err ( e ) => { println ! ( " " e ) ; self . interest . remove ( EventSet :: readable ( ) ) ; } } ; event_loop . reregister ( & self . sock , self . token , self . interest , PollOpt :: edge ( ) ) }
There's an initial ping/pong type communication going on between the client and the
qemu server to figure out what version we're talking and what the server is capable of.
There ' s an initial ping / pong type communication going on between the client and the qemu server to figure out what version we ' re talking and what the server is capable of .
&mut self
event_loop
&mut EventLoop<QApiConnection>
&mut self
event_loop
&mut EventLoop<QApiConnection>