02 The overall framework of the libevent library

02 The overall framework of the libevent library

以下是关于libevent学习的相关文章:
01 Download and installation of the libevent library and test whether the installation is successful
02 The overall framework idea of ​​the libevent library
03 The main function of
communication
under the
libevent Area features introduction
07libevent library related functions of the bufferevent event
08libevent library communication server and client main functions
09libevent library server and client TCP communication process and code examples

Thought: Everything you see is an event, analogous to Linux, and everything you see is a file. So some event responses are implemented based on callback functions; for example, set the callback function in advance, and when an event is met, the kernel will automatically call the registered callback for you. '

1 Libevent overall framework
1) Create event_base, similar to Lego base. The function is

struct event_base* event_base_new(void);

2) Create an event. Including common event event and buffer event used for socket communication.

event_new();
bufferevent_socket_new();//一般调用在建立好连接后

3) Add the event to the base.

int event_add(struct event *ev,const structtimeval *tv);

4) Loop monitoring events.

int event_base_dispatch(struct event_base *base);//类似epoll_wait()加上while()

5) Release event_base.

event_base_free(base);

Note: The above is just a brief introduction to the main framework of libevent, but it is very important. The next article will introduce the main functions of libevent communication in detail.

Guess you like

Origin blog.csdn.net/weixin_44517656/article/details/108742062
Recommended