關(guān)于我們
書(shū)單推薦
新書(shū)推薦
|
高質(zhì)量嵌入式Linux C編程(第2版) 讀者對(duì)象:本書(shū)既可作為大專(zhuān)院校相關(guān)專(zhuān)業(yè)師生的教學(xué)參考書(shū),也可供計(jì)算機(jī)及其相關(guān)領(lǐng)域的工程技術(shù)人員查閱之用,對(duì)于普通計(jì)算機(jī)愛(ài)好者,本書(shū)也不失為幫助他們掌握嵌入式Linux C高質(zhì)量系統(tǒng)開(kāi)發(fā)的一本深入淺出的嵌入式開(kāi)發(fā)讀物。
本書(shū)從嵌入式開(kāi)發(fā)角度出發(fā),以Linux操作系統(tǒng)為開(kāi)發(fā)平臺(tái),將隱藏在系統(tǒng)開(kāi)發(fā)背后的關(guān)于C語(yǔ)言、數(shù)據(jù)結(jié)構(gòu)與算法、計(jì)算機(jī)組成原理、計(jì)算機(jī)操作系統(tǒng)、數(shù)據(jù)庫(kù)原理等方面的機(jī)制和知識(shí)娓娓道來(lái),不僅讓讀者知其然,更要讓讀者知其所以然,并讓這些知識(shí)再反作用于編程實(shí)踐,從而幫助讀者寫(xiě)出高質(zhì)量的嵌入式Linux C代碼,揭開(kāi)嵌入式Linux C系統(tǒng)開(kāi)發(fā)背后鮮為人知的秘密。
梁庚,男,畢業(yè)于四川大學(xué)軟件工程專(zhuān)業(yè),現(xiàn)為南京優(yōu)奈特信息科技有限公司研發(fā)工程師,南京工業(yè)大學(xué)外聘講師,金陵科技學(xué)院外聘講師,主要從事嵌入式系統(tǒng)的研發(fā)工作。
第 1 章 嵌入式Linux C 語(yǔ)言開(kāi)發(fā)工具··········································································(1)
1.1 嵌入式Linux C 語(yǔ)言開(kāi)發(fā)概述·················································································(1) 1.2 嵌入式Linux C 開(kāi)發(fā)環(huán)境·······················································································(2) 1.3 嵌入式文本編輯器··························································································(2) 1.3.1 基本模式································································································. (3) 1.3.2 基本操作··································································································(3) 1.3.3 實(shí)訓(xùn)操作··································································································(5) 1.4 嵌入式編譯器······································································································(6) 1.4.1 初識(shí)GCC 編譯器························································································(6) 1.4.2 gcc 命令常用選項(xiàng)和工作流程·········································································(6) 1.4.3 庫(kù)的使用·······························································································.(10) 1.5 嵌入式調(diào)試器···································································································.(12) 1.6 工程管理器······································································································.(15) 1.6.1 Makefile·································································································.(16) 1.6.2 Makefile 特性介紹····················································································.(18) 1.7 Eclipse 程序開(kāi)發(fā)·······························································································.(27) 1.7.1 Eclipse 環(huán)境安裝······················································································.(27) 1.7.2 Eclipse C 程序開(kāi)發(fā)···················································································.(29) 1.8 軟件版本管理···································································································.(34) 1.8.1 Git 版本管理···························································································.(34) 1.8.2 Ubuntu 軟件包管理···················································································.(45) 第 2 章 數(shù)據(jù)類(lèi)型··································································································.(48) 2.1 變量與常量······································································································.(48) 2.2 變量···············································································································.(48) 2.2.1 什么是變量····························································································.(48) 2.2.2 變量名和變量值······················································································.(49) 2.2.3 局部變量和全局變量················································································.(51) 2.3 常量···············································································································.(53) 2.4 基本內(nèi)置類(lèi)型···································································································.(54) 2.4.1 數(shù)據(jù)類(lèi)型及其大小···················································································.(55) 2.4.2 陷阱——有符號(hào)與無(wú)符號(hào)·············································································.(55) 2.5 聲明與定義······································································································.(56) 2.5.1 定義·····································································································.(56) 2.5.2 聲明·····································································································.(57) 2.6 static 與extern····················································································.(57) 2.6.1 static ························································································.(57) 2.6.2 extern ······································································.·······.·······.(59) 2.7 const ··································································································.(60) 2.8 auto·································································································.(61) 2.9 register·····························································································.(62) 2.10 volatile ···························································································.(63) 2.11 typedef 詳解····································································································.(64) 2.11.1 typedef 與結(jié)構(gòu)的問(wèn)題··············································································.(64) 2.11.2 typedef 與#define 的問(wèn)題··········································································.(66) 2.11.3 typedef 與#define 的另一例·······································································.(67) 2.11.4 typedef 與復(fù)雜的變量聲明········································································.(67) 2.12 枚舉(enum)·································································································.(68) 2.12.1 枚舉類(lèi)型的使用方法···············································································.(68) 2.12.2 枚舉與#define 宏的區(qū)別··········································································.(69) 2.13 聯(lián)合體··········································································································.(69) 2.13.1 聯(lián)合體的定義························································································.(69) 2.13.2 從兩道經(jīng)典試題談聯(lián)合體(union)的使用···················································.(70) 第 3 章 運(yùn)算符和表達(dá)式·····················································································(73) 3.1 運(yùn)算符簡(jiǎn)介································································································.(73) 3.1.1 運(yùn)算符優(yōu)先級(jí)·························································································.(73) 3.1.2 一些容易出錯(cuò)的優(yōu)先級(jí)問(wèn)題·······································································.(75) 3.1.3 邏輯運(yùn)算符····························································································.(76) 3.2 條件運(yùn)算符和條件表達(dá)式····················································································.(76) 3.3 ++、--操作符···································································································.(77) 3.4 位運(yùn)算············································································································.(78) 3.4.1 按位與運(yùn)算及應(yīng)用···················································································.(78) 3.4.2 按位或運(yùn)算及應(yīng)用···················································································.(79) 3.4.3 按位異或運(yùn)算及應(yīng)用················································································.(79) 3.4.4 左移和右移····························································································.(79) 3.5 C 語(yǔ)言性能優(yōu)化:使用位操作········································································.(79) 第 4 章 語(yǔ)句···································································································.(81) 4.1 空語(yǔ)句·······································································································.(81) 4.2 基礎(chǔ)語(yǔ)句···································································································.(82) 4.2.1 表達(dá)式語(yǔ)句····························································································. (82) 4.2.2 函數(shù)調(diào)用語(yǔ)句·························································································.(82) 4.3 if 語(yǔ)句······································································································.(82) 4.3.1 布爾變量與零值的比較·············································································.(83) 4.3.2 整型變量與零值比較················································································.(83) 4.3.3 浮點(diǎn)變量與零值的比較·············································································.(83) 4.3.4 指針變量與零值的比較·············································································.(84) 4.3.5 對(duì)if 語(yǔ)句的補(bǔ)充說(shuō)明················································································.(84) 4.4 跳轉(zhuǎn)語(yǔ)句:goto ································································································.(85) 4.5 循環(huán)語(yǔ)句·········································································································.(85) 4.5.1 do-while 語(yǔ)句··························································································.(86) 4.5.2 for 語(yǔ)句·································································································.(86) 4.5.3 循環(huán)語(yǔ)句的效率······················································································.(88) 4.6 break 和continue ·······················································································.(89) 4.6.1 break 語(yǔ)句······························································································.(89) 4.6.2 continue 語(yǔ)句··························································································.(90) 4.7 switch 語(yǔ)句·································································································.(91) 第 5 章 數(shù)組與指針···························································································.(92) 5.1 數(shù)組認(rèn)知·····································································································.(92) 5.2 使用數(shù)組的常見(jiàn)問(wèn)題······················································································.(93) 5.2.1 數(shù)組的下標(biāo)總是從0 開(kāi)始嗎··························································. ············.(93) 5.2.2 可以使用數(shù)組后面第一個(gè)元素的地址嗎···············································. ········.(94) 5.2.3 為什么要小心對(duì)待位于數(shù)組后面的那些元素的地址呢··········································.(95) 5.2.4 當(dāng)數(shù)組作為參數(shù)傳遞給函數(shù)時(shí),可以通過(guò)sizeof 得到數(shù)組的大小嗎························.(95) 5.2.5 指針或帶下標(biāo)的數(shù)組名都可以訪問(wèn)元素,哪一種更好呢···································.····(96) 5.2.6 可以把另外一個(gè)地址賦給一個(gè)數(shù)組名嗎·····························································(98) 5.2.7 array_name 和&array_name 有什么不同·························································.(99) 5.2.8 為什么用const 說(shuō)明的常量不能用來(lái)定義一個(gè)數(shù)組的初始大小····························(100) 5.2.9 字符串和數(shù)組有什么不同··········································································(100) 5.3 指針···············································································································(102) 5.3.1 指針是變量····························································································(103) 5.3.2 指針的類(lèi)型和指針?biāo)赶虻念?lèi)型·································································(103) 5.3.3 指針的值·······························································································(104) 5.3.4 指針本身所占據(jù)的內(nèi)存·············································································(105) 5.4 指針的運(yùn)算······································································································(105) 5.4.1 指針的算術(shù)運(yùn)算······················································································(105) 5.4.2 指針的關(guān)系運(yùn)算······················································································(106) 5.4.3 間接引用·······························································································(106) 5.4.4 最多可以使用幾層指針·············································································(106) 5.5 常量指針和指針常量··························································································(108) 5.5.1 常量指針與指針常量的實(shí)例·······································································(108) 5.5.2 常量指針的應(yīng)用······················································································(109) 5.6 空指針及其使用································································································(110) 5.6.1 NULL 總是被定義為0 嗎···········································································(110) 5.6.2 NULL 總是等于0 嗎·················································································(110) 5.6.3 空指針的使用·························································································(111) 5.7 void 指針:萬(wàn)能指針··························································································(113) 5.8 指針數(shù)組與數(shù)組指針··························································································(114) 5.9 字符串函數(shù)詳解································································································(114) 5.10 函數(shù)指針與指針函數(shù)························································································(119) 5.11 復(fù)雜指針聲明:“int * (* (*fp1) (int) ) [10];” ···························································(120) 5.11.1 基礎(chǔ)····································································································(120) 5.11.2 const 修飾符··························································································(121) 5.11.3 typedef 的妙用·······················································································(122) 5.11.4 函數(shù)指針······························································································(123) 5.11.5 右左法則······························································································(123) 第 6 章 內(nèi)存管理································································································(125) 6.1 數(shù)據(jù)放在哪里···································································································(125) 6.1.1 未初始化的全局變量(.bss 段) ··································································(125) 6.1.2 初始化過(guò)的全局變量(.data 段) ·································································(126) 6.1.3 常量數(shù)據(jù)(.rodata 段) ·············································································(126) 6.1.4 代碼(.text 段) ······················································································(127) 6.1.5 棧(stack) ····························································································(127) 6.1.6 堆(heap)·····························································································(127) 6.2 內(nèi)存分配方式···································································································(128) 6.3 野指針············································································································(129) 6.4 常見(jiàn)的內(nèi)存錯(cuò)誤及對(duì)策·······················································································(129) 6.5 段錯(cuò)誤及其調(diào)試方法··························································································(130) 6.5.1 方法一:利用gdb 逐步查找段錯(cuò)誤······························································(131) 6.5.2 方法二:分析core 文件·············································································(131) 6.5.3 方法三:在發(fā)生段錯(cuò)誤時(shí)啟動(dòng)調(diào)試······························································(132) 6.5.4 方法四:利用backtrace 和objdump 進(jìn)行分析·················································(134) 6.6 指針與數(shù)組的對(duì)比·····························································································(135) 第 7 章 預(yù)處理和結(jié)構(gòu)體···························································································(138) 7.1 宏定義:#define································································································(138) 7.1.1 無(wú)參宏定義····························································································(138) 7.1.2 帶參宏定義····························································································(140) 7.2 文件包含·········································································································(141) 7.3 條件編譯·········································································································(142) 7.4 宏定義的使用技巧·····························································································(144) 7.5 關(guān)于#和## ·······································································································(146) 7.6 結(jié)構(gòu)體(struct) ·······························································································(147) 7.6.1 內(nèi)存字節(jié)對(duì)齊·························································································(149) 7.6.2 內(nèi)存對(duì)齊的正式原則················································································(152) 7.7 #define 和typedef 的區(qū)別·····················································································(152) 7.8 結(jié)構(gòu)體(struct)和聯(lián)合體(union)的區(qū)別·····························································(153) 7.9 淺談C 語(yǔ)言中的位段·························································································(153) 7.9.1 位段的使用····························································································(154) 7.9.2 位段結(jié)構(gòu)在內(nèi)存中的存儲(chǔ)方式····································································(154) 第 8 章 函數(shù)········································································································(155) 8.1 函數(shù)聲明與定義································································································(155) 8.1.1 定義·····································································································(155) 8.1.2 聲明與定義不同······················································································(156) 8.2 形式參數(shù)和實(shí)際參數(shù)··························································································(157) 8.3 參數(shù)傳遞·········································································································(157) 8.3.1 簡(jiǎn)單變量或數(shù)組元素作為函數(shù)參數(shù)······························································(157) 8.3.2 指針變量或數(shù)組名作為函數(shù)參數(shù)·································································(158) 8.3.3 數(shù)組名作為函數(shù)參數(shù)················································································(159) 8.3.4 結(jié)構(gòu)體數(shù)組作為函數(shù)參數(shù)··········································································(160) 8.4 如何編寫(xiě)有多個(gè)返回值的C 語(yǔ)言函數(shù)····································································(160) 8.4.1 利用全局變量·························································································(161) 8.4.2 傳遞數(shù)組指針·························································································(162) 8.4.3 傳遞結(jié)構(gòu)體指針······················································································(162) 8.5 回調(diào)函數(shù)·········································································································(163) 8.6 變參函數(shù)詳解:printf 函數(shù)的實(shí)現(xiàn)·········································································(165) 8.7 可變參數(shù)的相關(guān)問(wèn)題··························································································(166) 第 9 章 編碼規(guī)范··································································································(170) 9.1 排版···············································································································(170) 9.2 注釋···············································································································(173) 9.3 標(biāo)示符名稱(chēng)······································································································(178) 第 10 章 shell 編程································································································(181) 10.1 什么是shell ····································································································(181) 10.2 幾種流行的shell ······························································································(181) 10.3 shell 程序設(shè)計(jì)(基礎(chǔ)部分) ···········································································(182) 10.3.1 shell 的基本語(yǔ)法·····················································································(182) 10.3.2 shell 程序的變量和參數(shù)············································································(183) 10.4 shell 程序設(shè)計(jì)的流程控制··················································································(185) 10.4.1 test 命令·······························································································(185) 10.4.2 if 條件語(yǔ)句···························································································(186) 10.4.3 for 循環(huán)································································································(187) 10.4.4 while 和until 循環(huán)···················································································(187) 10.4.5 case 條件選擇························································································(189) 10.4.6 無(wú)條件控制語(yǔ)句break 和continue·······························································(189) 10.4.7 函數(shù)定義······························································································(189) 10.5 命令分組·······································································································(190) 10.6 用trap 命令捕捉信號(hào)························································································(190) 10.7 運(yùn)行shell 程序的方法·······················································································(191) 10.8 bash 程序的調(diào)試······························································································(191) 10.9 bash 的內(nèi)部命令······························································································(192) 第 11 章 文件操作·································································································(194) 11.1 Linux 文件結(jié)構(gòu)·······························································································(194) 11.1.1 Linux 文件系統(tǒng)······················································································(194) 11.1.2 Linux 目錄結(jié)構(gòu)······················································································(195) 11.1.3 Linux 文件分類(lèi)······················································································(197) 11.1.4 常見(jiàn)的文件類(lèi)型·····················································································(198) 11.1.5 Linux 文件屬性······················································································(198) 11.2 系統(tǒng)調(diào)用·······································································································(198) 11.3 Linux 文件描述符····························································································(199) 11.4 不帶緩存的I/O 操作·························································································(200) 11.4.1 creat 函數(shù)·····························································································(200) 11.4.2 open 函數(shù)·····························································································(201) 11.4.3 read 函數(shù)······························································································(203) 11.4.4 write 函數(shù)·····························································································(204) 11.4.5 lseek 函數(shù)·····························································································(204) 11.4.6 close 函數(shù)·····························································································(205) 11.4.7 經(jīng)典范例:文件復(fù)制···············································································(205) 11.5 帶緩存的I/O 操作····························································································(207) 11.5.1 3 種類(lèi)型的緩沖······················································································(207) 11.5.2 fopen 函數(shù)····························································································(209) 11.5.3 fclose 函數(shù)····························································································(209) 11.5.4 fdopen 函數(shù)···························································································(210) 11.5.5 fread 函數(shù)·····························································································(210) 11.5.6 fwrite 函數(shù)····························································································(211) 11.5.7 fseek 函數(shù)·····························································································(212) 11.5.8 fgetc 函數(shù)、getc 函數(shù)和getchar 函數(shù)···························································(213) 11.5.9 fputc 函數(shù)、putc 函數(shù)和putchar 函數(shù)···························································(214) 11.6 fgets 函數(shù)與gets 函數(shù)的比較分析········································································(215) 11.7 輸出與輸入····································································································(217) 11.7.1 printf 函數(shù)、fprintf 函數(shù)和sprintf 函數(shù)·························································(217) 11.7.2 scanf 函數(shù)、fcanf 函數(shù)和sscanf 函數(shù)···························································(220) 第12 章 進(jìn)程控制編程·····························································································(222) 12.1 為何需要多進(jìn)程(或者多線程),為何需要并發(fā)····················································(222) 12.1.1 進(jìn)程····································································································(222) 12.1.2 進(jìn)程分類(lèi)······························································································(223) 12.1.3 進(jìn)程的屬性···························································································(223) 12.1.4 父進(jìn)程和子進(jìn)程·····················································································(223) 12.2 Linux 進(jìn)程管理·······························································································(224) 12.2.1 ps 監(jiān)視進(jìn)程工具·····················································································(224) 12.2.2 pgrep 查詢(xún)進(jìn)程工具················································································(226) 12.2.3 終止進(jìn)程的工具kill、killall、pkill 和xkill····················································(226) 12.2.4 top 監(jiān)視系統(tǒng)任務(wù)的工具··········································································(228) 12.2.5 進(jìn)程的優(yōu)先級(jí):nice 和renice ····································································(229) 12.3 Linux 進(jìn)程的三態(tài)····························································································(230) 12.3.1 三種基本狀態(tài)························································································(230) 12.3.2 三種狀態(tài)間的轉(zhuǎn)換··················································································(231) 12.4 Linux 進(jìn)程結(jié)構(gòu)·······························································································(231) 12.5 Linux 進(jìn)程控制塊PCB ······················································································(232) 12.6 Linux 進(jìn)程調(diào)度·······························································································(233) 12.6.1 調(diào)度的目標(biāo)···························································································(233) 12.6.2 調(diào)度算法······························································································(233) 12.6.3 優(yōu)先級(jí)反轉(zhuǎn)···························································································(235) 12.7 進(jìn)程創(chuàng)建·······································································································(236) 12.7.1 獲取進(jìn)程······························································································(236) 12.7.2 啟動(dòng)進(jìn)程:fork( ) ···················································································(237) 12.7.3 啟動(dòng)進(jìn)程:vfork( )··················································································(240) 12.7.4 啟動(dòng)進(jìn)程:exec 族··················································································(241) 12.7.5 啟動(dòng)進(jìn)程:system···················································································(244) 12.8 進(jìn)程等待·······································································································(245) 12.8.1 僵尸進(jìn)程的產(chǎn)生·····················································································(245) 12.8.2 如何避免僵尸進(jìn)程··················································································(247) 12.8.3 wait 函數(shù)和waitpid 函數(shù)···········································································(247) 12.9 進(jìn)程退出·······································································································(251) 12.9.1 退出方式的不同點(diǎn)··················································································(252) 12.9.2 exit 函數(shù)和_exit 函數(shù)···············································································(252) 12.9.3 exit 函數(shù)和_exit 函數(shù)的區(qū)別······································································(253) 12.10 守護(hù)進(jìn)程······································································································(253) 12.10.1 守護(hù)進(jìn)程概述······················································································(253) 12.10.2 守護(hù)進(jìn)程的創(chuàng)建···················································································(254) 12.10.3 創(chuàng)建守護(hù)進(jìn)程的一般步驟·······································································(254) 12.10.4 利用庫(kù)函數(shù)daemon 創(chuàng)建守護(hù)進(jìn)程····························································(258) 第 13 章 進(jìn)程間通信方式·························································································(260) 13.1 進(jìn)程間通信方式概述························································································(260) 13.1.1 進(jìn)程間通信的目的··················································································(260) 13.1.2 Linux 進(jìn)程間通信方式簡(jiǎn)介·······································································(261) 13.2 管道通信·······································································································(262) 13.2.1 創(chuàng)建無(wú)名管道························································································(262) 13.2.2 讀寫(xiě)無(wú)名管道························································································(263) 13.2.3 無(wú)名管道應(yīng)用實(shí)例··················································································(267) 13.2.4 創(chuàng)建有名管道························································································(269) 13.2.5 讀寫(xiě)有名管道························································································(271) 13.3 管道通信方式的應(yīng)用場(chǎng)景··················································································(274) 13.4 信號(hào)·············································································································(275) 13.4.1 信號(hào)及信號(hào)來(lái)源·····················································································(275) 13.4.2 信號(hào)種類(lèi)······························································································(275) 13.4.3 信號(hào)處理方式························································································(277) 13.4.4 信號(hào)發(fā)送······························································································(277) 13.4.5 自定義信號(hào)處理方式···············································································(279) 13.4.6 信號(hào)集操作···························································································(284) 13.4.7 使用信號(hào)注意事項(xiàng)··················································································(285) 13.5 消息隊(duì)列·······································································································(287) 13.5.1 消息隊(duì)列基礎(chǔ)理論··················································································(287) 13.5.2 使用消息隊(duì)列························································································(288) 13.5.3 消息隊(duì)列API ························································································(289) 13.5.4 消息隊(duì)列的限制·····················································································(292) 13.5.5 消息隊(duì)列的應(yīng)用實(shí)例···············································································(292) 13.6 信號(hào)燈··········································································································(295) 13.6.1 信號(hào)燈概述···························································································(295) 13.6.2 內(nèi)核實(shí)現(xiàn)原理························································································(296) 13.6.3 使用信號(hào)燈···························································································(296) 13.6.4 信號(hào)燈API ···························································································(297) 13.6.5 信號(hào)燈的限制························································································(299) 13.6.6 競(jìng)爭(zhēng)問(wèn)題······························································································(299) 13.6.7 信號(hào)燈應(yīng)用實(shí)例·····················································································(300) 13.7 共享內(nèi)存方式一······························································································(303) 13.7.1 內(nèi)核實(shí)現(xiàn)原理························································································(304) 13.7.2 mmap( )及其相關(guān)系統(tǒng)調(diào)用········································································(304) 13.7.3 mmap( )范例··························································································(306) 13.7.4 對(duì)mmap( )返回地址的訪問(wèn)·······································································(310) 13.8 共享內(nèi)存方式二······························································································(312) 13.8.1 系統(tǒng)V 共享內(nèi)存原理··············································································(312) 13.8.2 系統(tǒng)V 共享內(nèi)存API···············································································(314) 13.8.3 系統(tǒng)V 共享內(nèi)存范例··············································································(314) 第 14 章 多線程編程·························································································(318) 14.1 線程概述···································································································(318) 14.1.1 為什么有了進(jìn)程的概念后,還要再引入線程呢··············································(318) 14.1.2 多線程的優(yōu)點(diǎn)························································································(319) 14.1.3 多線程的缺點(diǎn)························································································(319) 14.2 多線程的實(shí)現(xiàn)·································································································(320) 14.2.1 線程的創(chuàng)建···························································································(320) 14.2.2 終止線程······························································································(322) 14.2.3 等待線程終止························································································(323) 14.3 線程屬性·······································································································(324) 14.3.1 線程屬性初始化·····················································································(324) 14.3.2 線程分離······························································································(325) 14.3.3 線程的繼承性························································································(326) 14.3.4 線程的調(diào)度策略·····················································································(327) 14.3.5 線程的調(diào)度參數(shù)·····················································································(327) 14.3.6 實(shí)例分析······························································································(329) 14.4 線程同步機(jī)制·································································································(330) 14.4.1 互斥鎖(Mutex) ···················································································(330) 14.4.2 互斥鎖使用實(shí)例·····················································································(332) 14.4.3 條件變量(Conditions)···········································································(333) 14.4.4 條件變量使用實(shí)例··················································································(335) 第 15 章 網(wǎng)絡(luò)編程································································································(337) 15.1 TCP/IP 協(xié)議概述····························································································(337) 15.1.1 TCP/IP 協(xié)議的起源·················································································(337) 15.1.2 TCP/IP 協(xié)議的特性與應(yīng)用········································································(338) 15.1.3 互聯(lián)網(wǎng)地址···························································································(339) 15.1.4 域名系統(tǒng)······························································································(340) 15.1.5 封裝····································································································(340) 15.1.6 TCP/IP 協(xié)議的工作模型···········································································(341) 15.1.7 TCP/IP 協(xié)議層······················································································(342) 15.1.8 TCP/IP 協(xié)議的應(yīng)用·················································································(343) 15.1.9 網(wǎng)橋、路由器和網(wǎng)關(guān)···············································································(344) 15.2 TCP 和UDP ····························································································(345) 15.2.1 TCP ····································································································(345) 15.2.2 三次握手······························································································(346) 15.2.3 TCP 數(shù)據(jù)報(bào)頭························································································(347) 15.2.4 UDP ····································································································(348) 15.2.5 協(xié)議的選擇···························································································(348) 15.2.6 端口號(hào)和IP 地址····················································································(348) 15.3 套接字····································································································(349) 15.3.1 Socket 的概念························································································(349) 15.3.2 Socket 的類(lèi)型························································································(349) 15.3.3 Socket 的信息數(shù)據(jù)結(jié)構(gòu)············································································(349) 15.3.4 數(shù)據(jù)存儲(chǔ)優(yōu)先順序的轉(zhuǎn)換·········································································(350) 15.3.5 地址格式轉(zhuǎn)化························································································(351) 15.3.6 名字地址轉(zhuǎn)化························································································(352) 15.4 網(wǎng)絡(luò)編程··································································································(355) 15.4.1 建立Socket 通信····················································································(355) 15.4.2 綁定地址······························································································(356) 15.4.3 監(jiān)聽(tīng)····································································································(358) 15.4.4 接受請(qǐng)求······························································································(358) 15.4.5 連接服務(wù)器···························································································(359) 15.4.6 發(fā)送數(shù)據(jù)······························································································(360) 15.4.7 接收數(shù)據(jù)······························································································(362) 15.5 采用TCP 協(xié)議的C/S 架構(gòu)實(shí)現(xiàn)·····································································(363) 15.5.1 模塊封裝······························································································(363) 15.5.2 服務(wù)器端的實(shí)現(xiàn)·····················································································(365) 15.5.3 客戶(hù)端的實(shí)現(xiàn)························································································(366) 15.6 并發(fā)服務(wù)器模型························································································(367) 15.6.1 多進(jìn)程解決方案·····················································································(367) 15.6.2 多線程解決方案·····················································································(368) 15.6.3 調(diào)用fcntl 將sockfd 設(shè)置為非阻塞模式························································(374) 15.7 多路轉(zhuǎn)接模型······················································.··································(374) 15.7.1 服務(wù)器端的實(shí)現(xiàn)·····················································································(375) 15.7.2 客戶(hù)端的實(shí)現(xiàn)························································································(379) 15.8 采用UDP 的C/S 架構(gòu)的實(shí)現(xiàn)··············································································(381) 15.8.1 服務(wù)器端的實(shí)現(xiàn)·····················································································(381) 15.8.2 客戶(hù)端的實(shí)現(xiàn)························································································(382) 15.8.3 UDP 傳輸文件的實(shí)現(xiàn)··············································································(383) 第 16 章 SQLite3 數(shù)據(jù)庫(kù)編程··················································································(386) 16.1 SQLite 數(shù)據(jù)庫(kù)簡(jiǎn)介···························································································(386) 16.2 SQLite3 的命令·······························································································(387) 16.3 SQLite 編程接口······························································································(389) 16.3.1 數(shù)據(jù)庫(kù)的打開(kāi)與關(guān)閉···············································································(389) 16.3.2 數(shù)據(jù)庫(kù)的語(yǔ)句執(zhí)行··················································································(390) 16.3.3 數(shù)據(jù)庫(kù)查詢(xún)語(yǔ)句操作···············································································(391) 第 17 章 高性能服務(wù)器設(shè)計(jì)······················································································(395) 17.1 select 系統(tǒng)調(diào)用································································································(395) 17.1.1 select API······························································································(395) 17.1.2 fd_set···································································································(396) 17.1.3 文件描述符就緒條件···············································································(397) 17.1.4 select 實(shí)現(xiàn)TCP 循環(huán)服務(wù)器案例分析··························································(397) 17.2 poll 系統(tǒng)調(diào)用··································································································(400) 17.2.1 poll API································································································(400) 17.2.2 poll 函數(shù)的事件標(biāo)識(shí)符·············································································(400) 17.2.3 返回值和錯(cuò)誤代碼··················································································(401) 17.2.4 poll 實(shí)現(xiàn)TCP 循環(huán)服務(wù)器案例分析·····························································(401) 17.3 epoll 系列系統(tǒng)調(diào)用···························································································(404) 17.3.1 select 的缺陷·························································································(404) 17.3.2 內(nèi)核事件表···························································································(405) 17.3.3 epoll_wait 函數(shù)·······················································································(405) 17.3.4 LT 模式和ET 模式·················································································(406) 17.4 xinetd 配置·····································································································(406) 17.4.1 Linux 守護(hù)進(jìn)程······················································································(406) 17.4.2 超級(jí)服務(wù)xinetd······················································································(407) 17.4.3 xinetd 配置文件······················································································(407) 參考文獻(xiàn)·········································································································(409)
你還可能感興趣
我要評(píng)論
|