我的程序应该模拟一个回复客户端请求的简单httpServer。它应该回答.html和.html.gz请求。我的问题是当我收到.gz请求时。目前execute_script正在处理该请求并解压缩该文件,但我无法将其发送回客户端。我的代码有什么问题?
void execute_script(int socket)
{
FILE *gp;
char temp[SIZE_BUF];
// Searchs for page in directory htdocs
sprintf(buf_tmp,"htdocs/%s",req_buf);
sprintf(temp, "gunzip -k %s", buf_tmp);
// Verifies if file exists
if((gp=popen(temp,"r"))==NULL) {
// Page not found, send error to client
printf("send_page: page %s not found, alerting client\n",buf_tmp);
}
else {
// Page found, send to client
while(fgets(buf_tmp,SIZE_BUF,gp)!=NULL)
send(socket,buf_tmp,strlen(buf_tmp),0);
// Close file
pclose(gp);
}
return;
}