Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
f7a705c4
Commit
f7a705c4
authored
Dec 26, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added multi-threaded example
parent
f5f6edcf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
Makefile
examples/Makefile
+2
-0
multi_threaded.c
examples/multi_threaded.c
+34
-0
No files found.
examples/Makefile
View file @
f7a705c4
...
...
@@ -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
...
...
examples/multi_threaded.c
0 → 100644
View file @
f7a705c4
#include <stdio.h>
#include "mongoose.h"
static
int
request_handler
(
struct
mg_connection
*
conn
)
{
mg_printf
(
conn
,
"HTTP/1.0 200 OK
\r\n
Content-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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment