Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

linux cÓïÑÔ selectº¯ÊýÓ÷¨

  SelectÔÚSocket±à³ÌÖл¹ÊDZȽÏÖØÒªµÄ£¬¿ÉÊǶÔÓÚ³õѧSocketµÄÈËÀ´Ëµ¶¼²»Ì«°®ÓÃSelectд³ÌÐò£¬ËûÃÇÖ»ÊÇÏ°¹ßдÖîÈç connect¡¢accept¡¢recv»òrecvfromÕâÑùµÄ×èÈû³ÌÐò£¨Ëùν×èÈû·½Ê½block£¬¹ËÃû˼Ò壬¾ÍÊǽø³Ì»òÊÇÏß³ÌÖ´Ðе½ÕâЩº¯Êýʱ±ØÐëµÈ
´ýij¸öʼþµÄ·¢Éú£¬Èç¹ûʼþûÓз¢Éú£¬½ø³Ì»òÏ߳̾ͱ»×èÈû£¬º¯Êý²»ÄÜÁ¢¼´·µ»Ø£©¡£
¿ÉÊÇʹÓÃSelect¾Í¿ÉÒÔÍê³É·Ç×èÈû£¨Ëùν·Ç×èÈû·½Ê½non- block£¬¾ÍÊǽø³Ì»òÏß³ÌÖ´Ðд˺¯Êýʱ²»±Ø·ÇÒªµÈ´ýʼþµÄ·¢Éú£¬Ò»µ©Ö´Ðп϶¨·µ»Ø£¬ÒÔ·µ»ØÖµµÄ²»Í¬À´·´Ó³º¯ÊýµÄÖ´ÐÐÇé¿ö£¬Èç¹ûʼþ·¢ÉúÔòÓë×èÈû·½Ê½Ïàͬ£¬ÈôʼþûÓз¢ÉúÔò·µ»ØÒ»¸ö´úÂëÀ´¸æ֪ʼþδ·¢Éú£¬¶ø½ø³Ì»òÏ̼߳ÌÐøÖ´ÐУ¬ËùÒÔЧÂʽϸߣ©·½Ê½¹¤×÷µÄ³ÌÐò£¬ËüÄܹ»¼àÊÓÎÒÃÇÐèÒª¼àÊÓµÄÎļþÃèÊö·ûµÄ±ä»¯Çé¿ö——¶Áд»òÊÇÒì³£¡£
ÏÂÃæÏêϸ½éÉÜһϣ¡
SelectµÄº¯Êý¸ñʽ(ÎÒËù˵µÄÊÇUnixϵͳϵIJ®¿ËÀûsocket±à³Ì£¬ºÍwindowsϵÄÓÐÇø±ð£¬Ò»»á¶ù˵Ã÷)£º
int select(int maxfdp,fd_set *readfds,fd_set *writefds,fd_set *errorfds,struct timeval *timeout);
ÏÈ˵Ã÷Á½¸ö½á¹¹Ì壺
µÚÒ»£¬struct fd_set¿ÉÒÔÀí½âΪһ¸ö¼¯ºÏ£¬Õâ¸ö¼¯ºÏÖдæ·ÅµÄÊÇÎļþÃèÊö·û(filedescriptor)£¬¼´Îļþ¾ä±ú£¬Õâ¿ÉÒÔÊÇÎÒÃÇËù˵µÄÆÕͨÒâÒåµÄÎļþ£¬µ±È»UnixÏÂÈκÎÉ豸¡¢¹ÜµÀ¡¢FIFOµÈ¶¼ÊÇÎļþÐÎʽ£¬È«²¿°üÀ¨ÔÚÄÚ£¬ËùÒÔºÁÎÞÒÉÎÊÒ»¸ösocket¾ÍÊÇÒ»¸öÎļþ£¬socket¾ä±ú¾ÍÊÇÒ»¸öÎļþÃèÊö·û¡£
fd_set¼¯ºÏ¿ÉÒÔͨ¹ýһЩºêÓÉÈËΪÀ´²Ù×÷£¬±ÈÈç
Çå¿Õ¼¯ºÏFD_ZERO(fd_set *)£»
½«Ò»¸ö¸ø¶¨µÄÎļþÃèÊö·û¼ÓÈ뼯ºÏÖ®ÖÐFD_SET(int ,fd_set *)£»
½«Ò»¸ö¸ø¶¨µÄÎļþÃèÊö·û´Ó¼¯ºÏÖÐɾ³ýFD_CLR(int ,fd_set*)£»
¼ì²é¼¯ºÏÖÐÖ¸¶¨µÄÎļþÃèÊö·ûÊÇ·ñ¿ÉÒÔ¶ÁдFD_ISSET(int ,fd_set* )¡£Ò»»á¶ù¾ÙÀý˵Ã÷¡£
µÚ¶þ£¬struct timevalÊÇÒ»¸ö´ó¼Ò³£ÓõĽṹ£¬ÓÃÀ´´ú±íʱ¼äÖµ£¬ÓÐÁ½¸ö³ÉÔ±£¬Ò»¸öÊÇÃëÊý£¬ÁíÒ»¸öÊǺÁÃëÊý¡£
¾ßÌå½âÊÍselectµÄ²ÎÊý£º
int maxfdpÊÇÒ»¸öÕûÊýÖµ£¬ÊÇÖ¸¼¯ºÏÖÐËùÓÐÎļþÃèÊö·ûµÄ·¶Î§£¬¼´ËùÓÐÎļþÃèÊö·ûµÄ×î´óÖµ¼Ó1£¬²»ÄÜ´í£¡ÔÚWindowsÖÐÕâ¸ö²ÎÊýµÄÖµÎÞËùν£¬¿ÉÒÔÉèÖò»ÕýÈ·¡£
fd_set*readfdsÊÇÖ¸Ïòfd_set½á¹¹µÄÖ¸Õ룬Õâ¸ö¼¯ºÏÖÐÓ¦¸Ã°üÀ¨ÎļþÃèÊö·û£¬ÎÒÃÇÊÇÒª¼àÊÓÕâЩÎļþÃèÊö·ûµÄ¶Á±ä»¯µÄ£¬¼´ÎÒÃǹØÐÄÊÇ·ñ¿ÉÒÔ´ÓÕâЩÎļþÖжÁÈ¡Êý¾ÝÁË£¬Èç¹ûÕâ¸ö¼¯ºÏÖÐÓÐÒ»¸öÎļþ¿É¶Á£¬select¾Í»á·µ»ØÒ»¸ö´óÓÚ0µÄÖµ£¬±íʾÓÐÎļþ¿É¶Á£¬Èç¹ûûÓпɶÁµÄÎļþ£¬Ôò¸ù¾Ýtimeout²ÎÊýÔÙÅжÏÊÇ·ñ³¬Ê±£¬Èô³¬³ötime


Ïà¹ØÎĵµ£º

ÔÚlinuxÏÂʵÏÖweb qqµÄ×ÀÃ滯


´´½¨×ÀÃæͼ±ê
Ä¿Ç°½«ÍøÂçÓ¦ÓÃÀ©Õ¹µ½×ÀÃæÊÇÒ»¸öÇ÷ÊÆ£¬´æÔÚןܶà½â¾ö·½°¸£¬±¾ÎÄÒÔ Mozilla Prism ΪÀý£¬ÀàËƵķ½·¨Í¬ÑùÊÊÓÃÓÚ Google Chrome ¡£
1. µ½ Mozilla Prism µÄÍøÕ¾ÉÏÏÂÔØ Prism£¬µã»÷ Download Now Ö®ºó»áÌáʾÓÐÁ½ÖÖ£¬Ò»ÖÖÊÇÒÔ Mozilla Firefox À©Õ¹µÄ·½Ê½£¬ÊʺÏÒѾ­°²×°ÓÐ Firefox µÄÅóÓÑ£»Ò»Ö ......

º¯ÊýµÄ½âÎöÖ®C/C++

      º¯ÊýÊdzÌÐòµÄÖ´ÐÐÄ£¿é£¬ÊÇÕû¸öÏîÄ¿µÄϸ°û£¬ÈçºÎ×éÖ¯ºÃÿһ¸öº¯ÊýµÄ½á¹¹£¬ÈçºÎÌá¸ß³ÌÐòµÄ¿É¶ÁÐÔºÍÔËÐÐЧÂÊ£¬ÊdzÌÐòÔ±ÃDz»¶ÏƷζµÄÖ÷Ìå¡£ÓÐʱº¯ÊýµÄÉè¼ÆÄÜÖ±½ÓÌåÏÖ³ö³ÌÐòÔ±¶ÔC/C++µÄÀí½âºÍ¸ÐÎò¡£
      C/C++µÄº¯ÊýÀàÐͲ»¶ÔÍâºõÒÔϼ¸ÖÖ£¬ÓÐЩÃèÊö¿ÉÄܲ»Ì«ÌùÇУº
......

Ö÷Ì⣺һ¸ö¼òµ¥µÄlinuxÏ̳߳Ø

Ï̳߳Ø
£º¼òµ¥µØ˵£¬Ï̳߳Ø
¾ÍÊÇÔ¤ÏÈ´´½¨ºÃÒ»ÅúỊ̈߳¬·½±ã¡¢¿ìËٵش¦ÀíÊÕµ½µÄÒµÎñ¡£±ÈÆð´«Í³µÄµ½À´Ò»¸öÈÎÎñ£¬¼´Ê±´´½¨Ò»¸öÏß³ÌÀ´´¦Àí£¬½ÚÊ¡ÁËÏ̵߳Ĵ´½¨ºÍ»ØÊյĿªÏú£¬ÏìÓ¦¸ü¿ì£¬Ð§ÂÊ
¸ü¸ß¡£
ÔÚlinuxÖУ¬Ê¹ÓõÄÊÇposixÏ߳̿⣬Ê×ÏȽéÉܼ¸¸ö³£Óõĺ¯Êý£º
1 Ï̵߳Ĵ´½¨ºÍÈ¡Ïûº¯Êý
pthread_create
´´½¨
pthread_join ......

Howto: Linux Add User To Group (tips)

Q. How can I add a user to a group under Linux operating system?
A. You can use useradd or usermod commands to add a user to a group. useradd command creates a new user or update default new user information. usermod command modifies a user account i.e. it is useful to add user to existin ......

Linux³£ÓÃÃüÁî

1¡¢free ²é¿´·þÎñÆ÷µÄÄÚ´æ·ÖÅäÇé¿ö
2¡¢resin ¼ò½é£º
 ps -elf|grep java    //²é¿´½ø³Ì resinÆô¶¯Çé¿ö
 ps -elf|grep java
 ll               //²é¿´½Å±¾Æô¶¯ÁÐ±í£¨ÒªÆô¶¯µÄÎļþÁÐ±í£©
 dl _jsp
 // ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ