linux中poll用法

来源:互联网 发布:如何求最大公约数 算法 编辑:程序博客网 时间:2024/05/01 10:00
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <poll.h>




/* thirddrvtest 
  */
int main(int argc, char **argv)
{
int fd;
   int ret; 
unsigned char key_val;
      
   struct pollfd *fds;

fd = open("/dev/buttons", O_RDWR);
if (fd < 0)
{
printf("can't open!\n");
}
   fds->fd = fd;
   fds->events =   POLLIN ;


    
while (1)

      ret = poll(fds, 1, 5000);
if(ret ==0)
      {printf("time out\n");
                   }
     else{
      read(fd, &key_val, 1);
printf("key_val = 0x%x\n", key_val);
                  }
}

return 0;
}
0 0