Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab has been updated. More info
here
and
there
.
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
f7a705c4
Commit
f7a705c4
authored
11 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
Added multi-threaded example
parent
f5f6edcf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/Makefile
+2
-0
2 additions, 0 deletions
examples/Makefile
examples/multi_threaded.c
+34
-0
34 additions, 0 deletions
examples/multi_threaded.c
with
36 additions
and
0 deletions
examples/Makefile
+
2
−
0
View file @
f7a705c4
...
@@ -20,6 +20,7 @@ all:
...
@@ -20,6 +20,7 @@ all:
$(
CC
)
hello.c ../mongoose.c
-o
hello
$(
CFLAGS
)
$(
CC
)
hello.c ../mongoose.c
-o
hello
$(
CFLAGS
)
$(
CC
)
qcomm.c ../mongoose.c
-o
qcomm
$(
CFLAGS
)
$(
CC
)
qcomm.c ../mongoose.c
-o
qcomm
$(
CFLAGS
)
$(
CC
)
post.c ../mongoose.c
-o
post
$(
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) upload.c ../mongoose.c -o upload $(CFLAGS)
# $(CC) -DUSE_WEBSOCKET websocket.c ../mongoose.c -o $@ $(CFLAGS)
# $(CC) -DUSE_WEBSOCKET websocket.c ../mongoose.c -o $@ $(CFLAGS)
...
@@ -36,6 +37,7 @@ LFLAGS = /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86
...
@@ -36,6 +37,7 @@ LFLAGS = /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86
windows
:
windows
:
$(
CL
)
hello.c ../mongoose.c
$(
CLFLAGS
)
$(
LFLAGS
)
$(
CL
)
hello.c ../mongoose.c
$(
CLFLAGS
)
$(
LFLAGS
)
$(
CL
)
post.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) upload.c ../mongoose.c $(CLFLAGS) $(LFLAGS)
# $(CL) /DUSE_WEBSOCKET websocket.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
#$(CL) lua_dll.c $(CLFLAGS) $(DLL_FLAGS) /DLL $(LFLAGS) /SUBSYSTEM:WINDOWS /ENTRY:luaopen_lua_dll /EXPORT:luaopen_lua_dll /out:lua_dll.dll
...
...
This diff is collapsed.
Click to expand it.
examples/multi_threaded.c
0 → 100644
+
34
−
0
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
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment