resiprocate协议栈分析内容摘要:

TransactionTerminated*, TimerMessage*, SipMessage* or derived ApplicationMessage* */ Message* receiveAny()。 /** Return true if the stack has new messages for the TU. Since the addition of TransactionUsers, this method is deprecated. This only looks into the old TuFifo that is not associated with any TransactionUser. @deprecated */ bool hasMessage() const。 五、几个成员变量的说明 /// if this object exists, it manages advanced security featues Security* mSecurity。 这是 如果需要安全处理而用到的类。 DnsStub* mDnsStub。 这是如果自己定义 DNS处理的话所需要的 DNS处理的存根和截取器。 /// if this object exists, it get39。 s notified when ApplicationMessage39。 s get posted AsyncProcessHandler* mAsyncProcessHandler。 异步处理的基类指针对象,可以自定义异步处理的方式。 /** fifo used to municate between the TU (Transaction User) and stack Note: since the introduction of multiple TU39。 s this Fifo should no longer be used by most applications each TU now owns it39。 s own Fifo. */ TimeLimitFifoMessage mTUFifo。 这个就不用说啦,看注释吧。 /// Protection for AppTimerQueue mutable Mutex mAppTimerMutex。 整个协议栈的同步都是集中利用了源码中实现的同步对象,非常不错,实现同步类的理论基础应该是基于大师 BS的理论“资源开 始即初始化”。 /// All aspects of the Transaction State Machine / DNS resolver TransactionController mTransactionController。 /** store all domains that this stack is responsible for. Controlled by addAlias and addTransport interfaces and checks can be made with isMyDomain() */ std::setData mDomains。 /// Responsible for routing messages to the correct TU based on installed rules TuSelector mTuSelector。 TransactionController 模块 在 SipStack中看到这样的描述: /// All aspects of the Transaction State Machine / DNS resolver TransactionController mTransactionController。 注意 all aspects在我的理解中这又是一个界面类, SipStack是 Sip Core整个庭院的外围的门面的话这又是进入庭院后第二道城墙;就如庭院高深的故宫和亭廊回环的苏州园林它们的实现中更有层次的递张以及庭院间的交互回环。 BS教导我们不要写“臃肿的界面”, SipStack这个大界面里面又套这个实现层次的界面是不是一种 好的实践呢。 我的理解是,应该是这样的。 ―――努力达到界面和实现分离。 现在就看看这个 Transaction State Machine / DNS resolver界面类吧,在我的实现中,其实把 DNS Resolver部分清理掉啦,导致只是个 Transaction State Machine 的界面类吧。 如果仔细看看 TransactionControl 的函数也就是它的接口函数的话和 SipStack就差不离,翻版而也,就是一道门进去还是一道门,就连造型都差不多,外面是拱洞型的里面还是;故宫和苏州园林的设计 把古建筑的设计模式推向了极致。 还是列一下吧: void process(FdSetamp。 fdset)。 unsigned int getTimeTillNextProcessMS()。 void buildFdSet(FdSetamp。 fdset)。 // graceful shutdown (eventually) void shutdown()。 TransportSelectoramp。 transportSelector() { return mTransportSelector。 } const TransportSelectoramp。 transportSelector() const { return mTransportSelector。 } bool isTUOverloaded() const。 void send(SipMessage* msg)。 再看一下几个重要的成员变量: // fifo used to municate to the transaction state machine within the // stack. Not for external use by the application. May contain, sip // messages (requests and responses), timers (used by state machines), // asynchronous dns responses, transport errors from the underlying // transports, etc. FifoTransactionMessage mStateMacFifo。 // from the sipstack (for convenience) TuSelectoramp。 mTuSelector。 // Used to decide which transport to send a sip message on. TransportSelector mTransportSelector。 // stores all of the transactions that are currently active in this stack TransactionMap mClientTransactionMap。 TransactionMap mServerTransactionMap。 重点和关键成员变量: FifoTransactionMessage mStateMacFifo。 看看这个成员变量的价值: void TransactionController::send(SipMessage* msg) { (msg)。 } 消息的流动不可能到此为止,它要上传下递,如何实现的呢。 看看构造函数吧: TransactionController::TransactionController(SipStackamp。 stack) : mStack(stack), mRegisteredForTransactionTermination(false), mDiscardStrayResponses(true), mStateMacFifo(), mTuSelector(), mTransportSelector(mStateMacFifo, (), ()), mTimers(mStateMacFifo), mShuttingDown(false), mStatsManager() { } 既然都点出来了,就继续往下看看,看看流向 TransportSelector会怎样呢 : TransportSelector::TransportSelector(FifoTransactionMessageamp。 fifo, Security* security, DnsStubamp。 dnsStub) : mDns(dnsStub), mStateMacFifo(fifo), mSecurity(security), mSocket( INVALID_SOCKET ), mSocket6( INVALID_SOCKET ) { memset(amp。 , 0, sizeof(sockaddr_in))。 = AF_UNSPEC。 } 再让我们看另外一支,只是一直在 Process中处理的: void TransactionController::process(FdSetamp。 fdset) { if (mShuttingDown amp。 amp。 !() amp。 amp。 !() amp。 amp。 ()) {。 } else {。 while (()) { TransactionState::process(*this)。 } } } TransactionState 的这个静态函数 Process 的参数居然是 *this,也就是是说 TransactionState 能从TransactionControler 得到它所要的内容,因此先让我们过去浏览一下先: 想了一下这儿放下暂且不表,我们到 TransactionState 部分再详细到来,但是我们知道下一步的流向将是哪儿。 再粗粗的看了一下 TransactionControler 我们发现内容并不多, Control 者只是一个控制调节的角色,它是一个 contact window。 向外是联系的窗口,向内负责安排和 分派其他包容的角色去实现。 在 TransactionControler 中有两个比较重要的成员变量: // from the sipstack (for convenience) TuSelectoramp。 mTuSelector。 // Used to decide which transport to send a sip message on. TransportSelector mTransportSelector。 // stores all of the transactions that are currently active in this stack TransactionMap mClientTransactionMap。 TransactionMap mServerTransactionMap。 可以看出它包含和管理的分别是三个层次的对象: Transaction User、 Transport、 TransactionState 它对这几个对象的互动和控制基本就在 Process里面完成。 并且为了以示关联,我们先 看看 mClientTransactionMap 是在哪儿体现它的价值的: void TransactionState::add(const Dataamp。 tid) { if (mMachine == ClientNonInvite || mMachine == ClientInvite || mMachine == ClientStale || mMachine == Stateless )。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。