select服务器实现
服务器端selectserver.c(支持读写逻辑)
客户端selectclient.c
select服务器优缺点:
优点:
(1)select()的可移植性更好,在某些Unix系统上不支持poll() ;
(2)select() 对于超时值提供了更好的精度:微秒,而poll是毫秒;
(3)select服务器不需要建立多个线程、进程就可以实现一对多的通信;
(4)select服务器可以同时等待多个文件描述符,效率比起多进程多线程来说要高很多。
缺点:
(1)每次调用select,都需要把fd集合从用户态拷贝到内核态,这个开销在fd很多时会很大 ;
(2)同时每次调用select都需要在内核遍历传递进来的所有fd,这个开销在fd很多时也很大 ;
(3)select支持的文件描述符数量太小了,默认是1024。
但相对于TCP单进程版本、TCP多线程版本和TCP多进程版本,select服务器效率高于以上三个;