当前位置:   article > 正文

select实现多路io转接_selectio interface wizard

selectio interface wizard

(内核提供函数)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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/866440
推荐阅读
相关标签
  

闽ICP备14008679号