Advertisement

Unix/Linux 编程:网络编程(epoll与Reactor)

阅读量:

在前一篇文章中完成了基于epoll的非阻塞IO服务端程序的开发。然而,在实际应用过程中,若需注册大量事件,采用冗长的if语句块将显著影响代码的可读性与维护性。为此,借鉴Reactor模型的设计理念,对epoll服务器进行了重构,将所有事件处理逻辑封装为回调函数的形式。在此过程中,需特别注意参数传递时可能遇到的一些常见问题。

复制代码
 /* Server based on EPOLL */

    
 #include <stdio.h>
    
 #include <stdlib.h>
    
 #include <string.h>
    
 #include <errno.h>
    
 #include <fcntl.h>
    
 #include <unistd.h>
    
 #include <sys/types.h>
    
 #include <sys/socket.h>
    
 #include <netinet/in.h>
    
 #include <netinet/tcp.h>
    
 #include <arpa/inet.h>
    
 #include <sys/epoll.h>
    
  
    
 #define BUFFER_LENGTH   1024
    
  
    
 struct sockite

全部评论 (0)

还没有任何评论哟~