mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-03 17:28:59 +08:00
1f75081f6e
Which disables tokenizer, parser, AST, and compiler. On ESP8266, it frees 21K of ROM. PUBLISHED_FROM=ff4c53ace6b9056c595b9e12ef3453330d659775
1.3 KiB
1.3 KiB
title |
---|
Event handler function |
Each connection has an event handler function associated with it. That function must be implemented by the user. Event handler is the key element of the Mongoose application, since it defines the application's behaviour. This is how an event handler function looks like:
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
switch (ev) {
/* Event handler code that defines behavior of the connection */
...
}
}
struct mg_connection *nc
: Connection that has received an event.int ev
: Event number, defined inmongoose.h
. For example, when data arrives on an inbound connection,ev
would beMG_EV_RECV
.void *ev_data
: This pointer points to the event-specific data, and it has a different meaning for different events. For example, for anMG_EV_RECV
event,ev_data
is anint *
pointer, pointing to the number of bytes received from the remote peer and saved into the receive IO buffer. The exact meaning ofev_data
is described for each event. Protocol-specific events usually haveev_data
pointing to structures that hold protocol-specific information.
NOTE: struct mg_connection
has void *user_data
which is a placeholder for
application-specific data. Mongoose does not use that pointer. Event handler
can store any kind of information there.