mirror of
https://github.com/Hizenberg469/Driver-tutorial.git
synced 2026-04-20 00:42:25 +03:00
Character driver finished
This commit is contained in:
46
select_poll/poll1.c
Normal file
46
select_poll/poll1.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <poll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(){
|
||||
int fd1, fd2;
|
||||
struct pollfd pollarray[10];
|
||||
char buf[10];
|
||||
int n;
|
||||
|
||||
fd1 = open("./pone", O_RDWR);
|
||||
fd2 = open("./ptwo", O_RDWR);
|
||||
pollarray[0].fd = fd1;
|
||||
pollarray[1].fd = fd2;
|
||||
pollarray[0].events = POLLIN;
|
||||
pollarray[1].events = POLLIN;
|
||||
|
||||
n = poll(pollarray, 2, 10000);
|
||||
if(n < 0){
|
||||
perror("poll:");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//test whether fd1 is ready or not
|
||||
if( (pollarray[0].revents & POLLIN)){
|
||||
printf(" reading from fd1 (pone)\n");
|
||||
n = read(fd1, buf, 10);
|
||||
printf(" read data = %s from pone\n", buf);
|
||||
}
|
||||
|
||||
|
||||
//test whether fd2 is ready or not
|
||||
if( (pollarray[1].revents & POLLIN)){
|
||||
printf(" reading from fd2 (ptwo)\n");
|
||||
n = read(fd2, buf, 10);
|
||||
printf(" read data = %s from ptwo\n", buf);
|
||||
}
|
||||
|
||||
// close(fd1);
|
||||
// close(fd2);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user