linux socketµÄselectº¯ÊýÀý×Ó
ʹÓÃselectº¯Êý¿ÉÒÔÒÔ·Ç×èÈûµÄ·½Ê½ºÍ¶à¸ösocketͨÐÅ¡£³ÌÐòÖ»ÊÇÑÝʾselectº¯ÊýµÄʹÓ㬹¦Äܷdz£¼òµ¥£¬¼´Ê¹Ä³¸öÁ¬½Ó¹Ø±ÕÒÔºóÒ²²»»áÐ޸ĵ±Ç°Á¬½ÓÊý£¬Á¬½ÓÊý´ïµ½×î´óÖµºó»áÖÕÖ¹³ÌÐò¡£
1. ³ÌÐòʹÓÃÁËÒ»¸öÊý×éfd_A£¬Í¨ÐÅ¿ªÊ¼ºó°ÑÐèҪͨÐŵĶà¸ösocketÃèÊö·û¶¼·ÅÈë´ËÊý×é¡£
2. Ê×ÏÈÉú³ÉÒ»¸ö½Ðsock_fdµÄsocketÃèÊö·û£¬ÓÃÓÚ¼àÌý¶Ë¿Ú¡£
3. ½«sock_fdºÍÊý×éfd_AÖв»Îª0µÄÃèÊö·û·ÅÈëselect½«¼ì²éµÄ¼¯ºÏfdsr¡£
4. ´¦ÀífdsrÖпÉÒÔ½ÓÊÕÊý¾ÝµÄÁ¬½Ó¡£Èç¹ûÊÇsock_fd£¬±íÃ÷ÓÐÐÂÁ¬½Ó¼ÓÈ룬½«Ð¼ÓÈëÁ¬½ÓµÄsocketÃèÊö·û·ÅÖõ½fd_A¡£
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define MYPORT 1234 // the port users will be connecting to
#define BACKLOG 5 // how many pending connections queue will hold
#define BUF_SIZE 200
int fd_A[BACKLOG]; // accepted connection fd
int conn_amount; // current connection amount
void showclient()
{
int i;
printf("client amount: %d\n", conn_amount);
for (i = 0; i < BACKLOG; i++) {
printf("[%d]:%d ", i, fd_A[i]);
}
printf("\n\n");
}
int main(void)
{
int sock_fd, new_fd; // listen on sock_fd, new connection on new_fd
struct sockaddr_in server_addr; // server address information
Ïà¹ØÎĵµ£º
Linux
Äں˱à³Ìѧϰ
³£³£ÓÐÈËÎÊ£ºÎÒÏëѧϰÄںˣ¬ÐèҪʲô»ù´¡Âð£¿Linus Torvalds
±¾ÈËÊÇÕâÑù»Ø´ðµÄ£ºÄã±ØÐëʹÓùý
Linux
¡£ Õâ¸ö
……
»¹ÊÇÓеãÌ«·ºÁË°É£¬ÎÒÏëÏÂÃ漸¸ö»ù´¡¿ÉÄÜ»¹ÊÇÐèÒªµÄ£¬¾¡¹Ü²»Ò»¶¨±ØÐ裺
1, ¹ØÓÚ²Ù×÷ϵͳÀíÂÛµÄ×î³õ¼¶µÄ֪ʶ¡£²»ÐèҪͨ¶Á²¢Àí½â¡¶²Ù×÷ϵͳ¸ÅÄ ......
1
¡¢Ï̵߳Ĵ´½¨¡¢ÖÕÖ¹¼°¿ØÖÆ£º
Èκνø³ÌÔÚÆô¶¯Ê±¾ÍÒÑÓÐÁËÒ»¸öÖ÷Ị̈߳¬Èç¹ûÐèÒªÔÙÉú³ÉÏß³ÌÔòʹÓÃ
pthread_create
º¯Êý£¬Ôڸú¯ÊýÖпÉÒÔÖ¸¶¨Ï̵߳ÄÊôÐÔ¡¢Ïß³ÌÀý³Ì¡¢´«¸øÏß³ÌÀý³ÌµÄ²ÎÊý¡£Ïß³ÌÀý³ÌÊÇÒ»¸öÓû§×Ô¶¨ÒåµÄº¯Êý£¬¼°Ïß³ÌÖ´ÐеĴúÂë¡£µ±Ïß³ÌÀý³Ì·µ»Øʱ£¬Ïß³ÌÔò½áÊøÔËÐУ¬ ......
££¿×½¨¾ü(Kongove.CN)
2008.11.12
Ê×ÏÈ£¬ÈÃÎÒÃÇÀ´¿´¼¸×éÁîÈËÕñ·ÜµÄÊý¾Ý¡£ÏÖÔÚ¶©ÔÄLinuxÄÚºËÓʼþÁбí[1]£¬Ã¿ÌìµÄÓʼþÁ÷Á¿´ó¸ÅÔÚ500·Ý×óÓÒ£»Ö´ÐÐ"grep "^P:"
MAINTAINERS |sort -u|wc
-l"£¬¶ÔÄÚºË×Óϵͳά»¤Õß½øÐÐͳ¼Æ£¬µÃµ½µÄ½á¹ûÊÇ534ÈË£»´Ó2007µ½2008Ä꣬ƽ¾ùÿÌìÓÐ4300ÐдúÂëÌí¼Óµ½Äںˣ¬ÓÐ180 ......
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
Linux
·¢ÐаæÓë
Linux
²úÆ·Á½ÕßÏà²îºÜ´ó£¬ÓÐʱÈÝÒ×»ìÏý£¬·¢ÉúÎó½â£¬ÉõÖÁÒªÄÖ³ö´óЦ»°À´¡£ÎªÊ²Ã´£¿
´Ó×ÖÃæÉÏÀ´½²£¬·¢Ðа棨
Distribution
£©ºÍ²úÆ ......