Linux Ì×½Ó×Ö±à³ÌÖÐµÄ 5 ¸öÒþ»¼
Linux Ì×½Ó×Ö±à³ÌÖÐµÄ 5 ¸öÒþ»¼
ÔÚÒì¹¹»·¾³Öпª·¢¿É¿¿µÄÍøÂçÓ¦ÓóÌÐò
¼¶±ð£º Öм¶
M. Tim Jones
(mtj@mtjones.com
), ×ÊÉîÈí¼þ¹¤³Ìʦ, Emulex
2005 Äê 10 ÔÂ 08 ÈÕ
Socket API ÊÇÍøÂçÓ¦ÓóÌÐò¿ª·¢ÖÐʵ¼ÊÓ¦Óõıê×¼ API¡£¾¡¹Ü¸Ã API ¼òµ¥£¬µ«ÊÇ¿ª·¢ÐÂÊÖ¿ÉÄÜ»á¾ÀúһЩ³£¼ûµÄÎÊÌâ¡£±¾ÎÄʶ±ðһЩ×î³£¼ûµÄÒþ»¼²¢ÏòÄúÏÔʾÈçºÎ±ÜÃâËüÃÇ¡£
ÔÚ 4.2 BSD UNIX® ²Ù×÷ϵͳÖÐÊ×´ÎÒýÈ룬Sockets API ÏÖÔÚÊÇÈκβÙ×÷ϵͳµÄ±ê×¼ÌØÐÔ¡£ÊÂʵÉÏ£¬ºÜÄÑÕÒµ½Ò»ÖÖ²»Ö§³Ö Sockets API µÄÏÖ´úÓïÑÔ¡£¸Ã API Ï൱¼òµ¥£¬µ«ÐµĿª·¢ÈËÔ±ÈÔÈ»»áÓöµ½Ò»Ð©³£¼ûµÄÒþ»¼¡£
±¾ÎÄʶ±ðÄÇЩÒþ»¼²¢ÏòÄúÏÔʾÈçºÎ±Ü¿ªËüÃÇ¡£
Òþ»¼ 1£®ºöÂÔ·µ»Ø״̬
µÚÒ»¸öÒþ»¼ºÜÃ÷ÏÔ£¬µ«ËüÊÇ¿ª·¢ÐÂÊÖ×îÈÝÒ×·¸µÄÒ»¸ö´íÎó¡£Èç¹ûÄúºöÂÔº¯ÊýµÄ·µ»Ø״̬£¬µ±ËüÃÇʧ°Ü»ò²¿·Ö³É¹¦µÄʱºò£¬ÄúÒ²Ðí»áÃÔʧ¡£·´¹ýÀ´£¬Õâ¿ÉÄÜ´«²¥´íÎó£¬Ê¹¶¨Î»ÎÊÌâµÄÔ´Í·±äµÃÀ§ÄÑ¡£
²¶»ñ²¢¼ì²éÿһ¸ö·µ»Ø״̬£¬¶ø²»ÊǺöÂÔËüÃÇ¡£¿¼ÂÇÇåµ¥ 1 ÏÔʾµÄÀý×Ó£¬Ò»¸öÌ×½Ó×Ö send
º¯Êý¡£
Çåµ¥ 1. ºöÂÔ API º¯Êý·µ»Ø״̬
int status, sock, mode;
/* Create a new stream (TCP) socket */
sock = socket
( AF_INET, SOCK_STREAM, 0 );
...
status = send
( sock, buffer, buflen, MSG_DONTWAIT );
if (status == -1) {
/* send failed */
printf( "send failed: %s\n", strerror(errno) );
} else {
/* send succeeded -- or did it? */
}
Çåµ¥ 1 ̽¾¿Ò»¸öº¯ÊýƬ¶Ï£¬ËüÍê³ÉÌ×½Ó×Ö send
²Ù×÷£¨Í¨¹ýÌ×½Ó×Ö·¢ËÍÊý¾Ý£©¡£º¯ÊýµÄ´íÎó״̬±»²¶»ñ²¢²âÊÔ£¬µ«Õâ¸öÀý×ÓºöÂÔÁË send
ÔÚÎÞ×èÈûģʽ£¨ÓÉ MSG_DONTWAIT
±êÖ¾ÆôÓã©ÏµÄÒ»¸öÌØÐÔ¡£
send
API º¯ÊýÓÐÈýÀà¿ÉÄܵķµ»ØÖµ£º
Èç¹ûÊý¾Ý³É¹¦µØÅŵ½´«Êä¶ÓÁУ¬Ôò·µ»Ø 0¡£
Èç¹ûÅŶÓʧ°Ü£¬Ôò·µ»Ø -1£¨Í¨¹ýʹÓà errno
±äÁ¿¿ÉÒÔÁ˽âʧ°ÜµÄÔÒò£©¡£
Èç¹û²»ÊÇËùÓеÄ×Ö·û¶¼Äܹ»ÔÚº¯Êýµ÷ÓÃʱÅŶӣ¬Ôò×îÖյķµ»ØÖµÊÇ·¢Ë͵Ä×Ö·ûÊý¡£
ÓÉÓÚ send
µÄ MSG_DONTWAIT
±äÁ¿µÄÎÞ×èÈûÐÔÖÊ£¬º¯Êýµ÷ÓÃÔÚ·¢ËÍÍêËùÓеÄÊý¾Ý¡¢Ò»Ð©Êý¾Ý»òûÓз¢ËÍÈκÎÊý¾Ýºó·µ»Ø¡£ÔÚÕâÀïºöÂÔ·µ»Ø״̬½«µ¼Ö²»ÍêÈ«µÄ·¢ËͺÍËæºóµÄÊý¾Ý¶ªÊ§¡£
»ØÒ³Ê×
Òþ»¼ 2£®¶ÔµÈÌ×½Ó×Ö±Õ°ü
UNIX ÓÐȤµÄÒ»ÃæÊÇÄú¼¸ºõ¿ÉÒÔ°ÑÈκζ«Î÷¿´³ÉÊÇÒ»¸öÎļþ¡£Îļþ±¾Éí¡¢Ä¿Â¼¡¢¹ÜµÀ¡¢É豸ºÍÌ×½Ó×Ö¶¼±»µ±×÷Îļþ¡£ÕâÊÇÐÂÓ±µÄ³éÏó£¬Òâζ×ÅÒ»ÕûÌ×µÄ API ¿ÉÒÔÓÃÔڹ㷺µÄÉ豸ÀàÐÍÉÏ¡£
¿¼ÂÇ read
API º¯Êý£¬Ëü´ÓÎļþ¶
Ïà¹ØÎĵµ£º
ÀýÒ»£º·¢ËÍ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 ......
1. ѧ»áд¼òµ¥µÄmakefile
2. ±àһЩӦÓÃ
³ÌÐò
£¬¿ÉÒÔÓÃmakefileÅÜÆðÀ´
3. ѧ»áдÇý¶¯
µÄmakefile
4. дһ¼òµ¥charÇý¶¯£¬makefile±àÒëͨ¹ý£¬¿ÉÒÔinsmod£¬ lsmod£¬ rmmod. ÔÚÇý¶¯µÄinitº¯ÊýÀï´òÓ¡hello world£¬insmodºóÓ¦¸ÃÄܹ»Í¨¹ýdmesg¿´µ½Êä³ö
¡£
5. дһÍêÕûÇý¶¯£¬ ¼ÓÉÏread£¬ write£¬ ioctl£¬ pollingµÈ¸ ......
LinuxÐźÅÓжàÖÖ˵·¨¡£Ò»¸ö½ø³Ì´´½¨Ò»¸öÐźÅÓÃÓÚ·¢Ë͸øÁíÍâÒ»¸ö½ø³Ì½Ð×ö·¢ËÍÒ»¸öÐźţ¬Äں˴´½¨Ò»¸öÐźŽÐ×öÉú³ÉÒ»¸öÐźţ¬½ø³Ì×Ô¼ºÏò×Ô¼º·¢ËÍÐźŽÐ×ö»½ÆðÒ»¸öÐźš£²»¹ýÎÒ¿´Ò²Ã»±ØÒªÕâôѧ¾¿Æø¡£
Ðźż¯--signel set,Æäʵ¾ÍÊǽ«¶à¸öÐźŷÅÔÚ¼¯ºÏÖнøÐм¯ÖеĴ¦Àí¡£POSIX.1¶¨ÒåÁËsigset_tÒÔ°üºÒ»¸öÐźż¯£ ......
×î½ü¿ªÊ¼×ªÏòLinux¿ª·¢£¬ÐèÒªÓõ½¶àÏ̡߳£ÉÏÍøÒ»²é£¬ÓеÄÈË˵LinuxûÓÐÏß³ÌÖ»Óнø³Ì£¬ÓеÄÈË˵Linuxµ±È»ÓÐỊ̈߳¬Ã»ÓÐÏß³Ìpthread¿âÊǸÉÂðµÄ£¿NPTLÓÖÊǸÉÂïÓã¿
¸öÈ˾õµÃ£¬Òª¿´´ÓÄĸö½Ç¶ÈÀ´¿´Õâ¸öÎÊÌâ¡£¶ÔÓÚÒ»°ãÓ¦ÓÃÈí¼þ¿ª·¢ÈËÔ±µÄ½Ç¶ÈÀ´¿´£¬¼ÈÈ»ÄÜÓÃpthread¿âÀ´´´½¨Ị̈߳¬ÒÔ¼°¿ÉÒÔ´¦ÀíÏ̼߳äµÄͨÐÅ£¬µ±È»¿ÉÒÔÈÏΪÔÚL ......