Presentation is loading. Please wait.

Presentation is loading. Please wait.

Term Project Hints Topics Keep-alive CGI Multi-thread Multi-process Event-based.

Similar presentations


Presentation on theme: "Term Project Hints Topics Keep-alive CGI Multi-thread Multi-process Event-based."— Presentation transcript:

1 Term Project Hints Topics Keep-alive CGI Multi-thread Multi-process Event-based

2 – 2 – CGI CGI (common gateway interface) 프로그램 Web content 는 static 과 dynamic 으로 나뉨 Dynamic content 는 CGI 프로그램 / 스크립트에 의하여 지원 보통 입력에 따라 다른 결과를 출력함 출력은 stdout 으로 하게됨 PHP, PERL, JSP, ASP, Javascript, python 등 script 언어가 주로 사용 GET 방식 브라우져는 입력방식 으로 url query string 을 사용 예 ) http://a.com/adder?name=heejune&age=44 환경 반수 (QUERY_STRING) 을 통하여 전달 POST 방식 : 브라우저는 입력방식으로 stdin 을 사용

3 – 3 – Tiny 서버의 문제점 문제점 CGI 프로그램 자체에서 HTTP Response 헤더를 생성 Query String 이 일반적이지 못함 adder?1&2 vs adder?value=1&value2=2 Body 길이를 계산할 수 없음 (keep-alive 에 필수적 ) POST 지원 안됨문제해결 HTTP Response 헤더는 Tiny 서버에서 생성하도록 위치조정 Query string 입력 방식 수정 Body 계산을 위하여 직접 socket 에 출력하지 않고, pipe 를 통하여 데이터를 받은 후 buffer 에 저장하여 길이 확인 후 socket 으로 전달 POST 지원을 위한 pipe 기능 제공

4 – 4 – HTML form 일반적으로 CGI 기능은 HTML-Form 을 사용하여 제공됨 예<html><body><center> Adder CGI TEST value1: value1: value2: value2: </form></center></body></html>

5 – 5 – Linux pipe PIPE ( 빨대, 관 ) File 과 유사 Byte 단위 입출력 file descriptor 를 사용 File API 를 그대로 사용 : read, write etc ( 간단히 메모리상에 존재하는 파일로 생각하여도 됨 ) uni-directional (read or write 만 가능 ) One pipe end for write / the other pipe end for read programmer decides which process to read and which to write

6 – 6 – pipe API Create Pipe : int pipe(int fds[2]); #include 한쌍의 file-descriptor 세팅 : fd[0] = 입력용, fd[1] = 출력용 pipe fd 는 uni-directional. array element 0 ==> for input (like stdin, 0) array element 1 ==> for output (like stdout, 1) return : < 0 (error) 1 (success)Read-write Use the same read( )/write() call as others read() return 0 when no more writers (opened fd) = end of file write on close pipe generates “SIFPIPE” and return errno = EPIPE

7 – 7 – How to use in CGI Gateway (Tiny) CGI program (adder) to_cgi_fd[0] to_cgi_fd[1] from_cgi_fd[0] HTTP RESP BODY HTTP POST BODY


Download ppt "Term Project Hints Topics Keep-alive CGI Multi-thread Multi-process Event-based."

Similar presentations


Ads by Google