91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

這是一個Linux的大作業實驗報告,里面包含了web服務器源碼和20頁的實驗報告。web服務器在Linux下以c語言實現,html作為頁面展示,實現了get和post方法。實驗報告包含了系統需求分析,系統設計,系統實現,系統測試等內容。

資源截圖

代碼片段和文件信息

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

/*
?==================================================
?********************函數聲明**********************
?==================================================
?*/
?
?/*
?*?讀取一行請求
?*?參數:套接字,保存數據的buffer,buffer大小
?*?返回值:請求長度
?*/
int?get_line(int?sock?char?*buf?int?size);

/*
?*?返回?200?OK
?*/?
void?response_200(int?client?const?char*?path);
?
?/*
?*?返回?400?BAD?REQUEST
?*/?
void?response_400(int?client);

/*
?*?返回?404?NOT?FOUND
?*/?
void?response_404(int?client);

/*
?*?返回?501?Method?Not?Implemented
?*/?
void?response_501(int?client);

/*
?*?向客戶端發送文件
?*?參數:客戶端套接口描述字,請求地址,標記1:GET??0:POST
?*/
void?response_file(int?client?const?char*?path?int?tag);

/*
?*?處理?get?的查詢參數,提取客戶端提交的數據,向客戶端發送結果
?*?參數:客戶端套接口描述字,請求地址,??后面的參數,以?&?隔開
?*/
?void?slove_get(int?client?const?char*?path?const?char*?query);
?
?/*
?*?處理?post?的查詢參數,提取客戶端提交的數據,向客戶端發送結果
?*?參數:客戶端套接口描述字,請求地址,請求報文主體長度
?*/
void?slove_post(int?client?const?char*?path?int?cont_len);

/*
?*?啟動服務器
?*?返回服務器套接口描述字
?*/
int?start(int?*port);

/*
?* 處理客戶端請求
?*/
void??accept_request(int?client);??

/*
?* 初始化為守護進程
?*/
void?init_daemon();

?/*
?==================================================
?********************主函數************************
?==================================================
?*/
?
?int?main(int?argc?char*?argv[])?{?
FILE?*fp;?
int?port?=?8080;
if((fp=fopen(“web.log““a“))? perror(“fopen?error!\n“);
fprintf(fp“httpd?running?on?port?%d.\n“?port);
??? init_daemon();?//初始化為守護進程
int?server_sockfd?=?start(&port);?
?????? puts(“開始運行“);
while?(1)?{
pthread_t?tid;?//用于聲明線程ID
struct?sockaddr_in?client_addr;
int?client_addrlen?=?sizeof(client_addr);
//接收客戶的連接請求
int?client_sockfd?=?accept(server_sockfd?
(struct?sockaddr*)&?client_addr
&client_addrlen);
if?(client_sockfd? perror(“accept?error!\n“);
break;
}
if?(pthread_create(&tid?NULL?accept_request?(void*)client_sockfd)?!=?0)
perror(“pthread_create?error\n“);
}
close(server_sockfd);??????????
????????fclose(fp);

return?0;
}
?
?
/*
?==================================================
?********************函數實現**********************
?==================================================
?*/
?
?
/*
?*?讀取一行請求
?*?參數:客戶端套接口描述字,保存數據的buffer,buffer大小
?*?返回值:請求長度
?*/
int?get_line(int?sock?char?*buf?int?size)?{
int?cnt?=?0;
char?c?=?‘\0‘;
int?n;
while?((cnt? n?=?read(sock?&c?1);?//讀一個字符放到c中
if?(n?>?0)?{
if?(c?==?‘\r‘)?{
//MSG_PEEK不會使套接字接收隊列中的數據減少
n?=?recv(sock?&c?1?MSG_PEEK);
if?((n?>?0)?&&?(c?==?‘\n‘))
read(sock?&c?1);
//實際上和上面MSG_PEEK是同一個字符
else
c?=?‘\n‘;
}
buf[cnt

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-02-10?11:28??web服務器\
?????文件?????1510599??2019-02-10?11:28??web服務器\web服務器文檔.docx
?????目錄???????????0??2019-02-10?11:27??web服務器\web項目源碼\
?????文件?????????816??2019-01-09?13:05??web服務器\web項目源碼\index.html
?????文件??????????78??2019-02-10?11:28??web服務器\web項目源碼\readme.txt
?????目錄???????????0??2019-01-16?12:01??web服務器\web項目源碼\resource\
?????文件???????25047??2019-01-09?12:29??web服務器\web項目源碼\resource\123.jpg
?????文件?????????285??2019-01-09?11:05??web服務器\web項目源碼\resource\GET.html
?????文件?????????297??2019-01-09?13:04??web服務器\web項目源碼\resource\pho.html
?????文件?????????286??2019-01-09?11:05??web服務器\web項目源碼\resource\POST.html
?????文件???????18872??2019-01-10?11:56??web服務器\web項目源碼\web
?????文件???????11070??2019-01-09?17:45??web服務器\web項目源碼\web.c
?????文件??????????56??2019-01-10?11:57??web服務器\web項目源碼\web.log

評論

共有 條評論