????д????Linux?豸?????е????????????I/0????ν???????????I/O??????????I/O????????????????????????????????????????????豸???????????????
???????????????
???????????????????????豸???????????????????????????????????????????????в??????????????????????? ?????????????????????????
?????????????????????????豸???????????????????????????????????????????????в?????????????ó?????????select?????ò??????????豸???????????????????????豸??????   poll??????С?
???????????????
????????????????????
????char buf;
????fd = open("/dev/ttyS1"??O_RDWR);
????.....
????res = read(fd??&buf??1);
????//???????????????????????????????????????
????if(res == 1)
????{
????printf("%c/n"??buf);
????}
?????????????????????
????char buf;
????fd = open("/dev/ttyS1"??O_RDWR|O_NONBLOCK);
????//O_NONBLOCK ?????????
????.....
????while(read(fd??&buf??1)!=1);
????//????????????????????????????
????printf("%c/n"??buf);
???????????????????????????????????????????????????????????????I/O?????????ò?????????select()??poll()?????ò????????豸???????????????select()??poll()??????????????豸?????е?poll()?????????á????????в????????????????????????????????
??????ò??select()??????
????int select(int numfds??fd_set *readfds??fd_set *writefds??fd_set *exceptionfds??
????struct timeval *timeout);  numfds ???????????????????????????1????select()????timeout????????????????????????????
??????ó??????
#inlcude------
main()
{
int fd??num;
char rd_ch[BUFFER_LEN];
fd_set rfds??wfds;
//??д???????????
//????????????/dev/globalfifo?豸???
fd=open("/dev/globalfifo"??O_RDWR|O_NONBLOCK);
if(fd != -1)
{
//FIFO ????
if(ioctl(fd??FIFO_CLEAR??0) < 0)
{
printf("ioctl cmd failed /n");
}
while(1)
{
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_SET(fd??&rfds);
FD_SET(fd??&wfds);
select(fd+1??&rfds??&wfds??null??null);
}
}
}
???????????豸?????е?poll()????????????????£?
????static unsigned int poll(struct file *file?? struct socket *sock??poll_table *wait)
????//???????????file??????????????????????????????????????y?????????
??????????????豸??????仯???????е???poll_wait()????????????????????????poll_table
?????????????????豸??????????????д?????????
???????????poll_wait()??????????????????wait_event()?????????????????????????????????????????????????????????????????????????????????wait????????????б?poll_table?????poll_wait()??????????£?
????static inline void poll_wait(struct file * filp?? wait_queue_head_t * wait_address?? poll_table *p)
???????п?????????????????wait_address????p???????????(poll_table)
?????????????е?poll()??????????????£?
static unsigned int xxx_poll(struct file *filp??struct socket *sock??
poll_table *wait)
{
unsigned int mask = 0;
struct xxx_dev *dev = filp-&gt;private_data;
//????豸???????
...
poll_wait(filp??&amp;dev-&gt;r_wait??wait);
//?????????????poll_table
poll_wait(filp??&amp;dev-&gt;w_wait??wait);
//??д??????????poll_table
...
if(...)
//???
mask |= POLLIN | POLLRDNORM;
if(...)
//??д
mask |= POLLOUT | POLLRDNORM;
...
return mask;
}<strong>????</strong>