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

linux—selectÏê½â

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)){
   


Ïà¹ØÎĵµ£º

ʵսLinux Bluetooth±à³Ì(Áù) L2CAP±à³ÌʵÀý

ÀýÒ»£º·¢ËÍSignaling Packet£º
Signaling CommandÊÇ2¸öBluetoothʵÌåÖ®¼äµÄL2CAP²ãÃüÁî´«Êä¡£ËùÒÔµÃSignaling CommandʹÓÃCID 0x0001.
¶à¸öCommand¿ÉÒÔÔÚÒ»¸öC-frame£¨control frame£©Öз¢ËÍ¡£
 Èç¹ûÒªÖ±½Ó·¢ËÍSignaling Command.ÐèÒª½¨Á¢SOCK_RAWÀàÐ͵ÄL2CAPÁ¬½ÓSocket¡£ÕâÑù²ÅÓлú»á×Ô¼ºÌî³äCommand Code£¬Identi ......

linux ±à³ÌÖ®¿âµÄʹÓã¨Ñ§Ï°±Ê¼Ç£©

1.¿â¸ÅÊö
¿â¿ÉÒÔ·ÖΪ¾²Ì¬¿âºÍ¶¯Ì¬¿â£¬¾²Ì¬¿â±àÒëʱ±ØÐë´æÔÚ£¬³ÌÐòÔËÐÐʱ²»ÐèÒª¡£
¶¯Ì¬¿âÒ²³Æ¹²Ïí¿â£¬Æä´úÂë²»»áÁ´½Óµ½Ä¿±êÎļþÖ®ÖУ¬Ö»Ó屶¯Ì¬¿â¿É·ÃÎÊʱ£¬Ó¦ÓóÌÐò²ÅÄÜÕýÈ·µØÖ´Ðж¯Ì¬¿âº¯Êý¡£Ö´Ðж¯Ì¬¿âÓÐÁ½ÖÖ·½Ê½£ºÒþʽµ÷ÓúÍÏÔʾµ÷Óá£Òþʽµ÷ÓÃÒ²³Æ¹²Ïí¿âµÄ¾²Ì¬¼ÓÔØ£¬¶¯Ì¬¿âº¯ÊýÔÚÓ¦ÓóÌÐò¿ªÊ¼Ö´ÐÐʱ»á×Ô¶¯ÔØÈëÄڴ棬 ......

linuxÐźŻúÖÆ


linuxÐźŻúÖÆ
 
 
ÐźÅÌṩÁËÒ»ÖÖ֪ͨ½ø³Ìϵͳʼþ·¢ÉúµÄ»úÖÆ£¬ËüÒ²ÊÇ×÷ΪÓû§½ø³ÌÖ®¼äͨÐźÍͬ²½µÄ
Ò»ÖÖԭʼ»úÖÆ¡£ÔÚ½ø³ÌǨÒƵÄÇé¿öÏ£¬ÈçºÎ´¦ÀíÐźÅÄØ£¿Õⲿ·Ö½éÉÜÁËMOSIXϵͳ¶ÔÐźÅ
»úÖƵĴ¦Àí¡£
LINUXÐźŻúÖÆ
ÐźÅÊÇÒì²½µÄ½ø³Ì¼äͨѶ»úÖÆ,ÊÇÔÚÈí¼þ²ã´ÎÉ϶ÔÖжϻúÖƵÄÒ»ÖÖÄ£Äâ¡£LINUXÄں˵ÄÐÅ
ºÅ» ......

Linux¼¼Êõѧϰroadmap

Linux³õ¼¶
linuxͼÐνçÃæʹÓÃ
linux¼òµ¥Ä¿Â¼½á¹¹
linux³£ÓÃÃüÁî
linuxϵͳ°²×°
LinuxÖм¶
linuxÓû§/Îļþϵͳ¹ÜÀí
linuxÍøÂç¹ÜÀí
linux´ÅÅ̹ÜÀí
linuxϵͳºÍÈÕ¼Çά»¤¹ÜÀí
linux°²È«ÓÅ»¯
linuxϵͳ±¸·ÝÓë»Ö¸´
shell³õ²½±à³Ì
linux¸ß¼¶
Linux·þÎñÆ÷
Linux Dns·þÎñÆ÷
Linux Mail·þÎñÆ÷
Linux Web·þÎ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ