diff options
author | LAN-TW <lantw44@gmail.com> | 2014-01-15 07:56:34 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2014-01-15 07:56:34 +0800 |
commit | 146b8d868b96a647866d0f723f7b0d9d5d22ef45 (patch) | |
tree | 41e3521e3c86808b94dd98b32c358955977e4637 | |
parent | ad65674f7feeff0ecc59969e259677c60464a2ba (diff) | |
download | sp2013-146b8d868b96a647866d0f723f7b0d9d5d22ef45.tar.gz sp2013-146b8d868b96a647866d0f723f7b0d9d5d22ef45.tar.zst sp2013-146b8d868b96a647866d0f723f7b0d9d5d22ef45.zip |
HW4: 加入 submit 與 README.txt
-rw-r--r-- | hw4/Makefile.am | 13 | ||||
-rw-r--r-- | hw4/README.txt | 54 |
2 files changed, 66 insertions, 1 deletions
diff --git a/hw4/Makefile.am b/hw4/Makefile.am index d43b80d..d76675e 100644 --- a/hw4/Makefile.am +++ b/hw4/Makefile.am @@ -1,4 +1,4 @@ -EXTRA_DIST = cgiprog/kill_myself cgiprog/close_pipe +EXTRA_DIST = cgiprog/kill_myself cgiprog/close_pipe cgiprog/very_slow README.txt NULL = MY_V_LN = $(MY_V_LN_@AM_V@) @@ -61,3 +61,14 @@ all-local: $(abs_top_builddir)/info $(abs_top_builddir)/info: $(abs_top_builddir)/server_info $(MY_V_LN)ln -s server_info $(abs_top_builddir)/info CLEANFILES = info kill_myself close_pipe very_slow + +# Workaround for SP homwork +submit_tarball_name=SPHW4_b01902062.tar.gz +submit_dir_name=b01902062 + +submit: $(submit_tarball_name) +$(submit_tarball_name): $(PACKAGE)-$(VERSION).tar.gz + tar -zxf $(PACKAGE)-$(VERSION).tar.gz + mv $(PACKAGE)-$(VERSION) $(submit_dir_name) + tar -zcf $(submit_tarball_name) $(submit_dir_name) + rm -rf $(submit_dir_name) diff --git a/hw4/README.txt b/hw4/README.txt new file mode 100644 index 0000000..22b6305 --- /dev/null +++ b/hw4/README.txt @@ -0,0 +1,54 @@ + +Compile (Autotools) +------------------- +執行 ./configure --enable-restriction 產生 Makefile,並執行 make 來編譯。 +如果需要顯示編譯時執行的指令,可用 make V=1。輸入 make dist 可將作業打包成 +.tar.gz 檔案,但由於預設的檔名不符合作業要求,需要額外執行 make submit 才能 +將檔名轉換成作業要求的格式。 + +Run HTTP Server +--------------- +執行 ./cgish-httpd service logfile 即可執行。service 可以是 TCP port number, +或是系統服務資料庫(通常是 /etc/services)中找得到的服務名稱。 +以下列出可用於控制 server 行為的 signal: + SIGINT 或 SIGTERM 要求結束 server,此時 server 會停止接收新連線, + 並等待所有連線結束。 + SIGHUP 或 SIGUSR2 顯示連線與 server 狀態,並重新檢查設定值。 + SIGUSR1 顯示連線與 CGI 程式狀態。 + +Tasks +----- +1. I/O multiplexing + 使用 poll 決定要 accept 的 socket,accept 成功後交由新的 thread 執行。 +2. Multi-process + 每個 thread 都會自己管理自己的 CGI program 的 process。 +3. Show process info + 收到 SIGUSR1 時 main thread 會處理。 +4. Detect the limits on cgi_program / filename + 只要 ./configure 時有加上 --enable-restriction 就會偵測。 +5. Detect the CGI program which close the pipe before the server writes to it + 忽略 SIGPIPE,當 write 時 errno 為 EPIPE 即可得知。 +6. Detect the CGI program when it terminates abnormally + 使用 waitpid 與 WIFSIGNALED。 +7. Detect the CGI program when it exits with a nonzero exit code + CGI program 應自行處理。 + +其他 +---- +1. 可同時 listen 多個 socket。然而由於還沒完成對應的使用者界面,現在還無法 + 線上調整要 listen 的 socket 數量。 +2. 每個 socket 可以使用不同的記錄檔。同樣因為沒有對應的使用者界面,目前無法 + 使用此功能。 +3. HTTP server 當發現 CGI program 執行失敗是因為權限問題時,會嘗試將檔案視為 + 靜態檔案直接將檔案內容傳送給 client。 +4. HTTP server 會分析 CGI program 送回的資料,若缺少 HTTP status 或 + Content-Length 會幫忙補上。 +5. HTTP server 使用 QUERY_STRING 環境變數傳送資料給 CGI program。不過仍有許多 + 變數因作業時間關係,還沒有傳給 CGI program。 +6. 整個程式的運作方式: + (1) 最上層是個 linked list,列出所有的 socket 及其對應的紀錄檔。 + (2) 每個 socket 又各自都有一個 linked list 來記錄有哪些連線。 + (3) 接收新連線時,會在對應的 socket 的 linked list 加入一個新項目。 + 同時並產生 detached thread 來處理連線。 + (4) 連線結束時,detached thread 要自行清理所有傳入參數所佔用的資源, + 並將自己從對應的 socket 的 linked list 中刪除。 |