42Seoul C++98 ๊ธฐ๋ฐ IRC ์๋ฒ ๊ตฌํ
ft_irc๋ IRC(Internet Relay Chat) ํ๋กํ ์ฝ์ ์ง์ ๊ตฌํํ๋ ํ๋ก์ ํธ์
๋๋ค.| ํญ๋ชฉ | ๋ด์ฉ |
|---|---|
| ๊ธฐ๊ฐ | 2024.10 ~ 2024.11 |
| ์คํ | C++98 TCP Socket poll() Makefile Docker Python |
| ํ | 3์ธ (Server 1 ยท Cmd 2) |
| ๋ด๋น | Server / Infra |
poll() ๊ธฐ๋ฐ non-blocking IRC ์๋ฒ ์ด๋ฒคํธ ๋ฃจํ ๊ตฌํ ๋ฐ ๋ฆฌํฉํ ๋งPASS, NICK, USER ๋ช
๋ น์ ํตํด IRC ํด๋ผ์ด์ธํธ ๋ฑ๋ก ์ํ ๊ด๋ฆฌJOIN, PART, PRIVMSG ๊ธฐ๋ฐ ์ฑ๋ ์
์ฅ, ํด์ฅ, ๋ธ๋ก๋์บ์คํธ ์ฒ๋ฆฌKICK, INVITE, TOPIC, MODE ๋ช
๋ น์ผ๋ก ์ฑ๋ ์ด์ ๊ถํ ์ ์ด+i, +t, +k, +o, +l ๋ชจ๋ ์ง์
ircserv๋ ๋จ์ผ ์ค๋ ๋ ์ด๋ฒคํธ ๋ฃจํ ๊ตฌ์กฐpoll() ๋ฃจํ์์ ๊ฐ์Cmd ๊ณ์ธต์ผ๋ก dispatchClient, Channel, nickname map์ ์ค์ฌ์ผ๋ก ๋ฉ๋ชจ๋ฆฌ์์ ๊ด๋ฆฌ| Layer | Responsibility |
|---|---|
| I/O | ํด๋ผ์ด์ธํธ ์ ์ ์๋ฝ, non-blocking read/write, send buffer ๊ด๋ฆฌ |
| Protocol | IRC ๋ฉ์์ง ํ์ฑ, ๋ช ๋ น์ด dispatch, numeric reply ์์ฑ |
| State | ํด๋ผ์ด์ธํธ, ์ฑ๋, ๋๋ค์ ์ธ๋ฑ์ค, ์ฑ๋ ๋ชจ๋ ๊ด๋ฆฌ |
| Test | Python socket ๊ธฐ๋ฐ ํตํฉ ํ ์คํธ๋ก ํ๊ท ๊ฒ์ฆ |
broadcastMsg()๊ฐ _clients ๋๋ channel map์ ์ํํ๋ ์ค castMsg()๋ฅผ ํธ์ถEPIPE, ECONNRESET, ENOTCONN ๋ฑ์ด ๋ฐ์ํ๋ฉด, ๊ธฐ์กด ๊ตฌ์กฐ์์๋ ์ํ ์ค์ธ map์์ client๋ฅผ ์ฆ์ erase/deleteํ ์ ์์์QUIT, ping timeout, write error, POLLERR/POLLHUP, broadcast ์คํจ ๋ฑ ํด๋ผ์ด์ธํธ ์ญ์ ๊ฒฝ๋ก๊ฐ ์ฌ๋ฌ ๊ณณ์ ๋ถ์ฐ๋จmarkClientForRemoval()์ด๋ผ๋ ์ด๋ฆ๊ณผ ๋ฌ๋ฆฌ ์ค์ ๋ก๋ ์ฆ์ teardown๊น์ง ์ํํ๋ ๊ฒฝ๋ก๊ฐ ์์ด, ๋งํน๊ณผ ์ญ์ ์ ์ฑ
์์ด ์์ฌ ์์์std::set<int> _toRemove๋ฅผ ๋์
ํด ๋ชจ๋ ์ญ์ ๊ฒฝ๋ก๊ฐ client๋ฅผ ์ฆ์ ์ญ์ ํ์ง ์๊ณ fd๋ง ํ์ํ๋๋ก ๋ณ๊ฒฝmarkClientForRemoval(fd)๋ ๋งํน ์ ์ฉ, removeClientFromServer(client)๋ ์ค์ teardown ์ ์ฉ์ผ๋ก ์ญํ ๋ถ๋ฆฌcleanupMarkedClients()์์ poll loop ์ํ๊ฐ ๋๋ ๋ค ํ ๋ฒ๋ง ์ํ_clients erase, delete client, _fds ์์ถ์ ๋จ์ผ cleanup ์ง์ ์ผ๋ก ํตํฉacceptClient()์ revents = 0 ์ด๊ธฐํ, POLLERR/POLLHUP/POLLNVAL ๋ถ๊ธฐ๋ ํจ๊ป ์ถ๊ฐmake re, make test ํต๊ณผtest/run_all.py๋ฅผ ์ถ๊ฐํด test/test_*.py ํ์ผ์ ์๋ ์์งํ๊ณ ์์ฐจ ์คํmake test์์ ์๋ฒ ์คํ ํ Python ํตํฉ ํ
์คํธ๋ฅผ ์ํํ๋๋ก ๊ตฌ์ฑmake asan ํ๊น ์ถ๊ฐMODE +o/-o, NICK, KICK ํ๋ฆmake test 4/4 ํต๊ณผ