Commit f7a705c4 authored by Sergey Lyubka's avatar Sergey Lyubka

Added multi-threaded example

parent f5f6edcf
......@@ -20,6 +20,7 @@ all:
$(CC) hello.c ../mongoose.c -o hello $(CFLAGS)
$(CC) qcomm.c ../mongoose.c -o qcomm $(CFLAGS)
$(CC) post.c ../mongoose.c -o post $(CFLAGS)
$(CC) multi_threaded.c ../mongoose.c -o multi_threaded $(CFLAGS)
# $(CC) upload.c ../mongoose.c -o upload $(CFLAGS)
# $(CC) -DUSE_WEBSOCKET websocket.c ../mongoose.c -o $@ $(CFLAGS)
......@@ -36,6 +37,7 @@ LFLAGS = /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86
windows:
$(CL) hello.c ../mongoose.c $(CLFLAGS) $(LFLAGS)
$(CL) post.c ../mongoose.c $(CLFLAGS) $(LFLAGS)
$(CL) multi_threaded.c ../mongoose.c $(CLFLAGS) $(LFLAGS)
# $(CL) upload.c ../mongoose.c $(CLFLAGS) $(LFLAGS)
# $(CL) /DUSE_WEBSOCKET websocket.c ../mongoose.c $(CLFLAGS) $(LFLAGS)
#$(CL) lua_dll.c $(CLFLAGS) $(DLL_FLAGS) /DLL $(LFLAGS) /SUBSYSTEM:WINDOWS /ENTRY:luaopen_lua_dll /EXPORT:luaopen_lua_dll /out:lua_dll.dll
......
#include <stdio.h>
#include "mongoose.h"
static int request_handler(struct mg_connection *conn) {
mg_printf(conn, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\n"
"This is a reply from server instance # %s",
(char *) conn->server_param);
return 1;
}
static void *serve(void *server) {
for (;;) mg_poll_server((struct mg_server *) server, 1000);
return NULL;
}
int main(void) {
struct mg_server *server1, *server2;
server1 = mg_create_server("1");
server2 = mg_create_server("2");
mg_add_uri_handler(server1, "/", request_handler);
mg_add_uri_handler(server2, "/", request_handler);
// Make both server1 and server2 listen on the same socket
mg_set_option(server1, "listening_port", "8080");
mg_set_listening_socket(server2, mg_get_listening_socket(server1));
// server1 goes to separate thread, server 2 runs in main thread
mg_start_thread(serve, server1);
serve(server2);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment