Epoll Implement reactor mode

Source: Internet
Author: User
Tags epoll

Turn from: http://blog.csdn.net/analogous_love/article/details/53319815

has been watching Zhang's "High-performance Linux Server Programming" book, download Link: http://download.csdn.net/detail/analogous_love/9673008

This is how the book describes the reactor model:




In this way, I write a simple exercise:

[CPP]  View Plain  copy  /**    * @desc:    Practice server programs with reactor mode,main.cpp  & nbsp;* @author: zhangyl   * @date:   2016.11.23   */       #include  <iostream>   #include  <string.h>   #include  < sys/types.h>   #include  <sys/socket.h>   #include  <netinet/in.h>    #include  <arpa/inet.h>  //for htonl ()  and htons ()    # include <unistd.h>   #include  <fcntl.h>   #include  <sys/ epoll.h>   #include  <signal.h>     //for signal ()     #include  <pthread.h>   #include  <semaphore.h>   #include   <list>   #include  <errno.h>   #include  <time.h>   # Include <sstream>   #include  <iomanip> //for std::setw ()/setfill ()     #include  <stdlib.h>         #define  WORKER_THREAD_NUM    5      #define &NBSP;MIN (a, b)   (a <= b)  ?  (a)  :  (b))        int g_epollfd = 0;   bool g_bstop  = false;   int g_listenfd = 0;   Pthread_t g_acceptthreadid  = 0;   pthread_t g_threadid[worker_thread_num] = { 0 };    pthread_cond_t g_acceptcond;   pthread_mutex_t g_acceptmutex;      pthread_cond_t g_cond /*= pthread_cond_initializer*/;   Pthread_mutex_t g_mutex  /*= PTHREAD_MUTEX_INITIALIZER*/;      pthread_mutex_t g_clientmutex;    &Nbsp;  std::list<int> g_listclients;      void prog_exit (Int signo)    {  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.