In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to understand the libevent cycle of events, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
# include # include "event2/event.h" # include void stdin_callback (evutil_socket_t fd,short what,void * arg) {static int i = 0; char buf [1024]; struct event* base = (struct event_base *) arg; printf ("stdin_callback start\ n"); int ret = read (fd,buf,sizeof (buf)); buf [ret] ='\ 0mm; printf ("buf% s\ n", buf) Printf ("stdin_callback end\ n"); if (+ + I > = 1) {/ / event_base_loopbreak (base); / / event_base_loopexit (base,NULL); struct timeval timeout = {5 base,&timeout 0}; event_base_loopexit (base,&timeout); / / 5 seconds later exit}} int main () {struct event_base * base = event_base_new () Struct event * ev0 = event_new (base,STDIN_FILENO,0,NULL.NULL); event_assign (ev0,base,STDIN_FILENO,EV_READ | EV_PERSIST,stdin_callback,base); event_add (ev0,NULL); struct event * ev1 = event_new (base,STDIN_FILENO,0,NULL.NULL); event_assign (ev1,base,STDIN_FILENO,EV_READ | EV_PERSIST,stdin_callback,base); event_add (ev1,NULL) / * event loop*/ event_base_loop (base,0); / / the effect is equivalent to event_base_dispatch (base); / / event_base_loop (base,EVLOOP_ONCE); / / event_base_loop (base,EVLOOP_NONBLOCK); if (event_base_got_break (base)) puts ("event base loop break") Else if (event_base_got_exit (base)) puts ("event base loop exit"); event_base_free (base); event_free (ev0); event_free (ev1); return 0;} is it helpful for you to read the above? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.