pub fn read_event(&mut self) -> io::Result<Event> {

        // This needs a good cleanup.
        
        let nbytes;
        let result = {
            let buf: &[u8] = try!(self.fd.fill_buf());

            if buf.len() == 0 {
                // I have a feeling this won't happen.
                // But if it does this is most sensible.
                return Err(io::Error::new(io::ErrorKind::WouldBlock, "No events available"));
            }

            assert!(buf.len() >= size_of::<ffi::event>(),
                    "Malformed event from drm device: {} < {}",
                    buf.len(), size_of::<ffi::event>());

            // Doing things the C way. There shouldn't be any byte-order issues.
            let ev_header: ffi::event = unsafe {
                *transmute::<_, *const ffi::event>(buf.as_ptr())
            };

            if buf.len() < ev_header.length as usize {
                nbytes = buf.len();
                Err(io::Error::new(ErrorKind::InvalidData, "Short DRM event"))
            } else {
                nbytes = ev_header.length as usize;
                match ev_header.type_ {
                    consts::DRM_EVENT_VBLANK | consts::DRM_EVENT_FLIP_COMPLETE => {
                        let ev: ffi::event_vblank = unsafe {
                            *transmute::<_, *const ffi::event_vblank>(buf.as_ptr())
                        };
                        
                        // This is not good.  This works fine on linux
                        // for now, as Instant is stored as a timespec.
                        // But it may not be portable and it may break.
                        let at: Instant = unsafe {
                            transmute(libc::timespec { tv_sec: ev.tv_sec as i64,
                                                       tv_nsec: ev.tv_usec as i64 * 1000 })
                        };
                        
                        match ev.base.type_ {
                            consts::DRM_EVENT_VBLANK => Ok(Event::VBlank {
                                seq: ev.sequence,
                                tv: at,
                                user: ev.user_data }),
                            consts::DRM_EVENT_FLIP_COMPLETE => Ok(Event::PageFlip {
                                seq: ev.sequence,
                                tv: at,
                                user: ev.user_data }),
                            _ => unreachable!(),
                        }
                    }
                    _ => Ok(Event::Unknown),
                }
            }
        };
        self.fd.consume(nbytes);
        result
    }
/// Reads the next available event.
///
/// # Errors
///
/// * If no events are availble an error with kind
///   `ErrorKind::WouldBlock` is returned.
/// * If a syscall is interrupted `ErrorKind::Interrupted`
/// * If suprising data is returned `ErrorKind::InvalidData`.
/// * Any other `io:Error` from the kernel.
Reads the next available event.
Reads the next available event .
pub fn read_event(&mut self) -> io::Result<Event> {
        // This needs a good cleanup.
        let nbytes;
        let result = {
            let buf: &[u8] = try!(self.fd.fill_buf());
            if buf.len() == 0 {
                // I have a feeling this won't happen.
                // But if it does this is most sensible.
                return Err(io::Error::new(io::ErrorKind::WouldBlock, "No events available"));
            }
            assert!(buf.len() >= size_of::<ffi::event>(),
                    "Malformed event from drm device: {} < {}",
                    buf.len(), size_of::<ffi::event>());
            // Doing things the C way. There shouldn't be any byte-order issues.
            let ev_header: ffi::event = unsafe {
                *transmute::<_, *const ffi::event>(buf.as_ptr())
            };
            if buf.len() < ev_header.length as usize {
                nbytes = buf.len();
                Err(io::Error::new(ErrorKind::InvalidData, "Short DRM event"))
            } else {
                nbytes = ev_header.length as usize;
                match ev_header.type_ {
                    consts::DRM_EVENT_VBLANK | consts::DRM_EVENT_FLIP_COMPLETE => {
                        let ev: ffi::event_vblank = unsafe {
                            *transmute::<_, *const ffi::event_vblank>(buf.as_ptr())
                        };
                        // This is not good.  This works fine on linux
                        // for now, as Instant is stored as a timespec.
                        // But it may not be portable and it may break.
                        let at: Instant = unsafe {
                            transmute(libc::timespec { tv_sec: ev.tv_sec as i64,
                                                       tv_nsec: ev.tv_usec as i64 * 1000 })
                        };
                        match ev.base.type_ {
                            consts::DRM_EVENT_VBLANK => Ok(Event::VBlank {
                                seq: ev.sequence,
                                tv: at,
                                user: ev.user_data }),
                            consts::DRM_EVENT_FLIP_COMPLETE => Ok(Event::PageFlip {
                                seq: ev.sequence,
                                tv: at,
                                user: ev.user_data }),
                            _ => unreachable!(),
                        }
                    }
                    _ => Ok(Event::Unknown),
                }
            }
        };
        self.fd.consume(nbytes);
        result
    }
pub fn read_event ( & mut self ) -> io :: Result < Event > { // This needs a good cleanup. let nbytes ; let result = { let buf : & [ u8 ] = try ! ( self fd fill_buf ( ) ) ; if buf . len ( ) == 0 { // I have a feeling this won't happen. // But if it does this is most sensible. return Err ( io :: Error :: new ( io :: ErrorKind :: WouldBlock , " " ) ) ; } assert ! ( buf len ( ) size_of ffi event ( ) " " buf len ( ) size_of ffi event ( ) ) ; // Doing things the C way. There shouldn't be any byte-order issues. let ev_header : ffi :: event = unsafe { * transmute :: < _ , * const ffi :: event > ( buf . as_ptr ( ) ) } ; if buf . len ( ) < ev_header . length as usize { nbytes = buf . len ( ) ; Err ( io :: Error :: new ( ErrorKind :: InvalidData , " " ) ) } else { nbytes = ev_header . length as usize ; match ev_header . type_ { consts :: DRM_EVENT_VBLANK | consts :: DRM_EVENT_FLIP_COMPLETE => { let ev : ffi :: event_vblank = unsafe { * transmute :: < _ , * const ffi :: event_vblank > ( buf . as_ptr ( ) ) } ; // This is not good.  This works fine on linux // for now, as Instant is stored as a timespec. // But it may not be portable and it may break. let at : Instant = unsafe { transmute ( libc :: timespec { tv_sec : ev . tv_sec as i64 , tv_nsec : ev . tv_usec as i64 * 1000 } ) } ; match ev . base . type_ { consts :: DRM_EVENT_VBLANK => Ok ( Event :: VBlank { seq : ev . sequence , tv : at , user : ev . user_data } ) , consts :: DRM_EVENT_FLIP_COMPLETE => Ok ( Event :: PageFlip { seq : ev . sequence , tv : at , user : ev . user_data } ) , _ => unreachable ! ( ) , } } _ => Ok ( Event :: Unknown ) , } } } ; self . fd . consume ( nbytes ) ; result }
Reads the next available event.
Reads the next available event .
&mut self
errors
If no events are availble an error with kind
`ErrorKind::WouldBlock` is returned.
If a syscall is interrupted `ErrorKind::Interrupted`
If suprising data is returned `ErrorKind::InvalidData`.
Any other `io:Error` from the kernel.
If no events are availble an error with kind ` ErrorKind :: WouldBlock ` is returned . If a syscall is interrupted ` ErrorKind :: Interrupted ` If suprising data is returned ` ErrorKind :: InvalidData ` . Any other ` io : Error ` from the kernel .