select() 함수 관련 질문 합니다.

vilinux의 이미지

int res, max_fd;

FD_SET(fd_sock, &readfds);
max_fd = fd_sock + 1;

res = select( max_fd, &readfds, NULL, NULL, &tv );

이렇게 있다면 도대체 fd_sock 에다가 +1을 왜 하나요 ??
이해가 안가네요~
그리고 하나만 기달리는게 아니고 fd_test해서 두개를 셀렉한다면
fd_test 에도 +1을 또해줘야하는지? 궁금합니다!

아직 초짜라서뤼.......많은 답변좀.

luscent의 이미지

새로 인지하게 될 소켓은 당연히

현재 가지고 있는 sockfd에 +1을 하게 되는 것이죠.

그래야 새로운 file descriptor에 대해 kernel이 알고 관리할 수 있죠..

unp v1을 잘 보세요.

(번역서라면 164페이지에 있네요.. )

fdset은 단순한 SET(집합)이라고 보시면 되구요.

select함수니까 당연히 기본 제한인 FD_MAXSET인 1024에 걸릴테니.

서지훈의 이미지

man select

Quote:

DESCRIPTION
The select() system call examines the I/O descriptor sets whose addresses
are passed in readfds, writefds, and exceptfds to see if some of their
descriptors are ready for reading, are ready for writing, or have an
exceptional condition pending, respectively. The only exceptional condi-
tion detectable is out-of-band data received on a socket. The first nfds
descriptors are checked in each set; i.e., the descriptors from 0 through
nfds-1 in the descriptor sets are examined.
On return, select() replaces
the given descriptor sets with subsets consisting of those descriptors
that are ready for the requested operation. The select() system call
returns the total number of ready descriptors in all the sets.

...

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

bugiii의 이미지

아마 select 구현중에 루프 카운터 비교를 <= 이 아닌 < 로 비교해서 그런 것 아닐까 합니다만... (찾아보니 프비는 그렇군요.)