sip线程

来源:互联网 发布:程序员电脑壁纸 编辑:程序博客网 时间:2024/06/05 16:56

 这是注册主函数中的循环:

 

while ( !clientHandler.done )

   {

      FdSet fdset;

 

      stack->buildFdSet(fdset);

      int err = fdset.selectMilliSeconds(100);

      assert ( err != -1 );

 

      stack->process(fdset);

      while(dum->process());

 

      if (n == 1000) clientHandler.done = true;

 

      if (!(n++ % 10)) cerr << "|/-//"[(n/10)%4] << '/b';

   }  

 

显然,它的作用是循环调用两个函数:

 

stack->process(fdset);

dum->process();

 

那么它跟直接用StarcThread::thread() DumThread::thread()直接启动一个线程有什么关系呢?

我们看下调用:run()---àStarcThread::thread()发生了什么:

void

StackThread::thread()

{

   while (!isShutdown())

   {

      try

      {

         resip::FdSet fdset;

         buildFdSet(fdset);

         mStack.buildFdSet(fdset);

          int ret = fdset.selectMilliSeconds(resipMin(mStack.getTimeTillNextProcessMS(),

                                                     getTimeTillNextProcessMS()));

         if (ret >= 0)

         {

            // .dlb. use return value to peak at the message to see if it is a

            // shutdown, and call shutdown if it is

            beforeProcess();

            mStack.process(fdset);

            afterProcess();

         }

      }

      catch (BaseException& e)

      {

         ErrLog (<< "Unhandled exception: " << e);

      }

   }

}

void DumThread::thread()

{

   while (!isShutdown())

   {

      try

      {

         std::auto_ptr<Message> msg(mDum.mFifo.getNext(1000));

         if (msg.get())

         {

            mDum.internalProcess(msg);

         }

      }

      catch (BaseException& e)

      {

      }

   }

}

 

 

结论:循环掉用stack->process(fdset)dum->process()与直接stack.run()dum.run()是一样的。

 

Run à thread à process

原创粉丝点击