日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Iperf源代码分析(八)

發布時間:2024/9/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Iperf源代码分析(八) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

????我在打開src文件夾時,大概瀏覽了一遍文件后,我突然發現了List.cpp和List.h文件。我一直在想,什么地方會用到List?在前一篇轉載的文章中,作者在介紹Audience類的時候提到了一句話,"Server 將所有Client(Audience)的連接信息組織成一個單向鏈表,每個Client對應鏈表中的一項,該項包含該Client的地址結構(sockaddr)以及實現與該Client對應的監控線程的對象(我們稱它為監控對象),所有與此Client相關的聽者對象和說者對象都是由該監控線程生成的。"。這里,有必要對這兩個文件進行一些分析以作為后期更加深入理解的基礎。

首先,閱讀List.h源文件:

#ifndef?Iperf_LIST_H #define?Iperf_LIST_H#include?"headers.h" #include?"Audience.hpp"/**?List?handling?utilities?to?replace?STD?vector*/struct?Iperf_ListEntry;/**?A?List?entry?that?consists?of?a?sockaddr*?a?pointer?to?the?Audience?that?sockaddr?is*?associated?with?and?a?pointer?to?the?next*?entry*/ struct?Iperf_ListEntry?{iperf_sockaddr?data;Audience*?holder;Iperf_ListEntry?*next; };/**?Functions?to?modify?or?search?the?List*/ void?Iperf_pushback?(?Iperf_ListEntry?*add,?Iperf_ListEntry?**root?);void?Iperf_delete?(?iperf_sockaddr?*del,?Iperf_ListEntry?**root?);void?Iperf_destroy?(?Iperf_ListEntry?**root?);Iperf_ListEntry*?Iperf_present?(?iperf_sockaddr?*find,?Iperf_ListEntry?*root?);Iperf_ListEntry*?Iperf_hostpresent?(?iperf_sockaddr?*find,?Iperf_ListEntry?*root?);#endif

在頭文件中,有一個很重要的結構體:

struct?Iperf_ListEntry?{iperf_sockaddr?data;Audience*?holder;Iperf_ListEntry?*next; };

在這個結構體中,有三個成員變量:

第一個????iperf_sockaddr data;?? ---->其指代的是套接字地址;

第二個??? Audience* holder; ---->其指代的是Audience指針;

第三個????Iperf_ListEntry *next; ----->其指代的是此結構體的指針,這是典型的鏈表struct。

在本文件中,還有幾個成員函數,其實現的功能基本同普通鏈表操作差不多,但這里還是提出來以加深印象:

(結合List.c文件內容)

A、Iperf_pushback函數:將Iperf_ListEntry結構體指針壓入鏈表

/**?Add?Entry?add?to?the?List*/ void?Iperf_pushback?(?Iperf_ListEntry?*add,?Iperf_ListEntry?**root?)?{add->next?=?*root;*root?=?add; }

B、Iperf_present函數:定位find指針指向的Iperf_ListEntry結構體(套接字地址相同)

/**?Check?if?the?exact?Entry?find?is?present*/ Iperf_ListEntry*?Iperf_present?(?iperf_sockaddr?*find,?Iperf_ListEntry?*root?)?{Iperf_ListEntry?*itr?=?root;while?(?itr?!=?NULL?)?{if?(?SocketAddr::are_Equal(?(sockaddr*)itr,?(sockaddr*)find?)?)?{return?itr;}itr?=?itr->next;}return?NULL; }

C、Iperf_delete 函數:先用Iperf_present定位所刪除的結構體,然后再進行刪除操作

/**?Delete?Entry?del?from?the?List*/ void?Iperf_delete?(?iperf_sockaddr?*del,?Iperf_ListEntry?**root?)?{Iperf_ListEntry?*temp?=?Iperf_present(?del,?*root?);if?(?temp?!=?NULL?)?{if?(?temp?==?*root?)?{*root?=?(*root)->next;}?else?{Iperf_ListEntry?*itr?=?*root;while?(?itr->next?!=?NULL?)?{if?(?itr->next?==?temp?)?{itr->next?=?itr->next->next;break;}itr?=?itr->next;}}delete?temp;} }

D、Iperf_destory函數:銷毀(釋放)鏈表空間

/**?Destroy?the?List?(cleanup?function)*/ void?Iperf_destroy?(?Iperf_ListEntry?**root?)?{Iperf_ListEntry?*itr1?=?*root,?*itr2;while?(?itr1?!=?NULL?)?{itr2?=?itr1->next;delete?itr1;itr1?=?itr2;}*root?=?NULL; }

E、Iperf_hostpresent函數:定位find指針指向的Iperf_ListEntry結構體(主機地址相同)

/**?Check?if?a?Entry?find?is?in?the?List?or?if?any*?Entry?exists?that?has?the?same?host?as?the?*?Entry?find*/ Iperf_ListEntry*?Iperf_hostpresent?(?iperf_sockaddr?*find,?Iperf_ListEntry?*root?)?{Iperf_ListEntry?*itr?=?root;while?(?itr?!=?NULL?)?{if?(?SocketAddr::Hostare_Equal(?(sockaddr*)itr,?(sockaddr*)find?)?)?{return?itr;}itr?=?itr->next;}return?NULL; }


轉載于:https://my.oschina.net/kiterunner24/blog/269143

總結

以上是生活随笔為你收集整理的Iperf源代码分析(八)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。