Commit 6a3d01ee authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Cesanta Bot

Depend on v7.c properly

PUBLISHED_FROM=cf49d0d345e4a7607c535f9578b8ed4160f2fccd
parent 27986213
...@@ -6,8 +6,8 @@ signature: | ...@@ -6,8 +6,8 @@ signature: |
struct mg_connection *mg_add_sock(struct mg_mgr *, sock_t, mg_event_handler_t); struct mg_connection *mg_add_sock(struct mg_mgr *, sock_t, mg_event_handler_t);
--- ---
Creates a connection, associates it with the given socket and event handler Create a connection, associate it with the given socket and event handler,
and adds it to the manager. and add it to the manager.
For more options see the `mg_add_sock_opt` variant. For more options see the `mg_add_sock_opt` variant.
...@@ -8,8 +8,8 @@ signature: | ...@@ -8,8 +8,8 @@ signature: |
struct mg_add_sock_opts); struct mg_add_sock_opts);
--- ---
Creates a connection, associates it with the given socket and event handler Create a connection, associate it with the given socket and event handler,
and adds to the manager. and add to the manager.
See the `mg_add_sock_opts` structure for a description of the options. See the `mg_add_sock_opts` structure for a description of the options.
...@@ -7,7 +7,7 @@ signature: | ...@@ -7,7 +7,7 @@ signature: |
mg_event_handler_t); mg_event_handler_t);
--- ---
Creates a listening connection. Create listening connection.
See `mg_bind_opt` for full documentation. See `mg_bind_opt` for full documentation.
...@@ -8,19 +8,19 @@ signature: | ...@@ -8,19 +8,19 @@ signature: |
struct mg_bind_opts opts); struct mg_bind_opts opts);
--- ---
Creates a listening connection. Create listening connection.
The `address` parameter specifies which address to bind to. It's format is the same `address` parameter tells which address to bind to. It's format is the same
as for the `mg_connect()` call, where `HOST` part is optional. `address` as for the `mg_connect()` call, where `HOST` part is optional. `address`
can just be a port number, e.g. `:8000`. To bind to a specific interface, can be just a port number, e.g. `:8000`. To bind to a specific interface,
an IP address can be specified, e.g. `1.2.3.4:8000`. By default, a TCP an IP address can be specified, e.g. `1.2.3.4:8000`. By default, a TCP
connection is created. To create a UDP connection, prepend a `udp://` prefix, connection is created. To create UDP connection, prepend `udp://` prefix,
e.g. `udp://:8000`. To summarise, the `address` paramer has following format: e.g. `udp://:8000`. To summarize, `address` paramer has following format:
`[PROTO://][IP_ADDRESS]:PORT`, where `PROTO` could be `tcp` or `udp`. `[PROTO://][IP_ADDRESS]:PORT`, where `PROTO` could be `tcp` or `udp`.
See the `mg_bind_opts` structure for a description of the optional See the `mg_bind_opts` structure for a description of the optional
parameters. parameters.
Returns a new listening connection or `NULL` on error. Return a new listening connection, or `NULL` on error.
NOTE: The connection remains owned by the manager, do not free(). NOTE: Connection remains owned by the manager, do not free().
...@@ -6,14 +6,14 @@ signature: | ...@@ -6,14 +6,14 @@ signature: |
void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t); void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t);
--- ---
Passes a message of a given length to all connections. Pass a message of a given length to all connections.
Must be called from a thread that does NOT call `mg_mgr_poll()`. Must be called from a thread that does NOT call `mg_mgr_poll()`.
Note that `mg_broadcast()` is the only function Note that `mg_broadcast()` is the only function
that can be, and must be, called from a different (non-IO) thread. that can be, and must be, called from a different (non-IO) thread.
`func` callback function will be called by the IO thread for each `func` callback function will be called by the IO thread for each
connection. When called, the event will be `MG_EV_POLL`, and a message will connection. When called, event would be `MG_EV_POLL`, and message will
be passed as the `ev_data` pointer. Maximum message size is capped be passed as `ev_data` pointer. Maximum message size is capped
by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes. by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes.
...@@ -6,22 +6,22 @@ signature: | ...@@ -6,22 +6,22 @@ signature: |
int mg_check_ip_acl(const char *acl, uint32_t remote_ip); int mg_check_ip_acl(const char *acl, uint32_t remote_ip);
--- ---
Verifies given IP address against the ACL. Verify given IP address against the ACL.
`remote_ip` - an IPv4 address to check, in host byte order `remote_ip` - an IPv4 address to check, in host byte order
`acl` - a comma separated list of IP subnets: `x.x.x.x/x` or `x.x.x.x`. `acl` - a comma separated list of IP subnets: `x.x.x.x/x` or `x.x.x.x`.
Each subnet is Each subnet is
prepended by either a - or a + sign. A plus sign means allow, where a prepended by either a - or a + sign. A plus sign means allow, where a
minus sign means deny. If a subnet mask is omitted, such as `-1.2.3.4`, minus sign means deny. If a subnet mask is omitted, such as `-1.2.3.4`,
it means that only that single IP address is denied. this means to deny only that single IP address.
Subnet masks may vary from 0 to 32, inclusive. The default setting Subnet masks may vary from 0 to 32, inclusive. The default setting
is to allow all access. On each request the full list is traversed, is to allow all accesses. On each request the full list is traversed,
and the last match wins. Example: and the last match wins. Example:
`-0.0.0.0/0,+192.168/16` - deny all acccesses, only allow 192.168/16 subnet `-0.0.0.0/0,+192.168/16` - deny all acccesses, only allow 192.168/16 subnet
To learn more about subnet masks, see this To learn more about subnet masks, see the
link:https://en.wikipedia.org/wiki/Subnetwork[Wikipedia page on Subnetwork]. link:https://en.wikipedia.org/wiki/Subnetwork[Wikipedia page on Subnetwork]
Returns -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed. Return -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed.
...@@ -7,7 +7,7 @@ signature: | ...@@ -7,7 +7,7 @@ signature: |
mg_event_handler_t handler); mg_event_handler_t handler);
--- ---
Connects to a remote host. Connect to a remote host.
See `mg_connect_opt()` for full documentation. See `mg_connect_opt()` for full documentation.
...@@ -8,11 +8,11 @@ signature: | ...@@ -8,11 +8,11 @@ signature: |
struct mg_connect_opts opts); struct mg_connect_opts opts);
--- ---
Connects to a remote host. Connect to a remote host.
The `address` format is `[PROTO://]HOST:PORT`. `PROTO` could be `tcp` or `udp`. `address` format is `[PROTO://]HOST:PORT`. `PROTO` could be `tcp` or `udp`.
`HOST` could be an IP address, `HOST` could be an IP address,
IPv6 address (if Mongoose is compiled with `-DMG_ENABLE_IPV6`) or a host IPv6 address (if Mongoose is compiled with `-DMG_ENABLE_IPV6`), or a host
name. If `HOST` is a name, Mongoose will resolve it asynchronously. Examples name. If `HOST` is a name, Mongoose will resolve it asynchronously. Examples
of valid addresses: `google.com:80`, `udp://1.2.3.4:53`, `10.0.0.1:443`, of valid addresses: `google.com:80`, `udp://1.2.3.4:53`, `10.0.0.1:443`,
`[::1]:80` `[::1]:80`
...@@ -20,18 +20,18 @@ of valid addresses: `google.com:80`, `udp://1.2.3.4:53`, `10.0.0.1:443`, ...@@ -20,18 +20,18 @@ of valid addresses: `google.com:80`, `udp://1.2.3.4:53`, `10.0.0.1:443`,
See the `mg_connect_opts` structure for a description of the optional See the `mg_connect_opts` structure for a description of the optional
parameters. parameters.
Returns a new outbound connection or `NULL` on error. Returns a new outbound connection, or `NULL` on error.
NOTE: The connection remains owned by the manager, do not free(). NOTE: Connection remains owned by the manager, do not free().
NOTE: To enable IPv6 addresses `-DMG_ENABLE_IPV6` should be specified NOTE: To enable IPv6 addresses, `-DMG_ENABLE_IPV6` should be specified
in the compilation flags. in the compilation flags.
NOTE: The new connection will receive `MG_EV_CONNECT` as its first event NOTE: New connection will receive `MG_EV_CONNECT` as it's first event
which will report the connect success status. which will report connect success status.
If the asynchronous resolution fails or the `connect()` syscall fails for whatever If asynchronous resolution fail, or `connect()` syscall fail for whatever
reason (e.g. with `ECONNREFUSED` or `ENETUNREACH`), then `MG_EV_CONNECT` reason (e.g. with `ECONNREFUSED` or `ENETUNREACH`), then `MG_EV_CONNECT`
event will report failure. Code example below: event report failure. Code example below:
```c ```c
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
......
...@@ -7,8 +7,8 @@ signature: | ...@@ -7,8 +7,8 @@ signature: |
const char *init_js_file_name); const char *init_js_file_name);
--- ---
Enables server-side JavaScript scripting. Enable server-side JavaScript scripting.
Requires a `-DMG_ENABLE_JAVASCRIPT` compilation flag and V7 engine sources. Requires `-DMG_ENABLE_JAVASCRIPT` compilation flag, and V7 engine sources.
V7 instance must not be destroyed during manager's lifetime. v7 instance must not be destroyed during manager's lifetime.
Returns a V7 error. Return V7 error.
...@@ -6,9 +6,9 @@ signature: | ...@@ -6,9 +6,9 @@ signature: |
void mg_enable_multithreading(struct mg_connection *nc); void mg_enable_multithreading(struct mg_connection *nc);
--- ---
Enables multi-threaded handling for the given listening connection `nc`. Enable multi-threaded handling for the given listening connection `nc`.
For each accepted connection, Mongoose will create a separate thread For each accepted connection, Mongoose will create a separate thread
and run an event handler in that thread. Thus, if an event handler is doing and run event handler in that thread. Thus, if an event hanler is doing
a blocking call or some long computation, it will not slow down a blocking call or some long computation, that will not slow down
other connections. other connections.
...@@ -7,5 +7,5 @@ signature: | ...@@ -7,5 +7,5 @@ signature: |
--- ---
Callback function (event handler) prototype. Must be defined by the user. Callback function (event handler) prototype. Must be defined by the user.
Mongoose calls the event handler, passing the events defined below. Mongoose calls the event handler, passing events defined below.
...@@ -6,7 +6,7 @@ signature: | ...@@ -6,7 +6,7 @@ signature: |
void mg_mgr_free(struct mg_mgr *); void mg_mgr_free(struct mg_mgr *);
--- ---
De-initialises Mongoose manager. De-initializes Mongoose manager.
Closes and deallocates all active connections. Close and deallocate all active connections.
...@@ -6,9 +6,9 @@ signature: | ...@@ -6,9 +6,9 @@ signature: |
void mg_mgr_init(struct mg_mgr *mgr, void *user_data); void mg_mgr_init(struct mg_mgr *mgr, void *user_data);
--- ---
Initialise Mongoose manager. Side effect: ignores SIGPIPE signal. Initialize Mongoose manager. Side effect: ignores SIGPIPE signal.
`mgr->user_data` field will be initialised with a `user_data` parameter. `mgr->user_data` field will be initialized with `user_data` parameter.
That is an arbitrary pointer, where the user code can associate some data That is an arbitrary pointer, where user code can associate some data
with the particular Mongoose manager. For example, a C++ wrapper class with the particular Mongoose manager. For example, a C++ wrapper class
could be written, in which case `user_data` can hold a pointer to the could be written, in which case `user_data` can hold a pointer to the
class instance. class instance.
......
...@@ -6,10 +6,10 @@ signature: | ...@@ -6,10 +6,10 @@ signature: |
time_t mg_mgr_poll(struct mg_mgr *, int milli); time_t mg_mgr_poll(struct mg_mgr *, int milli);
--- ---
This function performs the actual IO and must be called in a loop This function performs the actual IO, and must be called in a loop
(an event loop). It returns the current timestamp. (an event loop). Returns the current timestamp.
`milli` is the maximum number of milliseconds to sleep. `milli` is the maximum number of milliseconds to sleep.
`mg_mgr_poll()` checks all connections for IO readiness. If at least one `mg_mgr_poll()` checks all connection for IO readiness. If at least one
of the connections is IO-ready, `mg_mgr_poll()` triggers the respective of the connections is IO-ready, `mg_mgr_poll()` triggers respective
event handlers and returns. event handlers and returns.
...@@ -6,10 +6,10 @@ signature: | ...@@ -6,10 +6,10 @@ signature: |
struct mg_connection *mg_next(struct mg_mgr *, struct mg_connection *); struct mg_connection *mg_next(struct mg_mgr *, struct mg_connection *);
--- ---
Iterates over all active connections. Iterate over all active connections.
Returns the next connection from the list Returns next connection from the list
of active connections or `NULL` if there are no more connections. Below of active connections, or `NULL` if there is no more connections. Below
is the iteration idiom: is the iteration idiom:
```c ```c
......
...@@ -6,7 +6,7 @@ signature: | ...@@ -6,7 +6,7 @@ signature: |
int mg_printf(struct mg_connection *, const char *fmt, ...); int mg_printf(struct mg_connection *, const char *fmt, ...);
--- ---
Sends `printf`-style formatted data to the connection. Send `printf`-style formatted data to the connection.
See `mg_send` for more details on send semantics. See `mg_send` for more details on send semantics.
...@@ -6,7 +6,7 @@ signature: | ...@@ -6,7 +6,7 @@ signature: |
void mg_send(struct mg_connection *, const void *buf, int len); void mg_send(struct mg_connection *, const void *buf, int len);
--- ---
Sends data to the connection. Send data to the connection.
Note that sending functions do not actually push data to the socket. Note that sending functions do not actually push data to the socket.
They just append data to the output buffer. MG_EV_SEND will be delivered when They just append data to the output buffer. MG_EV_SEND will be delivered when
......
...@@ -7,15 +7,15 @@ signature: | ...@@ -7,15 +7,15 @@ signature: |
const char *ca_cert); const char *ca_cert);
--- ---
Note: This function is deprecated. Please, use SSL options in mg_connect_opt. Note: This function is deprecated, please use SSL options in mg_connect_opt.
Enables SSL for a given connection. Enable SSL for a given connection.
`cert` is a server certificate file name for a listening connection `cert` is a server certificate file name for a listening connection,
or a client certificate file name for an outgoing connection. or a client certificate file name for an outgoing connection.
The certificate files must be in PEM format. The server certificate file Certificate files must be in PEM format. Server certificate file
must contain a certificate, concatenated with a private key, optionally must contain a certificate, concatenated with a private key, optionally
concatenated with DH parameters. concatenated with DH parameters.
`ca_cert` is a CA certificate or NULL if peer verification is not `ca_cert` is a CA certificate, or NULL if peer verification is not
required. required.
Return: NULL on success or error message on error. Return: NULL on success, or error message on error.
...@@ -6,12 +6,12 @@ signature: | ...@@ -6,12 +6,12 @@ signature: |
double mg_set_timer(struct mg_connection *c, double timestamp); double mg_set_timer(struct mg_connection *c, double timestamp);
--- ---
Schedules an MG_EV_TIMER event to be delivered at `timestamp` time. Schedule MG_EV_TIMER event to be delivered at `timestamp` time.
`timestamp` is UNIX time (the number of seconds since Epoch). It is `timestamp` is a UNIX time (a number of seconds since Epoch). It is
`double` instead of `time_t` to allow for sub-second precision. `double` instead of `time_t` to allow for sub-second precision.
Returns the old timer value. Return the old timer value.
Example: set the connect timeout to 1.5 seconds: Example: set connect timeout to 1.5 seconds:
``` ```
c = mg_connect(&mgr, "cesanta.com", ev_handler); c = mg_connect(&mgr, "cesanta.com", ev_handler);
......
...@@ -6,7 +6,7 @@ signature: | ...@@ -6,7 +6,7 @@ signature: |
int mg_socketpair(sock_t[2], int sock_type); int mg_socketpair(sock_t[2], int sock_type);
--- ---
Creates a socket pair. Create a socket pair.
`sock_type` can be either `SOCK_STREAM` or `SOCK_DGRAM`. `sock_type` can be either `SOCK_STREAM` or `SOCK_DGRAM`.
Returns 0 on failure and 1 on success. Return 0 on failure, 1 on success.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment