我正忙于在嵌入式平台上实现自己的 http 服务器。从技术上讲,服务器符合 HTTP 1.0,因此它希望客户端发送标头“Connection: Keep-Alive”以保持连接打开。
实现看起来像这样。我删除了解析 HTTP 标头并执行请求的代码,以使帖子尽可能简短:
int Service_Request(int conn) {
struct ReqInfo reqinfo;
volatile int resource = 0;
int retval = 0;
Req_Result req_result = GOT_REQ;
InitReqInfo(&reqinfo);
/* while we still have HTTP requests to process */
while (req_result == GOT_REQ)
{
/* Get HTTP request, there are 3 different return values:
* GOT_REQ: we got a valid HTTP request
* TIMEOUT_REQ we timed out waiting for a request
* ERROR_REQ there was some error receiving from …
Run Code Online (Sandbox Code Playgroud)