假如TCP请求端发了1000个字符过来,然后服务端读了10个字符就回送消息,这样行不行?why?谢谢。
tinyhttpd代码里读取完http第一行后进入serve_file()函数,只有取消下面的注释才能浏览器才能正常访问页面,注释中的内容是在读取请求的其他部分。
void serve_file(int client, const char *filename)
{
FILE *resource = NULL;
int numchars = 1;
char buf[1024];
buf[0] = 'A'; buf[1] = '\0';//这个赋值不清楚是干什么的
//read whole header from client is must!!!if not,
/*
while ((numchars > 0) && strcmp("\n", buf)){ //将HTTP请求头读取并丢弃
numchars = get_line(client, buf, sizeof(buf));
printf("%s\n",buf);
}*/
//打开文件
resource = fopen(filename, "r");
if (resource == NULL)
//如果文件不存在,则返回not_found
not_found(client);
else
{
//添加HTTP头
headers(client, filename);
//并发送文件内容
cat(client, resource);
}
fclose(resource);//关闭文件句柄
}