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
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
b2b43ab0
Commit
b2b43ab0
authored
12 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
updated user manual
parent
1415d187
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
UserManual.md
+43
-5
43 additions, 5 deletions
UserManual.md
with
43 additions
and
5 deletions
UserManual.md
+
43
−
5
View file @
b2b43ab0
...
@@ -294,11 +294,49 @@ must be for a file name only, not including directory name. Example:
...
@@ -294,11 +294,49 @@ must be for a file name only, not including directory name. Example:
so updating the config file might be necessary after executable update.
so updating the config file might be necessary after executable update.
# Embedding
# Embedding
Embedding Mongoose is easy. Somewhere in the application code,
`mg_start()`
Embedding Mongoose is easy. Copy
function must be called. That starts the web server in a separate thread.
[
mongoose.c
](
https://github.com/valenok/mongoose/blob/master/mongoose.c
)
and
When it is not needed anymore,
`mg_stop()`
must be called. Application code
[
mongoose.h
](
https://github.com/valenok/mongoose/blob/master/mongoose.h
)
can pass configuration options to
`mg_start()`
, and also specify callback
to your application's source tree and include them in the build. For
functions that Mongoose should call at certain events.
example, your application's code lives in C++ file
`my_app.cpp`
, then on UNIX
this command embeds Mongoose:
$ ls
my_app.cpp mongoose.c mongoose.h
$ g++ my_app.cc mongoose.c -o my_app
Somewhere in the application code, call
`mg_start()`
to start the server.
Pass configuration options and event handlers to
`mg_start()`
.
Mongoose then calls handlers when certain events happen.
For example, when new request arrives, Mongoose calls
`begin_request`
handler function to let user handle the request. In the handler, user code
can get all information about the request -- parsed headers, etcetera.
Mongoose API is logically divided in three categories: server setup/shutdown
functions, functions to be used by user-written event handlers, and
convenience utility functions.
### Starting and stopping embedded web server
To start the embedded web server, call
`mg_start()`
. To stop it, call
`mg_stop()`
.
// This structure needs to be passed to mg_start(), to let mongoose know
// which callbacks to invoke. For detailed description, see
// https://github.com/valenok/mongoose/blob/master/UserManual.md
struct mg_callbacks {
int (*begin_request)(struct mg_connection *);
void (*end_request)(const struct mg_connection *, int reply_status_code);
int (*log_message)(const struct mg_connection *, const char *message);
int (*init_ssl)(void *ssl_context);
int (*websocket_connect)(const struct mg_connection *);
void (*websocket_ready)(struct mg_connection *);
int (*websocket_data)(struct mg_connection *);
const char * (*open_file)(const struct mg_connection *,
const char *path, size_t *data_len);
void (*init_lua)(struct mg_connection *, void *lua_context);
void (*upload)(struct mg_connection *, const char *file_name);
};
[
hello.c
](
https://github.com/valenok/mongoose/blob/master/examples/hello.c
)
[
hello.c
](
https://github.com/valenok/mongoose/blob/master/examples/hello.c
)
provides a minimalistic example.
provides a minimalistic example.
...
...
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