[중요] 프로그램 전체 흐름 #8
JuneParkCode
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
argument로 conf 파일이 들어왔을 경우
1-1. 잘못된 argc 일 경우 invalid argument 에러 반환 후 종료
Server Class instance 생성. 이 때 constructor의 인자로 conf 파일 경로를 넣는다.
2-1. 만약 conf 파일을 읽는데 오류가 발생할 경우 parse error 반환 후 종료
2-2. conf 파일을 읽고, 기본적으로 Server class가 가져야하는 요소들을 초기화함. 해당 요소가 없을 경우 Default 값을 부여.
server.run() 을 통해서 서버를 구동
server.run() 에서는 다음과 같은 작업을 수행한다.
server에 할당된 listen IP:PORT 로 정보를 수신하도록 socket을 만들고 해당 socket에 정보를 binding, listen 함
listen 하기 시작하는 socket fd에 대해서 fcntl()을 통해서 accept 작업을 non-blocking 작업으로 전환
server fd을 kqueue 에 등록
해당 fd에 이벤트가 감지되면 accept()를 실행
accept 가 실행되면 모든 I/O 작업에 대해서 non-blocking으로 kqueue 등록, response를 하도록 함.
accept 가 성공하고, read를 통해서 소켓에 들어온 정보를 읽는 것 까지 성공하면, 해당 정보를 HTTP Parser 를 통해서 정보를 얻어 HTTP Request Class instance를 반환받음
Request 가 정상적이라면, 이에 맞춰서 Response를 작성함. 이를 위한 Class 작성이 필요
Response가 완성되면, send()를 마찬가지로 수행하고 Request에 대한 작업을 완수함.
8~12 번의 작업은 하나의 while loop에서 작동하고 있음. non-blocking이기 때문에 I/O 작업의 경우 event가 왔을 때 callback으로 실행되도록 함.
#TODO
--
우선 일련의 과정은 이렇게 생각하고 있고, 추가로 작업을 하면서 필요하다고 생각하는 부분을 답글로 자유롭게 남겨주세요.
Beta Was this translation helpful? Give feedback.
All reactions