mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-27 12:26:24 +00:00
Refactor Mongoose documentation
PUBLISHED_FROM=e9a4e5c7b4a1d03b93a2a79e29de19e60e919929
This commit is contained in:
1 parent
4120f953c7
commit
12437fd7fe
87 files changed
+977
-332
No files matched your search
@@ -0,0 +1,31 @@
|
||||
---
|
||||
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 what an event
|
||||
handler function looks like:
|
||||
|
||||
```c
|
||||
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 in `mongoose.h`. For example, when data
|
||||
arrives on an inbound connection, `ev` would be `MG_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 an `MG_EV_RECV` event,
|
||||
`ev_data` is an `int *` pointer, pointing to the number of bytes received
|
||||
from the remote peer and saved into the receive IO buffer. The exact meaning of
|
||||
`ev_data` is described for each event. Protocol-specific events usually have
|
||||
`ev_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.
|
||||
Reference in new issue
Block a user