가능은 한 것 같은데..
[링크 : https://stackoverflow.com/questions/15055065/o-rdwr-on-named-pipes-with-poll]
[링크 : https://man7.org/linux/man-pages/man3/mkfifo.3.html]
Macro: int ENXIO“No such device or address.” The system tried to use the device represented by a file you specified, and it couldn’t find the device. This can mean that the device file was installed incorrectly, or that the physical device is missing or not correctly attached to the computer. |
[링크 : https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html]
+
2022.10.27
POLLIN으로 탐지가 되는 듯?
$ cat rx.c //#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <linux/fcntl.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <errno.h> #include <sys/poll.h> #define FIFO_FILE "/tmp/fifo" #define BUFF_SIZE 1024*768*4 struct pollfd pfd[1]; int main(int argc, char** argv) { int ret = 0; int counter = 0; int fd; char buff[BUFF_SIZE]; // printf("argc[%d]\n",argc); if ( -1 == mkfifo( FIFO_FILE, 0666)){ perror( "mkfifo() 실행에러"); exit( 1); } if ( -1 == ( fd = open( FIFO_FILE, O_RDONLY|O_NONBLOCK))){ // <---- (A) perror( "open() 실행에러"); exit( 1); } ret = fcntl(fd, F_SETPIPE_SZ, 1024 * 1024); pfd[0].fd = fd; pfd[0].events = POLLIN; printf("fd[%d]ret[%d]\n",fd,ret); while( 1 ){ int n = poll(pfd, 1, 10); if (n > 0) { memset( buff, 0, BUFF_SIZE); ret = read( fd, buff, BUFF_SIZE); if(ret > 0 ) printf("ret[%d]\n",ret); // printf( "%d: %s\n", counter++, buff); } printf("."); usleep(10000); } close( fd); } |
$ cat tx.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <signal.h> #define FIFO_FILE "/tmp/fifo" int main_loop = 1; int write_loop = 1; void sigint_handler(int sig) { main_loop = 0; write_loop = 0; } void sigpipe_handler(int sig) { write_loop = 0; } int main(int argc, char **argv) { int fd; int fd_r; // char *str = "badayak.com"; char *str = NULL; char *temp = NULL; str = (char*)malloc(1024*768*4); temp = (char*)malloc(1024*768*4); memset(str, *argv[1], 1024*768*4); // signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, &sigpipe_handler); signal(SIGINT, &sigint_handler); /* printf("%d\n",__LINE__); if ( -1 == mkfifo( FIFO_FILE, 0666)){ perror( "mkfifo() 실행에러"); exit( 1); } */ while(main_loop) { printf("%d\n",__LINE__); do { fd = open( FIFO_FILE, O_WRONLY | O_NONBLOCK); usleep(100000); printf("fd[%d] %d\n",fd,__LINE__); if(main_loop == 0 && write_loop == 0) exit(1); } while(fd == -1); write_loop = 1; int ret = 0; while(write_loop) { printf("%d\n",__LINE__); int a = write( fd, str, atoi(argv[1])); printf("%d a[%d]\n",__LINE__,a); usleep(1000000); } } close( fd); } |
'Linux API > linux' 카테고리의 다른 글
pthread (0) | 2022.11.23 |
---|---|
iio(industrial io) 문서 (0) | 2022.11.11 |
‘F_SETPIPE_SZ’ undeclared (0) | 2022.10.20 |
linux fifo (0) | 2022.10.18 |
SIGPIPE (0) | 2022.10.17 |