fasynctest.c
来自「盛博can驱动程序功能很全」· C语言 代码 · 共 42 行
C
42 行
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
int input_handler(void)
{
printf("message come!\n");
return 0;
}
int main(void)
{
int fd;
int result;
signal(SIGIO,&input_handler);
fd=open("/dev/can0",O_RDWR);
if (fd<0)
printf("open failed\n");
fcntl(fd,F_SETOWN,getpid());
fcntl(fd,F_SETFL, FASYNC|fcntl(fd,F_GETFL));
while (1) {
/*
here you can do your other job ,such as analyse the data ,send answer message
etc, especially for the process which need much time,you can process it while
no data come.if data came ,the input_handler will receive it in buf automatic
and needn't you wait the data comming.
*/
}
if (close(fd))
printf("close failed\n");
return 1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?