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 º¯Êý£¬Ëü´ÓÎļþ¶
Ïà¹ØÎĵµ£º
1. HCI²ãÐÒé¸ÅÊö£º
HCIÌṩһÌ×ͳһµÄ·½·¨À´·ÃÎÊBluetoothµ×²ã¡£ÈçͼËùʾ£º
´ÓͼÉÏ¿ÉÒÔ¿´³ö£¬Host Controller Interface(HCI) ¾ÍÊÇÓÃÀ´¹µÍ¨HostºÍModule¡£Hostͨ³£¾ÍÊÇPC£¬ ModuleÔòÊÇÒÔ¸÷ÖÖÎïÀíÁ¬½ÓÐÎʽ£¨USB,serial,pc-cardµÈ£©Á¬½Óµ½PCÉϵÄbluetooth Dongle¡£
ÔÚHostÕâÒ»¶Ë£ºapplication,SDP,L2capµÈÐÒé ......
Service Discovery Protocol(SDP)ÌṩһÖÖÄÜÁ¦£¬ÈÃÓ¦ÓóÌÐòÓз½·¨·¢ÏÖÄÄÖÖ·þÎñ¿ÉÓÃÒÔ¼°ÕâÖÖ·þÎñµÄÌØÐÔ¡£
·þÎñ·¢ÏÖÐÒé(SDP»òBluetooth SDP)ÔÚÀ¶ÑÀÐÒéÕ»ÖжÔÀ¶ÑÀ»·¾³ÖеÄÓ¦ÓóÌÐòÓÐÌØÊâµÄº¬Ò⣬·¢ÏÖÄĸö·þÎñÊÇ¿ÉÓõĺÍÈ·¶¨ÕâЩ¿ÉÓ÷þÎñµÄÌØÕ÷¡£SDP¶¨ÒåÁËbluetooth client·¢ÏÖ¿ÉÓÃbluetooth server·þÎñºÍËüÃǵÄÌØÕ÷µÄ·½·¨¡£ ......
ÔÌû¼ûhttp://www.inthirties.com/thread-685-1-1.html
1¡¢Ê²Ã´ÂãÉ豸£¿×Ö·ûÉ豸£¿¿éÉ豸£¿
ÂãÉ豸£ºÒ²½ÐÂã·ÖÇø£¨Ôʼ·ÖÇø£©£¬ÊÇÒ»ÖÖûÓо¹ý¸ñʽ»¯£¬²»±»Unix/Linuxͨ¹ýÎļþϵͳÀ´¶ÁÈ¡µÄÌØÊâ×Ö·ûÉ豸¡£ÂãÉ豸¿ÉÒÔ°ó¶¨Ò»¸ö·ÖÇø£¬Ò²¿ÉÒÔ°ó¶¨Ò»¸ö´ÅÅÌ¡£
×Ö·ûÉ豸£º¶Ô×Ö·ûÉ豸µÄ¶Áд²»ÐèҪͨ¹ýOSµÄbuffer ......
LinuxÐźÅÓжàÖÖ˵·¨¡£Ò»¸ö½ø³Ì´´½¨Ò»¸öÐźÅÓÃÓÚ·¢Ë͸øÁíÍâÒ»¸ö½ø³Ì½Ð×ö·¢ËÍÒ»¸öÐźţ¬Äں˴´½¨Ò»¸öÐźŽÐ×öÉú³ÉÒ»¸öÐźţ¬½ø³Ì×Ô¼ºÏò×Ô¼º·¢ËÍÐźŽÐ×ö»½ÆðÒ»¸öÐźš£²»¹ýÎÒ¿´Ò²Ã»±ØÒªÕâôѧ¾¿Æø¡£
Ðźż¯--signel set,Æäʵ¾ÍÊǽ«¶à¸öÐźŷÅÔÚ¼¯ºÏÖнøÐм¯ÖеĴ¦Àí¡£POSIX.1¶¨ÒåÁËsigset_tÒÔ°üºÒ»¸öÐźż¯£ ......
ǶÈëʽϵͳ´î½¨¹ý³ÌÖУ¬¶ÔÓÚϵͳƽ̨´î½¨¹¤³ÌʦÔÚÍê³ÉBootloader
µÄµ÷ÊÔÖ®ºó¾Í½øÈëKernel
²Ã¼õÒÆÖ²µÄ½×¶Î£¬ÆäÖÐ×îÖØÒªµÄÒ»²½ÊÇKernel
Æô¶¯µÄµ÷ÊÔ£¬ÔÚµ÷ÊÔKernel
¹ý³ÌÖÐͨ³£Óöµ½×î³£¼ûµÄÎÊÌâÊÇÆô¶¯Òì³£:
Uncompressing Linux............................................................
......................... ......