Liemani

blog

홈으로

webserv study 5

April 22, 2022

2022-04-20

select

select가 readable이라고 판단하는 경우는

  1. 값을 읽을 수 있는 경우
  2. disconnect인 경우(poll도 마찬가지로 연결을 정상 종료한 client socket을 readable이라고 판단한다.)

https://yeosong1.github.io/webserv

2022-04-21

https://developer.ibm.com/articles/l-async/

Asynchronous blocking I/O

https://evan-moon.github.io/2019/09/19/sync-async-blocking-non-blocking/#동기-방식–논블록킹-방식

동기(Synchronous)는 정확히 무엇을 의미하는걸까?

asynchronous blocking I/O

https://homoefficio.github.io/2017/02/19/Blocking-NonBlocking-Synchronous-Asynchronous/

Blocking-NonBlocking-Synchronous-Asynchronous

  1. 동기 & 블록킹 I/O의 경우 직관적이나, 여러 개의 I/O를 동시에 처리할 수 없다.
  2. 논블록킹 I/O는 프로세스들의 작업을 컨트롤하는 것이 까다롭다. (대부분 이런 저레벨 프로그램은 C로 짠다. JS나 Python 같은 걸 생각하면 안된다.)
  3. 그렇다고 동기 & 블록킹 I/O와 멀티 프로세싱이나 쓰레딩을 결합해서 쓰자니 자원 문제도 있고 프로세스/쓰레드 간 통신이나 동기화가 빡셈
int main(configuration file)
	check validity of configuration file

https://nginx.org/en/docs/beginners_guide.html

Beginner’s Guide

directive =			simple-directive / block-directive
simple-directive =	name SPACES *parameter ";"
block-directive =	name SPACES *parameter "{" *instruction "}"
context =			name SPACES *parameter "{" *(instruction / directive) "}"
main {
	events {}
	http {}
}

http {
	server {}
}

server {
	location {}
}
location / {
	root /data/www;
}
server {
	location / {
		root /data/www;
	}

	location /images/ {
		root /data;
	}
}
server {
	listen 8080;
	root /data/upl;

	location / {
	}
}
server {
	location ~ .php$ {
		root /data
	}
}

configuration file 에러 상황 예시

server {
	listen 80 default_server;
	listen [::]:80 default_server;

	root /var/www/html;

	index index.html index.htm index.nginx-debian.html;

	server_name _;

	location / {
		try_files $uri $uri/ =404;
	}
}

server {
	listen 80 default_server;
	listen [::]:80 default_server;

	root /var/www/html;

	index index.html index.htm index.nginx-debian.html;

	server_name _;

	location / {
		try_files $uri $uri/ =404;
	}
}
root@2fef7e25b01f:/etc/nginx/sites-available# nginx -s reload
nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/default:74
root@2fef7e25b01f:/etc/nginx/sites-available# 
1. configuration file을 파싱해서 메모리에 구조화하여 저장한다.
	단순 문법적 오류에 대해 에러를 발생시킨다. ( ex: "{}"를 사용하기로 약속했다면 여는 괄호와 닫는 괄호가 짝이 맞는가? )
	일단 전부 string으로 값을 읽어온다.
2. 여러 방식으로 에러 check를 진행한다.
	1. directive가 올바른가? ( ex: 구현하지 않은 directive )
	2. directive의 인자가 올바른가? ( ex: checkListen(), checkIndex() )
		- directive에 따라 인자의 type, 인자의 범위, 인자의 갯수 등 확인
3. 파싱해온 값으로 server의 변수들을 설정한다.
for (fin >> string) {
	if (string is syntax error)
		handle error;
	else
		parser.add(string);
}

try {
	server.setWithParser(parser);
}
catch (server set error) {
	handle error;
}