1 / 14

실습 6 차 I/O Multiplexing

2008NP. 실습 6 차 I/O Multiplexing. MinKyu Han Multimedia Communications Laboratory Hankuk University of Foreign Studies. Blocking vs I/O Multiplexing Model. select(). 정의 : readset, writeset, exceptset 가 가리키는 descriptor 그룹을 보고 , 읽기 / 쓰기 / 예외 상황에 해당하는지 확인. #include <sys/select.h>

katy
Download Presentation

실습 6 차 I/O Multiplexing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2008NP 실습 6 차 I/O Multiplexing MinKyu Han Multimedia Communications Laboratory Hankuk University of Foreign Studies

  2. Blocking vs I/O Multiplexing Model

  3. select() • 정의 : readset, writeset, exceptset가 가리키는 descriptor 그룹을 보고, 읽기/쓰기/예외 상황에 해당하는지 확인 #include <sys/select.h> #include <sys/time.h> int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, const struct timeval *timeout); Returns: positive count of ready descriptors 0 on timeout, -1 on error struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ }

  4. select() • arguments • maxfdp1 : descriptor의 수를 지정 • readset : 읽기가 가능한지 확인해야 할 descriptor들을 정의 • writeset : 쓰기가 가능한지 확인해야 할 descriptor들을 정의 • exceptset : 예외 조건에 해당하는 descriptor들을 정의 • timeout • 계속 대기(NULL) • 정해진 시간만큼 대기(timeout에 정의된 값) • 대기하지 않음(0) int // unpv13e/lib/wrapsock.c Select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { int n; if ((n = select(nfds, readfds, writefds, exceptfds, timeout)) < 0) err_sys("select error"); return(n); /* can return 0 on timeout */ }

  5. select() • descriptor 관련 macro 함수 • 예제 void FD_ZERO(fd_set *fdset); // fdset의 모든 bit를 초기화 void FD_SET(int fd, fd_set *fdset); // fdset의 fd bit를 활성화 void FD_CLR(int fd, fd_set *fdset); // fdset의 fd bit를 비활성화 int FD_ISSET(int fd, fd_set *fdset); // fdset의 fd bit가 활성화 되었는가 ? fd_set rset, wset; FD_ZERO(&rest); // rset의 모든 bit를 초기화 FD_SET(sd, &wset); // sd bit를 활성화 FD_SET(0, &rset); // stdin bit를 비활성화 FD_ISSET(sd, &wset); // sd가 writable 한가 ? FD_ISSET(0, rset); // stdin이 readable 한가 ?

  6. 실습코드 분석 <참고 fd_set structure> Select()함수는 리턴하면서 fd_set structure의 bit값을 변경시키므로 이를 다시 설정해줘야 한다. 그 방안이 포인터를 사용하는 방식과 매번 리셋팅하는 방식이 있다.

  7. Makefile

  8. Make? • Make는 파일관리 유틸리티이다. • 프로젝트 컴파일 시간을 단축시켜준다. • 수정되지 않은 파일에 대한 반복 컴파일을 없애준다. • 프로그램의 종속 구조를 빠르게 파악할 수 있다. • Make는 소스를 컴파일 하는 것 이외에 순차적이고 반복적인 어떠한 작업에도 이용될 수 있다. • Make의 동작방식은 매우 단조롭다. • Makefile이라는 기술파일을 작성하면 make가 기술 파일에 적힌 대로 명령을 수행하게 되어 있다.

  9. Make의 기본동작 • diary.h, main.c, memo.ccalendar.c 의 종속구조 diary.h diary.h diary.h diary.h diary.h diary.h diary.h diary 실행파일

  10. Makefile 내용 • Makefile의 내용과 결과화면 사이 간격이 TAB <실행화면> 1. Makefile 내에서 제일 처음 오는 타겟을 찾는다. (all) 2. all 타겟을 만들기 위한 종속 타겟 diary를 보고 현재 디렉토리 내에 없다는 것을 확인 3. Diary를 생성하기 위한 첫번째 종속항목 memo.o가 아직 안만들어져 있음을 보고 memo.o를 생성하기 위한 룰을 찾은 후 memo.o를 만든다. ….(calendar.o,main.o 반복) 4. diary를 만든다. 5. all : diary를 검색하여 해당 디렉토리에 만들어졌음을 확인 후 종료

  11. Makefile의 기본구조 CC = gcc Target1 : dependency1 dependency2 command1 command2 Target2 : dependency3 … command3 command4 … 매크로 정의 룰1 명령어 룰2

  12. Makefile의 기본구조(Con’t) • 종속 항목이 없는 타겟도 사용 가능하다. • Clean : • rm[space]–rf[space]*.o[space]target1[space]target2 • 명령 부분에는 어떠한 명령어가 와도 상관 없다. • Target1 : dependency1 dependency2 • cp –f file1 file2 • gcc –o target1 dependency1 dependency2

  13. 매크로 작성 기본 규칙 • 기술 파일 내에 매크로는 C와 마찬가지로 사용자 저으이 변수에 특정한 문자열을 정의하고 표현하는 것을 의미한다 • 매크로의 정의는 ‘=‘를 포함하는 하나의 문장이다. • NAME = string • ‘#’은 주석문의 시작이다. • NAME = string #주석 • 매크로를 참조할 때는 소괄호나 중괄호로 둘러싸고 앞에 ‘$’를 붙인다. • NAME = string • ${NAME} • $(NAME) • 중복된 정의는 최후에 정의된 값을 사용한다. • NAME = stringA • NAMe = stringB • $(NAME) #stringB로 치환된다.

  14. 매크로를 사용한 Makefile수정 • 매크로를 사용하면 수정이 쉽다. + 자동매크로 $@ : 현재 타겟의 파일 부분 $^ : 현재 타겟의 종속 항목 리스트

More Related