Linux/Linux

[Linux] Select 함수 (작성중)

i5 2022. 12. 1. 00:06
반응형

 

동기 IO 멀티플렉싱 함수

synchronous I/O multiplexing

 

       int select(int nfds, fd_set *restrict readfds,
                  fd_set *restrict writefds, fd_set *restrict exceptfds,
                  struct timeval *restrict timeout);

readfds

읽기 준비되었는 지를 보기 위해, 관찰하려는 파일 디스크립터들이다.

 

writefds

쓰기 준비되었는 지를 보기 위해, 관찰하려는 파일 디스크립터들이다.

 

exceptfds

예외 조건을 위해 관찰하려는 파일 디스크립터들이다.

 

 

timeout

timeout을 NULL로 설정할 경우,

select()함수는 block한다. 즉, select()함수는 준비상태가 되기 위해 파일 디스크립터를 무한정 기다린다.

 

보통 아래처럼 쓰임

		if (select(maxfdp1, &read_fds, NULL, NULL, NULL) < 0) {
			printf("select error <= 0 \n");
			exit(0);
		}

 

반응형