πŸ“Œ  Tiny server Implementation

  • Tiny serverλŠ” 정적, 동적 μ½˜ν…μΈ λ₯Ό μ œκ³΅ν•˜λŠ” μž‘μ€ μ›Ήμ„œλ²„μ΄λ‹€.

  • TinyλŠ” GET λ©”μ†Œλ“œλ§Œ μ§€μ›ν•œλ‹€.

  • argc β‰ 2 λΌλŠ” μ˜λ―ΈλŠ” μ—°κ²°λœ ν¬νŠΈκ°€ μ—†λ‹€λŠ” 것을 μ˜λ―Έν•œλ‹€. argcλŠ” argv의 κ°œμˆ˜μ΄λ‹€.

  • 그럼 μ™œ 1개만 μžˆμ–΄λ„ λ˜λŠ”κ²Œ μ•„λ‹ˆλƒλΌκ³  생각할 수 μžˆλŠ”λ°, 자기 μžμ‹ μ„ κ°€λ¦¬ν‚€λŠ” μ£Όμ†Œκ°’μ΄ 있기 λ•Œλ¬Έμ— 자기 μžμ‹ μ„ ν¬ν•¨ν•˜κ³  2κ°œκ°€ μžˆμ–΄μ•Ό μ—°κ²°ν•  ν¬νŠΈκ°€ μžˆλ‹€λŠ” 것을 μ˜λ―Έν•œλ‹€.

  • open_listenfd λ₯Ό 톡해 server_socket의 listenκΉŒμ§€ 호좜된 listening socket이 μƒμ„±λœλ‹€.

  • connfdλŠ” μ—°κ²°μš© μ†ŒμΌ“μ΄λ‹€. clientλ‘œλΆ€ν„° (clientaddr) listenfdκ°€ μ—°κ²°μš”μ²­μ„ 받아듀일 λ•Œ ν•΄λ‹Ή μ†ŒμΌ“μ„ μƒμ„±ν•˜μ—¬ clientλ‘œλΆ€ν„° μ—°κ²°μš”μ²­μ„ 받아듀인닀.

πŸ“Œ Using Functions

void doit(int fd);
void read_requesthdrs(rio_t *rp);
int parse_uri(char *uri, char *filename, char *cgiargs);
void serve_static(int fd, char *filename, int filesize, char *method);
void get_filetype(char *filename, char *filetype);
void serve_dynamic(int fd, char *filename, char *cgiargs, char *method);
void clienterror(int fd, char *cause, char *errnum, char *shortmsg,
                 char *longmsg);

πŸ“Œ Concurrent Programming

  • ν•œ 개의 ν΄λΌμ΄μ–ΈνŠΈ μš”μ²­λ§Œ μ²˜λ¦¬ν•˜λŠ” μ„œλ²„λ₯Ό μ μ ˆν•˜μ§€ λͺ»ν•˜λ‹€.
  • λ‹€μˆ˜μ˜ λ„€νŠΈμ›Œν¬ ν΄λΌμ΄μ–ΈνŠΈμ—κ²Œ μ„œλΉ„μŠ€λ₯Ό μˆ˜ν–‰ν•˜κΈ° μœ„ν•΄μ„œλŠ” λ™μ‹œμ„± μ„œλ²„λ₯Ό μƒμ„±ν•˜μ—¬ ν΄λΌμ΄μ–ΈνŠΈμ—κ²Œ λ³„λ„μ˜ μ„œλΉ„μŠ€λ₯Ό μ œκ³΅ν•˜λŠ” 방식이 ν•„μš”ν•˜λ‹€.
  • κ΅¬ν˜„μ€ Threadλ₯Ό μ‚¬μš©ν•œ λ™μ‹œμ„± μ„œλ²„λ₯Ό κ΅¬ν˜„ν•˜μ˜€λ‹€.
  • μƒˆλ‘­κ²Œ μƒμ„±ν•œ ν”Όμ–΄μ“°λ ˆλ“œ tidκ°€ μ—°κ²°μ‹λ³„μž 포인터 *commfdpλ₯Ό μ—­μ°Έμ‘°ν•˜λŠ” 것 >> Pthread_create
  • μ“°λ ˆλ“œλ₯Ό λΆ„λ¦¬ν•˜λŠ” 이유 : λΆ„λ¦¬λœ μ“°λ ˆλ“œμ˜ νŠΉμ§• λ•Œλ¬Έ >>λ‹€λ₯Έ μ“°λ ˆλ“œμ— μ˜ν•΄ μ²­μ†Œλ˜κ±°λ‚˜ μ’…λ£Œλ˜μ§€ μ•Šκ³  ν•΄λ‹Ή μ“°λ ˆλ“œκ°€ μ’…λ£Œλ˜λ©΄ μžλ™μœΌλ‘œ λ©”λͺ¨λ¦¬ μžμ›μ„ λ°˜ν™˜
  • μ„œλ²„μ—μ„œ μ—°κ²° μš”μ²­μ„ μˆ˜μ‹ ν•  λ•Œλ§ˆλ‹€ μƒˆλ‘œμš΄ ν”Όμ–΄μ“°λ ˆλ“œκ°€ 생성될 수 μžˆλ‹€. μ΄λ•Œ 각각의 연결이 μ“°λ ˆλ“œ λ³„λ‘œ λ…λ¦½μ μœΌλ‘œ μ²˜λ¦¬λ˜λ―€λ‘œ 각각에 ν”Όμ–΄ μ“°λ ˆλ“œκ°€ μ’…λ£Œλ˜κΈ°λ₯Ό 기닀릴 ν•„μš”μ—†μ΄ μ’…λ£Œλ˜μžλ§ˆμž λ©”λͺ¨λ¦¬μžμ›μ„ λ°˜ν™˜ν•˜λŠ” 방식이 μ μ ˆν•˜λ‹€.

####################################################################

CS:APP Proxy Lab

Student Source Files

####################################################################

This directory contains the files you will need for the CS:APP Proxy Lab.

proxy.c csapp.h csapp.c These are starter files. csapp.c and csapp.h are described in your textbook.

You may make any changes you like to these files.  And you may
create and handin any additional files you like.

Please use `port-for-user.pl' or 'free-port.sh' to generate
unique ports for your proxy or tiny server. 

Makefile This is the makefile that builds the proxy program. Type "make" to build your solution, or "make clean" followed by "make" for a fresh build.

Type "make handin" to create the tarfile that you will be handing
in. You can modify it any way you like. Your instructor will use your
Makefile to build your proxy from source.

port-for-user.pl Generates a random port for a particular user usage: ./port-for-user.pl

free-port.sh Handy script that identifies an unused TCP port that you can use for your proxy or tiny. usage: ./free-port.sh

driver.sh The autograder for Basic, Concurrency, and Cache.
usage: ./driver.sh

nop-server.py helper for the autograder.

tiny Tiny Web server from the CS:APP text