summaryrefslogtreecommitdiffstats
path: root/hw4/README.txt
blob: 22b63054fdeaedfbcd96e309abed7be20182edd8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 non­zero 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 中刪除。