EPOLL 이나 POLL에서 EVENT 검사할 때..뭐가 정확한건지
글쓴이: bsakiag / 작성시간: 수, 2011/04/06 - 5:53오후
안녕하세요..
항상 궁금해 하던 것이었는데.. 이참 에 질문합니다.
poll()이나 epoll()을 사용할 경우, POLLIN 또는 EPOLLIN 등을 검사합니다.
이때,
1.
if(POLLIN & events) {
} else if(POLLERR & events) {
} else if(POLLHUP & events) {
}
위처럼 하는게 맞는 건지, 아니면
2.
if(POLLIN & events) {
}
if(POLLERR & events) {
}
if(POLLHUP & events) {
}
위처럼 하는게 맞는건지 항상 궁금했습니다.
저는 2번이 맞다고 보여집니다만, 리눅스/유닉스 관련서적에는 1번처럼 많이 쓰더라구요.
대부분의 경우, 1이나 2나 동일한 결과일것 같긴한데.. 논리적인면에서 어느표현이 맞는 것일까요?
Forums:


이렇게도 쓰는군요
그건 아마도. 연결이 끊겼거나. 에러상황이라서 if문을 else로 넣은것 같습니다.
http://jeix2.blog.me/80015318021
http://emca.tistory.com/45
#include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <stropts.h> #include <poll.h> #include <unistd.h> #include <errno.h> #include <string.h> #define NORMAL_DATA 1 #define HIPRI_DATA 2 int poll_two_normal( int fd1 , int fd2) { struct pollfd poll_list[2]; int retval; poll_list[0].fd = fd1; poll_list[0].events = POLLIN | POLLPRI; poll_list[1].fd = fd2; poll_list[1].events = POLLIN | POLLPRI; while(1) { retval = poll(poll_list, (unsigned long) 2 , -1 ); /* Retval will always be greater than 0 or -1 in this case. Since we're doing it while blocking */ if(retval < 0) { fprintf(stderr,"Error while polling: %s\n",strerror(errno)); return -1; } if(((poll_list[0].revents&POLLHUP) == POLLHUP) || ((poll_list[0].revents&POLLERR) == POLLERR) || ((poll_list[0].revents&POLLNVAL) == POLLNVAL) || ((poll_list[1].revents&POLLHUP) == POLLHUP) || ((poll_list[1].revents&POLLERR) == POLLERR) || ((poll_list[1].revents&POLLNVAL) == POLLNVAL)) return 0; if((poll_list[0].revents&POLLIN) == POLLIN) handle(poll_list[0].fd,NORMAL_DATA); if((poll_list[0].revents&POLLPRI) == POLLPRI) handle(poll_list[0].fd,HIPRI_DATA); if((poll_list[1].revents&POLLIN) == POLLIN) handle(poll_list[1].fd,NORMAL_DATA); if((poll_list[1].revents&POLLPRI) == POLLPRI) handle(poll_list[1].fd,HIPRI_DATA); } }----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.
매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.
각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com
감사합니다.
제 생각이 틀리지 않았네요.. 감사합니다.
댓글 달기