freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

bt軟件下載開發(fā)完整版-01-文庫吧

2025-07-18 08:16 本頁面


【正文】 = initialize_btcache_node()。 if(node == NULL) { printf(%s:%d create_btcache error\n,__FILE__,__LINE__)。 release_memory_in_btcache()。 return 1。 451 項(xiàng)目實(shí)踐: BT 下載軟件的開發(fā) 第章 13 } if(last_piece == NULL) { last_piece = node。 last = node。 } else { lastnext = node。 last = node。 } count。 } for(i = 0。 i 64。 i++) { have_piece_index[i] = 1。 } return 0。 } ? void release_memory_in_btcache() 功能:釋放 文件中動(dòng)態(tài)分配的內(nèi)存。函數(shù)實(shí)現(xiàn)代碼如下: void release_memory_in_btcache() { Btcache *p = btcache_head。 while(p != NULL) { btcache_head = pnext。 if(pbuff != NULL) free(pbuff)。 free(p)。 p = btcache_head。 } release_last_piece()。 if(fds != NULL) free(fds)。 } ? void release_last_piece() 功能:釋放為存儲(chǔ)最后一個(gè) piece 而申請(qǐng)的空間。函數(shù)實(shí)現(xiàn)代碼如下: void release_last_piece() { Btcache *p = last_piece。 while(p != NULL) { last_piece = pnext。 if(pbuff != NULL) free(pbuff)。 free(p)。 p = last_piece。 } } ? int get_files_count() 功能:判斷種子文件中待下載的文件個(gè)數(shù)。函數(shù)實(shí)現(xiàn)代碼如下: int get_files_count() { int count = 0。 if(is_multi_files() == 0) return 1。 Files *p = files_head。 while(p != NULL) { count++。 p = pnext。 } return count。 } 452 Linux 系統(tǒng) 下的 C 編程 ? int create_files() 功能:根據(jù)種子文件中的信息創(chuàng)建保存下載數(shù)據(jù)的文件。通過 lseek 和 write 兩個(gè)函數(shù)來實(shí)現(xiàn)物理存儲(chǔ)空間的分配。函數(shù)實(shí)現(xiàn)代碼如下: int create_files() { int ret, i。 char buff[1] = { 0x0 }。 fds_len = get_files_count()。 if(fds_len 0) return 1。 fds = (int *)malloc(fds_len * sizeof(int))。 if(fds == NULL) return 1。 if( is_multi_files() == 0 ) { // 待下載的為單文件 *fds = open(file_name,O_RDWR|O_CREAT,0777)。 if(*fds 0) { printf(%s:%d error,__FILE__,__LINE__)。 return 1。 } ret = lseek(*fds,file_length1,SEEK_SET)。 if(ret 0) { printf(%s:%d error,__FILE__,__LINE__)。 return 1。 } ret = write(*fds,buff,1)。 if(ret != 1) { printf(%s:%d error,__FILE__,__LINE__)。 return 1。 } } else { // 待下載的是多個(gè)文件 ret = chdir(file_name)。 if(ret 0) { // 改變目錄失敗,說明該目錄還未創(chuàng)建 ret = mkdir(file_name,0777)。 if(ret 0) { printf(%s:%d error,__FILE__,__LINE__)。 return 1。 } ret = chdir(file_name)。 if(ret 0) { printf(%s:%d error,__FILE__,__LINE__)。 return 1。 } } Files *p = files_head。 i = 0。 while(p != NULL) { fds[i] = open(ppath,O_RDWR|O_CREAT,0777)。 if(fds[i] 0) { printf(%s:%d error,__FILE__,__LINE__)。 return 1。 } ret = lseek(fds[i],plength1,SEEK_SET)。 if(ret 0) { printf(%s:%d error,__FILE__,__LINE__)。 return 1。 } ret = write(fds[i],buff,1)。 if(ret != 1) { printf(%s:%d error,__FILE__,__LINE__)。 return 1。 } p = pnext。 i++。 } //while的循環(huán)結(jié)束 } //end else return 0。 } ? int write_btcache_node_to_harddisk(Btcache *node) 功能:判斷一個(gè) Btcache 結(jié) 點(diǎn)(即一個(gè) slice)的數(shù)據(jù)要寫到哪個(gè)文件以及具體位置,并寫入。函數(shù)實(shí)現(xiàn)代碼如下: int write_btcache_node_to_harddisk(Btcache *node) { long long line_position。 Files *p。 int i。 if((node == NULL) || (fds == NULL)) return 1。 453 項(xiàng)目實(shí)踐: BT 下載軟件的開發(fā) 第章 13 // 無論下載的是多文件還是單個(gè)文件,將要下載的所有數(shù)據(jù)看 作一個(gè)線性字節(jié)流 // 變量 line_position的值是要寫入硬盤的線性位置 // 變量 piece_length的值為每個(gè) piece長度,它被定義在 line_position = nodeindex * piece_length + nodebegin。 // 如果下載的是單個(gè)文件 if( is_multi_files() == 0 ) { lseek(*fds,line_position,SEEK_SET)。 write(*fds,nodebuff,nodelength)。 return 0。 } // 下載的是多個(gè)文件 if(files_head == NULL) { printf(%s:%d file_head is NULL,__FILE__,__LINE__)。 return 1。 } p = files_head。 i = 0。 while(p != NULL) { if((line_position plength) amp。amp。 (line_position+nodelength plength)) { // 如果待寫入的數(shù)據(jù) (即一個(gè)長度為 16KB 的 slice)屬于同一個(gè)文件 lseek(fds[i],line_position,SEEK_SET)。 write(fds[i],nodebuff,nodelength)。 break。 // 寫入數(shù)據(jù)完畢,退出 while循環(huán) } else if((line_position plength) amp。amp。 (line_position+nodelength = plength) ) { // 如果待寫入的數(shù)據(jù)跨越了兩個(gè)或兩個(gè)以上的文件 int offset = 0。 // buff內(nèi)的偏移 ,也是已寫的字節(jié)數(shù) int left = nodelength。 // 剩余要寫的字節(jié)數(shù) lseek(fds[i],line_position,SEEK_SET)。 write(fds[i],nodebuff,plength line_position)。 offset = plength line_position。 // offset存放已寫的字節(jié)數(shù) left = left (plength line_position)。 // 還未寫的字節(jié)數(shù) p = pnext。 // 用于獲取下一個(gè)文件的長度 i++。 // 獲取下一個(gè)文件描述符 while(left 0) { if(plength = left) { // 當(dāng) 前文件的長度大于等于要寫的字節(jié)數(shù) lseek(fds[i],0,SEEK_SET)。 write(fds[i],nodebuff+offset,left)。// 寫入剩余要寫的字節(jié)數(shù) left = 0。 } else { // 當(dāng)前文件的長度小于要寫的字節(jié)數(shù) lseek(fds[i],0,SEEK_SET)。 write(fds[i],nodebuff+offset,plength)。 // 先寫滿當(dāng)前文件 offset = offset + plength。 left = left plength。 i++。 p = pnext。 } } break。 // 執(zhí)行到此處說明所有數(shù)據(jù)已正確寫入文件中,退出 while循環(huán) } else { // 待寫入的數(shù)據(jù)不應(yīng)寫入當(dāng)前文件 line_position = line_position plength。 i++。
點(diǎn)擊復(fù)制文檔內(nèi)容
高考資料相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1