网络编程 select
2018-03-02 17:18
183 查看
1. select多路复用:多路即多个socket,复用即select可以检查多个socket,然后根据select函数的返回值,对socket进行使用。#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);2. 参数说明:
nfds:文件描述符的最大值
readfds:可读的文件描述符
writefds:可写的文件描述符
exceptfds:异常的文件描述符
timeout:NULL:阻塞,即无限等待直到有可读写文件。>0:指定等待的时间,时间到,函数返回。
3. fd_set处理函数:
<0:出错
=0:等待超时
>0:有文件可读写
5. struct timeval结构struct timeval {
time_t tv_sec;
susends_t tv_usec;
};
#include <sys/types.h>
#include <unistd.h>
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);2. 参数说明:
nfds:文件描述符的最大值
readfds:可读的文件描述符
writefds:可写的文件描述符
exceptfds:异常的文件描述符
timeout:NULL:阻塞,即无限等待直到有可读写文件。>0:指定等待的时间,时间到,函数返回。
3. fd_set处理函数:
FD_ZERO(fd_set *fdset) // 将指定的文件描述符集清空,在对文件描述符集合进行设置前,必须对其进行初始化,如果不清空,由于在系统分配内存空间后,通常并不作清空处理,所以结果是不可知的。 FD_SET(int fd,fd_set *fdset) // 用于在文件描述符集合中增加一个新的文件描述符。 FD_CLR(int fd,fd_set *fdset) // 用于在文件描述符集合中删除一个文件描述符。 FD_ISSET(int fd,fd_set *fdset) // 用于测试指定的文件描述符是否在该集合中。4. 返回值:
<0:出错
=0:等待超时
>0:有文件可读写
5. struct timeval结构struct timeval {
time_t tv_sec;
susends_t tv_usec;
};
相关文章推荐
- 网络编程(51)—— Windows下使用select进行IO复用
- linux 网络编程 I/O复用 select,poll ,epoll
- 网络编程五种IO模型之WSAEventSelect模型
- 【网络编程】之六、选择select
- Linux 网络编程中的select
- 朴素、Select、Poll和Epoll网络编程模型实现和分析——Poll、Epoll模型处理长连接性能比较
- linux 网络编程【三】 非阻塞通信select
- WSAEventSelect网络编程
- Linux 网络编程中的 select 函数
- socket Linux 下网络编程中的select
- linux(or Windows) 异步网络编程 simple client-server-select 应用
- 【网络编程】之七、select聊天室
- linux socket网络编程:fcntl select(多个客户端连接服务器端情形)
- linux下非阻塞网络编程-select
- Linux网络编程select模型的实现
- windows Socket编程之select网络模型
- socket网络编程之select模型
- linux------tcp---------Linux网络编程一步一步学-异步通讯聊天程序select
- C++网络编程之select
- python select网络编程模块详解