赞
踩
(内核提供函数)int select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout);
nfds:监听的所有文件描述符中,最大文件描述符+1 readfds: 读 文件描述符监听集合。 传入、传出参数 writefds:写 文件描述符监听集合。 传入、传出参数 NULL exceptfds:异常 文件描述符监听集合 传入、传出参数 NULL timeout: > 0: 设置监听超时时长。 NULL: 阻塞监听 0: 非阻塞监听,轮询 返回值: > 0: 所有监听集合(3个)中, 满足对应事件的总数。 0: 没有满足监听条件的文件描述符 -1: errno
1.#include <stdio.h> 2.#include <stdlib.h> 3.#include <unistd.h> 4.#include <string.h> 5.#include <arpa/inet.h> 6.#include <ctype.h> 7. 8.#include "wrap.h" 9. 10.#define SERV_PORT 6666 11. 12.int main(int argc, char *argv[]) 13.{ 14. int i, j, n, nready; 15. 16. int maxfd = 0; //最大描述符 17. 18. int listenfd, connfd; 19. 20. char buf[BUFSIZ]; /* #define INET_ADDRSTRLEN 16 */ 21. 22. struct sockaddr_in clie_addr
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。