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

Ï̳߳¬Ê±µÈ´ý·½·¨ linuxÖÐselect()º¯ÊýʹÓÃ

selectϵͳµ÷ÓÃʱÓÃÀ´ÈÃÎÒÃǵijÌÐò¼àÊÓ¶à¸öÎļþ¾ä±úµÄ״̬±ä»¯µÄ¡£³ÌÐò»áÍ£ÔÚselectÕâÀïµÈ´ý£¬Ö±µ½±»¼àÊÓµÄÎļþ¾ä±úÓÐÒ»¸ö»ò¶à¸ö·¢ÉúÁË״̬¸Ä±ä¡£
¹ØÓÚÎļþ¾ä±ú£¬Æäʵ¾ÍÊÇÒ»¸öÕûÊý£¬Í¨¹ýsocketº¯ÊýµÄÉùÃ÷¾ÍÃ÷°×ÁË£º
int socket(int domain, int type, int protocol);
ÎÒÃÇ×îÊìϤµÄ¾ä±úÊÇ0¡¢1¡¢2Èý¸ö£¬0ÊDZê×¼ÊäÈ룬1ÊDZê×¼Êä³ö£¬2ÊDZê×¼´íÎóÊä³ö¡£0¡¢1¡¢2ÊÇÕûÊý±íʾµÄ£¬¶ÔÓ¦µÄFILE *½á¹¹µÄ±íʾ¾ÍÊÇstdin¡¢stdout¡¢stderr¡£
¼ÌÐøÉÏÃæµÄselect£¬¾ÍÊÇÓÃÀ´¼àÊÓij¸ö»òijЩ¾ä±úµÄ״̬±ä»¯µÄ¡£selectº¯ÊýÔ­ÐÍÈçÏ£º
int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
º¯ÊýµÄ×îºóÒ»¸ö²ÎÊýtimeoutÊÇÒ»¸ö³¬Ê±Ê±¼äÖµ¡£ÆäÀàÐÍÊÇstruct timeval *£¬¼´Ò»¸östruct timeval½á¹¹µÄ±äÁ¿µÄÖ¸Õ룬ËùÒÔÎÒÃÇÔÚ³ÌÐòÀïÒªÉùÃ÷Ò»¸östruct timeval tv;È»ºó°Ñ±äÁ¿tvµÄµØÖ·&tv´«µÝ¸øselectº¯Êý¡£struct timeval½á¹¹ÈçÏ£º
struct timeval
{
       long tv_sec;  //seconds
       long tv_usec; //microseconds
}£»
µÚ2¡¢3¡¢4Èý¸ö²ÎÊýÊÇÒ»ÑùµÄÀàÐÍ;fd_set *,¼´ÎÒÃÇÔÚ³ÌÐòÀïÒªÉêÇ뼸¸öfd_setÀàÐ͵ıäÁ¿£¬±ÈÈçrdfds£¬wtfds£¬exfds£¬È»ºó°ÑÕâ¸ö±äÁ¿µÄµØÖ·&rdfds,&wtfds,&exfds´«µÝ¸øselectº¯Êý¡£ÕâÈý¸ö²ÎÊý¶¼ÊÇÒ»¸ö¾ä±úµÄ¼¯ºÏ£¬µÚÒ»¸ördfdsÊÇÓÃÀ´±£´æÕâÑùµÄ¾ä±úµÄ:µ±¾ä±úµÄ״̬±ä³É¿É¶Áʱϵͳ¾Í¸æËßselectº¯Êý·µ»Ø£¬Í¬ÀíµÚ¶þ¸öº¯ÊýÊÇÖ¸ÏòÓоä±ú״̬±ä³É¿Éдʱϵͳ¾Í»á¸æËßselectº¯Êý·µ»Ø£¬Í¬ÀíµÚÈý¸ö²ÎÊýexfdsÊÇÌØÊâÇé¿ö£¬¼´¾ä±úÉÏÓÐÌØÊâÇé¿ö·¢Éúʱϵͳ»á¸æËßselectº¯Êý·µ»Ø¡£ÌØÊâÇé¿ö±ÈÈç¶Ô·½Í¨¹ýÒ»¸ösocket¾ä±ú·¢À´Á˽ô¼±Êý¾Ý¡£Èç¹ûÎÒÃdzÌÐòÀïÖ»Ïë¼ì²âij¸ösocketÊÇ·ñÓÐÊý¾Ý¿É¶Á£¬ÎÒÃÇ¿ÉÒÔÕâÑù£º
fd_set  rdfds;
struct timeval tv;
int ret;
FD_ZERO(&rdfds);
FD_SET(socket, &rdfds);
tv.tv_sec = 1;
tv.tv_uses = 500;
ret = select (socket + 1, %rdfds, NULL, NULL, &tv);
if(ret < 0) perror (“select”);
else if (ret = = 0) printf(“time out”);
else {
       printf(“ret = %d\n”,ret);
       if(FD_ISSET(socket, &rdfds)){
    /* ¶ÁÈ¡socket¾ä±úÀïµÄÊ


Ïà¹ØÎĵµ£º

ʵսLinux Bluetooth±à³Ì (Æß) SDPЭÒé

Service Discovery Protocol(SDP)ÌṩһÖÖÄÜÁ¦£¬ÈÃÓ¦ÓóÌÐòÓз½·¨·¢ÏÖÄÄÖÖ·þÎñ¿ÉÓÃÒÔ¼°ÕâÖÖ·þÎñµÄÌØÐÔ¡£
·þÎñ·¢ÏÖЭÒé(SDP»òBluetooth SDP)ÔÚÀ¶ÑÀЭÒéÕ»ÖжÔÀ¶ÑÀ»·¾³ÖеÄÓ¦ÓóÌÐòÓÐÌØÊâµÄº¬Ò⣬·¢ÏÖÄĸö·þÎñÊÇ¿ÉÓõĺÍÈ·¶¨ÕâЩ¿ÉÓ÷þÎñµÄÌØÕ÷¡£SDP¶¨ÒåÁËbluetooth client·¢ÏÖ¿ÉÓÃbluetooth server·þÎñºÍËüÃǵÄÌØÕ÷µÄ·½·¨¡£ ......

LinuxÐéÄâÖ÷»úÖ»ÓÐÓʾֺÍBIND²¿·Ö

С½á£º
      ÔÚ°²×°postfixʱ£¬rrdtoolÕâ¸öÈí¼þÐèÒªÓÃyumÀ´×°¡£·½·¨²½ÖèÈçÏ£º
      1>£ºwget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
      2>£º
rpm -ivh rpmforge-release-0.3.6-1. ......

linux manµÄÓ÷¨

man -k    [keyword ]    ÔÚwhatis Êý¾Ý¿âÖвéÕҹؼü×Ö£»
•man -f     [keyword ]    ͬÉÏ£¬µ«keyword Ϊһ¸öÕû×Ö(whole word)
•man -a    [keyword ]    ͨ³£man »áÏÔʾµÚÒ»¸öÕÒµ½µÄkeywordµÄman page£¬µ« ......

ÉîÈëÀí½âLinuxÄÚºËÖеÄÁ´±í

  ×î½ü£¬¿ªÊ¼ÑжÁÒ»ÏÂLinuxµÄÄں˴úÂ룬¸ÕÒ»¿ªÊ¼£¬¾ÍÓÐÁîÈ˾ªÌ¾µÄ·¢ÏÖ£¬²»µÃ²»¸Ð̾Äں˴úÂëÉè¼ÆµÃÖ®ÃÀ£¡µ¥ÊÇ×î³£ÓõÄÁ´±íÒ²Éè¼ÆµÃ²»µÃ²»ÁîÈËÅå·þ£¡
1.1.Á´±ílist_head
    include/linux/list.h
    ºÜ¾­µä£¬Á´±íÔÚÄÚºËÖкܳ£Óã¬ÀýÈç¹ÜÀí½ø³Ì£¬½ø³ÌµÄ¸÷¸ö״̬¶ÓÁж¼ÊÇʹÓÃÕâ¸öË«ÏòÁ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ