最近因項目需要,要學習live555這個開源平臺。live555是用c++實現的,對於該平臺的介紹網上有很多文章,以下是個人在讀它源碼時的記錄,也是一個初步的理解,和大家一起分享一下。有錯誤,或者不足之處請大家指出。
BasicUsageEnvironment庫
a) BasicHashTable.cpp
1. BasicHashTable類
功能: 一個簡單的hash表的實現
SMALL_HASH_TABLE_SIZE=4
構造函數BasicHashTable(int keyType),傳入參數鍵的類型
Add(char const* key, void* value) 增加一對鍵值 注:void* 指針,它可以保存任何類型對象的地址
Remove(char const* key) 根據鍵刪除一個鍵值對
Lookup(char const* key) 根據鍵查詢鍵值
NumEntries() 返回實體數目
HashTable* create(int keyType) hash表的創建
Iterator* create(HashTable& hashTable) 返回hash表的迭代器
b) HandlerSet.hh (handlerSet 的定義)
1. HandlerDescriptor類,句柄描述符
int socketNum //socket數量
BackgroundHandlerProc* handlerProc //句柄後臺處理的進程指針
void* clientData //客戶端數據指針
2. HandlerSet類,句柄的集合
assignHandler(int socketNum,TaskScheduler::BackgroundHandlerProc* handlerProc, void* clientData); //分配句柄
removeHandler(int socketNum); //根據socket號刪除句柄
3. HandlerIterator類,句柄迭代器
HandlerDescriptor* next(); //下一個句柄,沒有則返回NULL
reset();
c) DelayQueue.hh
1. DelayQueueEntry類,延遲隊列實體
long token(); //????
2. DelyQueue類,延遲隊列
addEntry(DelayQueueEntry* newEntry); //return a token for the entry
updateEntry(DelayQueueEntry* entry, DelayInterval newDelay);
updateEntry( long tokenToFind, DelayInterval newDelay);
removeEntry() //移除實體,但是不刪除
DelayInterval const& timeToNextAlarm();
handleAlarm();
d) UsageEnvironment.hh
1. UsageEnvironment類,這是一個抽象的基類
void reclaim();//回收,當沒有剩餘的狀態時,刪除自己
taskScheduler() //任務調度程序
//結果信息的處理
getResultMsg();
setResultMsg();
setResultErrMsg();
appendToResultMsg(); //like setResultMsg(), except that an 'errno' message is appended
reportBackgroundError();//用於報告後臺預先設置的錯誤的信息
getErrno(); // ‘errno’
UsageEnvironment& operator<<(); //console output
2. TaskScheduler類,任務調度類,是一個抽象的基類
virtual TaskToken scheduleDelayedTask(nt64_t microseconds, TaskFunc* proc,void* clientData) //當我們下一個達到調度點的,調度一個任務(在一個延遲之後)。(Does not delay, if “microseconds”<=0,)。返回一個token,可用於以後的unscheduleDelayTask()的調用。
virtual void unscheduleDelayedTask(TaskToken& prevTask); //設置”prevTask”=NULL(如果prevTask==NULL,no effect)
virtual void rescheduleDelayedTask() // Combines "unscheduleDelayedTask()" with "scheduleDelayedTask()" (setting "task" to the new task token).
typedef void BackgroundHandlerProc(void* clientData, int mask); // handing sockets reads in the background
virtual void turnOnBackgroundReadHandling () //打開後臺socket讀取
virtual void turnOffBackgroundReadHandling () //關閉後臺socket讀取
virtual void doEventLoop(char* watchVariable = NULL) // Stops the current thread of control from proceeding, but allows delayed tasks (and/or background I/O handling) to proceed.(If "watchVariable" is not NULL, then we return from this routine when *watchVariable != 0)