基础原理理解请参考这篇:
select主要解决的问题:(详细请参考:select用法&原理详解(源码剖析))
select/epoll区别:如果这篇文章说不清epoll的本质,那就过来掐死我吧!
逻辑框架
服务端:
//服务端 gcc server_epoll.c -o server_epoll
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <pthread.h>
#include <sys/ioctl.h>
#define true 1
#define false 0
#define MAX_EVENT_NUMBER 1024
#define BUFFER_SIZE 10
/*将文件描述符设置为非阻塞*/
int setnonblocking(int fd)
{
int old_option = fcntl(fd, F_GETFL);
int new_option = old_option | O_NONBLO