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
49232847
Commit
49232847
authored
Dec 16, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only hello example left, adopted to the new API
parent
673a2c58
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
56 deletions
+24
-56
Makefile
examples/Makefile
+8
-19
hello.c
examples/hello.c
+16
-37
No files found.
examples/Makefile
View file @
49232847
...
@@ -16,25 +16,14 @@ else
...
@@ -16,25 +16,14 @@ else
endif
endif
endif
endif
all
:
hello upload post websocket chat
all
:
$(CC)
hello.c ../mongoose.c
-o
hello
$(CFLAGS)
hello
:
$(CC)
hello.c ../mongoose.c
-o
$@
$(CFLAGS)
# $(CC) upload.c ../mongoose.c -o upload $(CFLAGS)
# $(CC) post.c ../mongoose.c -o post $(CFLAGS)
upload
:
# $(CC) -DUSE_WEBSOCKET websocket.c ../mongoose.c -o $@ $(CFLAGS)
$(CC)
upload.c ../mongoose.c
-o
$@
$(CFLAGS)
# $(CC) chat.c ../mongoose.c -o chat $(CFLAGS)
# $(CC) lua_dll.c ../build/lua_5.2.1.c -o $@.so $(CFLAGS) $(DLL_FLAGS)
post
:
$(CC)
post.c ../mongoose.c
-o
$@
$(CFLAGS)
websocket
:
$(CC)
-DUSE_WEBSOCKET
websocket.c ../mongoose.c
-o
$@
$(CFLAGS)
chat
:
$(CC)
chat.c ../mongoose.c
-o
$@
$(CFLAGS)
lua_dll
:
$(CC)
lua_dll.c ../build/lua_5.2.1.c
-o
$@
.so
$(CFLAGS)
$(DLL_FLAGS)
MSVC
=
../../vc6
MSVC
=
../../vc6
...
...
examples/hello.c
View file @
49232847
...
@@ -2,50 +2,29 @@
...
@@ -2,50 +2,29 @@
#include <string.h>
#include <string.h>
#include "mongoose.h"
#include "mongoose.h"
// This function will be called by mongoose on every new request.
// This function will be called by mongoose on every new request
static
int
event_handler
(
struct
mg_event
*
event
)
{
static
int
index_html
(
struct
mg_connection
*
conn
)
{
static
const
char
*
reply
=
"HTTP/1.0 200 OK
\r\n\r\n
Hello!"
;
if
(
event
->
type
==
MG_REQUEST_BEGIN
)
{
mg_write
(
conn
,
reply
,
strlen
(
reply
));
char
content
[
100
];
// Prepare the message we're going to send
int
content_length
=
snprintf
(
content
,
sizeof
(
content
),
"Hello from mongoose! Requested: [%s] [%s]"
,
event
->
request_info
->
request_method
,
event
->
request_info
->
uri
);
// Send HTTP reply to the client
mg_printf
(
event
->
conn
,
"HTTP/1.1 200 OK
\r\n
"
"Content-Type: text/plain
\r\n
"
"Content-Length: %d
\r\n
"
// Always set Content-Length
"
\r\n
"
"%s"
,
content_length
,
content
);
// Returning non-zero tells mongoose that our function has replied to
// the client, and mongoose should not send client any more data.
return
1
;
}
// We do not handle any other event
return
0
;
return
0
;
}
}
int
main
(
void
)
{
int
main
(
void
)
{
struct
mg_
context
*
ctx
;
struct
mg_
server
*
server
;
// List of options. Last element must be NULL.
// Create and configure the server
const
char
*
options
[]
=
{
"listening_ports"
,
"8080"
,
NULL
};
server
=
mg_create_server
(
NULL
);
mg_set_option
(
server
,
"listening_port"
,
"8080"
);
mg_add_uri_handler
(
server
,
"/"
,
index_html
);
// Start the web server.
// Serve request. Hit Ctrl-C to terminate the program
ctx
=
mg_start
(
options
,
&
event_handler
,
NULL
);
printf
(
"Starting on port %s
\n
"
,
mg_get_option
(
server
,
"listening_port"
));
for
(;;)
{
// Wait until user hits "enter". Server is running in separate thread.
mg_poll_server
(
server
,
1000
);
// Navigating to http://localhost:8080 will invoke begin_request_handler().
}
getchar
();
//
Stop the server.
//
Cleanup, and free server instance
mg_
stop
(
ctx
);
mg_
destroy_server
(
&
server
);
return
0
;
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