Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

Changes between Initial Version and Version 1 of Developer/Mongoose_Web_Server


Ignore:
Timestamp:
01/02/16 00:07:04 (8 years ago)
Author:
Tan Gemicioglu
Comment:

Moved and fixed page from TBR/Delete

Legend:

Unmodified
Added
Removed
Modified
  • Developer/Mongoose_Web_Server

    v1 v1  
     1= Mongoose Web Server =
     2
     3
     4This page aims to help application developers integrate the [https://github.com/valenok/mongoose/ Mongoose] Web / HTTP server into their RTEMS applications. Only a reasonably basic configuration is treated.
     5
     6It is assumed that:
     7 *  the reader is using RTEMS 4.11 (the interface to Mongoose has changed significantly from 4.10), [wiki:TBR/UserManual/Quick_Start compiling it from source] and is comfortable doing so
     8 *  networking is already configured and working in the application
     9 *  a file-system (from which to serve web pages and write logs to) is already configured and working in the application
     10=  What is it?  =
     11
     12Mongoose is a lightweight web server, one of two (the other being the [wiki:TBR/UserManual/Simple_HTTPD Simple HTTPD] server) available in RTEMS.
     13=  Prerequisites  =
     14
     15RTEMS must have been configured (that is, with the GNU Configure tool), with the ''--enable-httpd'' and ''--enable-networking'' options. Because Mongoose uses the POSIX API, ''--disable-posix'' should ''not'' be specified.
     16=  Library  =
     17
     18The Mongoose library must be pulled in for linking. To do so, ensure that ''-lmghttpd'' is passed to the linker.
     19
     20If you're using a ''Makefile'' based on the provided [http://git.rtems.org/rtems/tree/make/Templates/Makefile.leaf template] - available for RTEMS 4.11 in its ''share/rtems4.11/make/Templates/Makefile.leaf'' path - this can be accomplished by adding ''-lmghttpd'' to ''LD_LIBS''; e.g.:
     21{{{
     22LD_LIBS+=-lmghttpd
     23}}}
     24=  CONFIGURE / confdefs.h  =
     25
     26Mongoose uses the POSIX API and its mutex and condition variable features and thus resources must be allocated for it in the application's configuration. For example, add the following before including ''confdefs.h'' (with ''CONFIGURE_INIT'' #defined):
     27{{{
     28#define CONFIGURE_MAXIMUM_POSIX_THREADS 10
     29#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 10
     30#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 10
     31}}}
     32=  Initializing Mongoose  =
     33
     34{{{
     35#include <mghttpd/mongoose.h
     36}}}
     37in the source file you'll initialize Mongoose from.
     38
     39''mg_start()'' is used to start Mongoose:
     40{{{
     41struct mg_context *mg_start(const struct mg_callbacks *callbacks, void *user_data, const char **options)
     42}}}
     43
     44For the basic configuration described here, ''NULL'' can be passed for the ''user_data'' parameter, but ''callback'' '''must''' be provided. To initialise a structure with no callbacks enabled, use:
     45  {{{
     46struct mg_callbacks callbacks = { NULL };
     47}}}
     48
     49The ''options'' parameter is a ''NULL''-terminated array of string pairs, each pair giving an option name and a value (see the Mongoose documentation for a [https://docs.cesanta.com/Options.shtml description of options]). By way of example, though, ''options'' might be defined as such:
     50   {{{
     51 const char *options[] = {
     52   "document_root",   "/usr/www",
     53   "listening_ports", "80",
     54   "num_threads",     "1",
     55   "thread_priority", "10",
     56   "access_log_file", "/var/log/httpd-access.log",
     57   "error_log_file",  "/var/log/httpd-error.log",
     58   NULL
     59 }
     60}}}
     61
     62Calling ''mg_start()'' (after networking and the file-system are initialized) will return a "context" upon success, ''NULL'' upon failure (sadly, at the time of writing, not necessarily with an indication of the nature of the failure - configuring an error log (as in the example ''options'' above) is recommended for troubleshooting failures).
     63
     64This context is used for further operating on that Mongoose instance (for example, in calling ''mg_stop()'' to halt it).
     65=  Done!  =
     66
     67Hopefully at this point, you've a working Mongoose server.
     68
     69Ensure there's a page for it to serve (e.g., ''/usr/www/index.html'') and test by browsing to ''!http://''<ip>''/'' (where ''<ip>'' is a resolvable name or IP address for your RTEMS target)!