mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-02 03:27:52 +08:00
Embed doc synced
This commit is contained in:
parent
253927008c
commit
51f0cc2b67
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
Embedding Mongoose is done in two steps:
|
Embedding Mongoose is done in two steps:
|
||||||
|
|
||||||
1. Download and copy two files:
|
1. Copy
|
||||||
[mongoose.c](https://raw.github.com/cesanta/mongoose/master/mongoose.c) and
|
[mongoose.c](https://raw.github.com/cesanta/mongoose/master/mongoose.c) and
|
||||||
[mongoose.h](https://raw.github.com/cesanta/mongoose/master/mongoose.h)
|
[mongoose.h](https://raw.github.com/cesanta/mongoose/master/mongoose.h)
|
||||||
to your application's source tree and include these two files in the build.
|
to your application's source tree and include them in the build.
|
||||||
2. Somewhere in the application code, call `mg_create_server()` to create
|
2. Somewhere in the application code, call `mg_create_server()` to create
|
||||||
a server, configure it with `mg_set_option()` and loop with
|
a server, configure it with `mg_set_option()` and loop with
|
||||||
`mg_poll_server()` until done. Call `mg_destroy_server()` to cleanup.
|
`mg_poll_server()` until done. Call `mg_destroy_server()` to cleanup.
|
||||||
@ -51,8 +51,8 @@ http://127.0.0.1:8080/hello will say hello, and here's the code:
|
|||||||
#include "mongoose.h"
|
#include "mongoose.h"
|
||||||
|
|
||||||
static int handle_hello(struct mg_connection *conn) {
|
static int handle_hello(struct mg_connection *conn) {
|
||||||
static const char *reply = "HTTP/1.0 200 OK\r\n\r\nHello world!\n";
|
static const char *reply = "Hello world!\n";
|
||||||
mg_write(conn, reply, strlen(reply));
|
mg_write_data(conn, reply, strlen(reply));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,11 +66,6 @@ http://127.0.0.1:8080/hello will say hello, and here's the code:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Note that URI handler must output valid HTTP response, which includes
|
|
||||||
the reply line with status code `HTTP/1.0 200 OK`, HTTP headers which are
|
|
||||||
empty in our example, and message body `Hello world!\n`. Note that reply
|
|
||||||
line is ended with `\r\n`, and HTTP headers are also ended with `\r\n`.
|
|
||||||
|
|
||||||
Below is the list of compilation flags that enable or disable certain
|
Below is the list of compilation flags that enable or disable certain
|
||||||
features. By default, some features are enabled, and could be disabled
|
features. By default, some features are enabled, and could be disabled
|
||||||
by setting appropriate `NO_*` flag. Features that are disabled by default
|
by setting appropriate `NO_*` flag. Features that are disabled by default
|
||||||
@ -95,5 +90,6 @@ a couple of kilobytes to the executable size, and also has some runtime penalty.
|
|||||||
Mongoose source code contains a well-commented example code, listed below:
|
Mongoose source code contains a well-commented example code, listed below:
|
||||||
|
|
||||||
* [hello.c](https://github.com/cesanta/mongoose/blob/master/examples/hello.c)
|
* [hello.c](https://github.com/cesanta/mongoose/blob/master/examples/hello.c)
|
||||||
shows how to handle form input, file upload, websocket communication, get
|
is a minimalisting hello world example
|
||||||
cookie values.
|
* [post.c](https://github.com/cesanta/mongoose/blob/master/examples/post.c)
|
||||||
|
shows how to handle form input
|
||||||
|
Loading…
x
Reference in New Issue
Block a user