Search
๐ŸŒ

webserv

Created
2022/05/18

1) Socket

Concept and Basic Webserv with C

Very good flow chart to understand webserv

TCP or UDP by socket option

fd_set, FD_SET, FD_ZERO, FD_ISSET

File Control by fcntl

fcntl์„ ์ด์šฉํ•œ ํŒŒ์ผ์ œ์–ด
2016-01-16 15:44:51 fcntl ์„ ์ด์šฉํ•œ ํŒŒ์ผ์ œ์–ด ์œ ๋‹‰์Šค์˜ ๋ชจ๋“ ๊ฒƒ์€ ํŒŒ์ผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค๋Š” ์‚ฌ์‹ค์€ ์•„๋งˆ๋„ ์ž˜์•Œ๊ณ  ์žˆ์„ ๊ฒƒ์ด๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ์œ ๋Šฅํ•œ? ์œ ๋‹‰์Šค ํ”„๋กœ๊ทธ๋ž˜๋จธ๋กœ ์„ฑ์žฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํŒŒ์ผ๊ด€๋ จ๋œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ž‘์—…๋“ค์„ ๋Šฅ์ˆ™ํ•˜๊ฒŒ ์ฒ˜๋ฆฌํ• ์ˆ˜ ์žˆ์–ด์•ผํ•œ๋‹ค. ์‹ค์ œ๋กœ ์œ ๋‹‰์Šค ํ”„๋กœ๊ทธ๋žจ์„ ํ•˜๊ฒŒ ๋˜๋ฉด ๊ฐ€์žฅ ๋งŽ์ด ํ•˜๋Š” ์ž‘์—…์ด ํŒŒ์ผ๊ณผ ์—ฐ๊ด€๋œ ์ž‘์—…์ด๋‹ค. ์ผ๋ฐ˜ ํŒŒ์ผ์€ ๋ฌผ๋ก ์ด๊ณ , ๋„คํŠธ์› ํ”„๋กœ๊ทธ๋ž˜๋ฐ์‹œ ์†Œ์ผ“์„ ๋‹ค๋ฃฐ๋•Œ, IPC, ๋””๋ฐ”์ด์Šค๋“ฑ์„ ๋‹ค๋ฃจ๋Š” ๋ชจ๋“  ๊ฒƒ์ด ๊ฒฐ๊ตญ์€ ํŒŒ์ผ์„ ๋‹ค๋ฃจ๋Š” ๊ฒƒ๋“ค์ด๋‹ค.

Socket Option

[๋„คํŠธ์›Œํฌ/์†Œ์ผ“ ํ”„๋กœ๊ทธ๋ž˜๋ฐ] setsockopt, getsockopt ์†Œ์ผ“์˜ต์…˜ ์ƒ์„ธ์„ค๋ช…, ์„ธ๋ถ€ ์˜ต์…˜ ์„ค์ •ํ•˜๊ธฐ, ์†Œ์ผ“ ๋ฒ„ํผ SO_SNDBUF & SO_KEEPALIVE
์˜ค๋Š˜์€ ์†Œ์ผ“ ์„ธ๋ถ€ ์„ค์ •ํ•˜๋Š” ํ•จ์ˆ˜์— ๋Œ€ํ•ด์„œ ํฌ์ŠคํŒ…์„ ํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ํ†ต์‹ ์ด ํ•˜๋‚˜์˜ ์„œ๋ฒ„์— ํ•˜๋‚˜์˜ ํด๋ผ์ด์–ธํŠธ๋งŒ์œผ๋กœ ์ด๋ค„์ง€๋Š” ๊ฑด ์•„๋‹ˆ์ฃ , ๋˜ ํ•˜๋‚˜์˜ ํŠธ๋žœ์ ์…˜๋งŒ ๋ฐœ์ƒํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์—, ๋„คํŠธ์›Œํฌ ํ™˜๊ฒฝ์„ ๋ชจ๋‘ ์˜ˆ์ธกํ•˜๊ธฐ๋Š” ํž˜๋“ค์–ด์š”. ์ƒ๊ฐ์ง€๋„ ๋ชปํ•œ ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ๋Š”! ๋ณดํ†ต ๊ธฐ๋ณธ์œผ๋กœ ๋‹ค ์„ค์ •์ด ๋˜์–ด์žˆ์œผ๋‹ˆ๊นŒ ์„ธ๋ถ€ ์„ค์ • ํ•  ์ผ์ด ์—†์„ ๊ฒƒ ๊ฐ™๊ฒ ์ง€๋งŒ, ์„ธ๋ถ€์„ค์ •์„ ํ•ด์ค˜์•ผ๋งŒ ํ•˜๋Š” ์ƒํ™ฉ์ด ๊ฝค ํ”ํ•˜๊ฒŒ ์˜จ๋‹ต๋‹ˆ๋‹ค.

Multiple client by socket

sockaddr vs sockaddr_storage

sockaddr vs sockaddr_in

setsockopt

[๋„คํŠธ์›Œํฌ/์†Œ์ผ“ ํ”„๋กœ๊ทธ๋ž˜๋ฐ] setsockopt, getsockopt ์†Œ์ผ“์˜ต์…˜ ์ƒ์„ธ์„ค๋ช…, ์„ธ๋ถ€ ์˜ต์…˜ ์„ค์ •ํ•˜๊ธฐ, ์†Œ์ผ“ ๋ฒ„ํผ SO_SNDBUF & SO_KEEPALIVE
์˜ค๋Š˜์€ ์†Œ์ผ“ ์„ธ๋ถ€ ์„ค์ •ํ•˜๋Š” ํ•จ์ˆ˜์— ๋Œ€ํ•ด์„œ ํฌ์ŠคํŒ…์„ ํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ํ†ต์‹ ์ด ํ•˜๋‚˜์˜ ์„œ๋ฒ„์— ํ•˜๋‚˜์˜ ํด๋ผ์ด์–ธํŠธ๋งŒ์œผ๋กœ ์ด๋ค„์ง€๋Š” ๊ฑด ์•„๋‹ˆ์ฃ , ๋˜ ํ•˜๋‚˜์˜ ํŠธ๋žœ์ ์…˜๋งŒ ๋ฐœ์ƒํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์—, ๋„คํŠธ์›Œํฌ ํ™˜๊ฒฝ์„ ๋ชจ๋‘ ์˜ˆ์ธกํ•˜๊ธฐ๋Š” ํž˜๋“ค์–ด์š”. ์ƒ๊ฐ์ง€๋„ ๋ชปํ•œ ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ๋Š”! ๋ณดํ†ต ๊ธฐ๋ณธ์œผ๋กœ ๋‹ค ์„ค์ •์ด ๋˜์–ด์žˆ์œผ๋‹ˆ๊นŒ ์„ธ๋ถ€ ์„ค์ • ํ•  ์ผ์ด ์—†์„ ๊ฒƒ ๊ฐ™๊ฒ ์ง€๋งŒ, ์„ธ๋ถ€์„ค์ •์„ ํ•ด์ค˜์•ผ๋งŒ ํ•˜๋Š” ์ƒํ™ฉ์ด ๊ฝค ํ”ํ•˜๊ฒŒ ์˜จ๋‹ต๋‹ˆ๋‹ค.

SO_REUSEADDR

2) I/O Multiplexing

select, poll, epoll, kqueue

ํ‚น์Šคํ‚ค kqueue ์‚ฌ์šฉ๋ฒ•!

poll

3) HTTP

RFC 7230 to RFC 7231

HTTP ๊ตฌ์กฐ

Separator for CRLF

Default Timeout (on Nginx and HTTP Packet)

The case that buffer size can be bigger than Content-Length

Trailer Format on the Last Chunked Transfer

Contents Negotiation

Accept-Charset

Accept-Language

CGI Example and Principles

CGI Response Header

CGI Env

4) Debugging

Mac OS X vscode Debugg Setting

5) Implementation

Invalid pthread_t

Safe nullptr

Main thread cannot catch exception of other thread

Logger by strftime function

Frequenst Mistakes about Overloading Selection on String Literal

Do not miss Destructor when it is a virtual thing

Thread & Mutex Wrapper for RAII

cpp-pthread
HerbertKoelman

Directory Checker

Localtime Multithreading

Map Iterator after Erase

inet_ntop

Regex on C

readdir Entry Order

new / delete vs malloc / free

Charset & Collation

6) Regarding Evaluation