-
大小: 221KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-06-11
- 语言: 其他
- 标签: mongoose multithread httpserver
资源简介
1、基于mongoose 6.7实现的http server
2、支持多线程(本项目使用vs2008编译)
3、附带mongoose6.7版本源代码,6.7以上的版本,多线程实现方式与现在不一样)
2、支持多线程(本项目使用vs2008编译)
3、附带mongoose6.7版本源代码,6.7以上的版本,多线程实现方式与现在不一样)
代码片段和文件信息
// httpserver_multithread.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
#include “mongoose-6.7/mongoose.h“
static const char *s_http_port = “7879“;
static void ev_handler(struct mg_connection *c int ev void *p) {
if (ev == MG_EV_HTTP_REQUEST) {
struct http_message *hm = (struct http_message *) p;
char reply[100];
/* Simulate long calculation */
//sleep(3);
/* Send the reply */
snprintf(reply sizeof(reply) “{ \“uri\“: \“%.*s\“ }\n“ (int) hm->uri.len hm->uri.p);
mg_printf(c “HTTP/1.1 200 OK\r\n“
“Content-Type: application/json\r\n“
“Content-Length: %d\r\n“
“\r\n“
“%s“
(int) strlen(reply) reply);
}
}
int main(void) {
struct mg_mgr mgr;
mg_mgr_init(&mgr NULL);
struct mg_connection *nc = mg_bind(&mgr s_http_port ev_handler);
mg_set_protocol_http_websocket(nc);
/* For each new connection execute ev_handler in a separate thread */
mg_enable_multithreading(nc);
printf(“starting multi-threaded server on port %s\n“ s_http_port);
for (;;) {
mg_mgr_poll(&mgr 500);
}
mg_mgr_free(&mgr);
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-02-14 15:05 httpserver_multithread\
目录 0 2019-02-14 15:05 httpserver_multithread\Debug\
文件 202752 2019-02-14 15:04 httpserver_multithread\Debug\httpserver_multithread.exe
目录 0 2019-02-14 15:05 httpserver_multithread\httpserver_multithread\
文件 932 2019-02-14 15:02 httpserver_multithread\httpserver_multithread.sln
文件 8704 2019-02-14 15:04 httpserver_multithread\httpserver_multithread.suo
文件 1092 2019-02-14 15:04 httpserver_multithread\httpserver_multithread\httpserver_multithread.cpp
文件 4413 2019-02-14 15:02 httpserver_multithread\httpserver_multithread\httpserver_multithread.vcproj
目录 0 2019-02-14 15:02 httpserver_multithread\httpserver_multithread\mongoose-6.7\
文件 451883 2019-02-14 14:23 httpserver_multithread\httpserver_multithread\mongoose-6.7\mongoose.cpp
文件 171997 2017-01-17 17:08 httpserver_multithread\httpserver_multithread\mongoose-6.7\mongoose.h
文件 1273 2019-02-14 15:02 httpserver_multithread\httpserver_multithread\ReadMe.txt
文件 227 2019-02-14 15:02 httpserver_multithread\httpserver_multithread\stdafx.cpp
文件 233 2019-02-14 15:02 httpserver_multithread\httpserver_multithread\stdafx.h
文件 498 2019-02-14 15:02 httpserver_multithread\httpserver_multithread\targetver.h
评论
共有 条评论