| Monkey HTTP Daemon 0.12 Documentation: A Fast and Lightweight Web Server for Linux | ||
|---|---|---|
| Prev | Chapter 5. Monkey API | Next |
5.2. Monkey Events
As part of the API interface, Monkey provides a set of functions and callbacks to work with events for any kind of file descriptor, more common used with sockets. These set of functions are wrappers for the epoll(7) Linux system call.
In order to use the events interface properly, you must register the file descriptor with the API function event_add() and define the hooks described above for the events read, write, close, error and timeout.
5.2.1. event_add()
This API function, register a file descriptor in the Monkey epoll thread interface
int event_add(int sockfd, struct plugin *handler, struct client_request *cr, struct request *sr)
5.2.2. _mkp_event_read()
This hook function, is invoked when the file descriptor has some data ready to be read.
int _mkp_event_read(struct client_request *cr, struct request *sr)
5.2.3. _mkp_event_write()
This hook function, is invoked when the file descriptor is ready to receive data.
int _mkp_event_write(struct client_request *cr, struct request *sr)
5.2.4. _mkp_event_close()
This hook function, is invoked when the file descriptor has been closed.
int _mkp_event_close(struct client_request *cr, struct request *sr)
5.2.5. _mkp_event_error()
This hook function, is invoked when some error has been reported in the file descriptor, if the context is sockets, a hangup or broken connection will provocate this hook being called.
int _mkp_event_error(struct client_request *cr, struct request *sr)
5.2.6. _mkp_event_timeout()
This hook function is invoked when some timeout is reported in the file descriptor, the time used for this timeout is the time defined in Monkey core for the epoll() interface.
int _mkp_event_timeout(struct client_request *cr, struct request *sr)