UC故事 2011/12/08 总结与计划(续4)

1. 近日要点

* 关于Thread与EventQueue(实际为Reactor)的使用总结

                                  主(平台)线程类              网络线程类                           主线程事件队列类                                 网络线程事件队列类

操作系统             

Win32                      CRtThreadReactor            CRtThreadReactor  ?         CRtReactorWin32Message              CRtReactorWin32AsyncSelect        

Linux                         CRtThreadTask                  CRThreadReactor              EventQueue                                         CRtReactorEpoll


Q1:CRtReactorWin32Asyncselect同时处理EventQueue与Socket的Event,这个定位从design上说是否合理?

Q2:CRtReactorBase::ProcessHandleEvent因前述原因,需要同时处理EventQueue的event以及socket的event,似乎污染了这一个接口的本义?

 

2. 问题汇总

 

Q: CRtThreadManager::JoinAllThreads()什么意思?

Q:EventQueue与TimerQueue

前者用于不同线程之间传递信息,后者完成定时器功能,如何理解定时器功能?

 

Q:理解cmd_main例子的几个问题

      Q:init main thred的时候,主线程的run event loop未运行?

      Q:几块东东如何关联的?

      Q:运行主线程的时候,没有reactor也没有问题?

 

Q:Conference Client主界面看见后,会有一个短暂的停顿,并出现白屏,背后在做什么东东?

 

3. 杂记

* std::auto_ptr用法:

http://wenku.baidu.com/view/42ad53fec8d376eeaeaa319e.html

 

4. 跟踪CConfPing.StartPing()

 

* main thread

STACK TRACE:

ReactorBase::PostEvent(IRtEvent * 0x01efd440, IRtEventQueue::EPriority EPRIORITY_NORMAL) line 517
CRtConnectorThreadProxy::AsycConnect(IRtAcceptorConnectorSink * 0x01efd138, const CRtInetAddr & {...}, CRtTimeValue * 0x01efd010, CRtInetAddr * 0x00000000) line 105 + 59 bytes
CRtDetectionConnector::CConnectorItem::AsycConnect(CRtTimeValue * 0x01efd010, CRtInetAddr * 0x00000000) line 214 + 46 bytes
CRtDetectionConnector::StartDetectionConnect(IRtAcceptorConnectorSink * 0x01efd370, CRtTimeValue * 0x0011c304, IRtDetectionConnector::DetectMode DETECT_INTERVAL_1S, CRtInetAddr * 0x00000000) line 78
CRtIMConnProvider::Connect_i(IConnProviderSink * 0x01efcbc8, unsigned long 1, const TransportAddress * 0x01efcd60, Event_Type EVENT_TYPE_CONFERENCE_PING, CRtTimeValue * 0x0011c304, int 0, int 1) line 454 + 39 bytes
CRtIMConnProvider::Connect(IConnProviderSink * 0x01efcbc8, unsigned long 1, const TransportAddress * 0x01efcd60, Event_Type EVENT_TYPE_CONFERENCE_PING, CRtTimeValue * 0x0011c304, int 0) line 356
CPingBase::Ping() line 116 + 51 bytes
CPingBase::StartPing() line 93
CConference::JoinConference(const CConfDetailInfo & {...}, const CInfoRosterInfo & {...}, unsigned short 1, const CRtString * 0x01efa27c {0x01efa2d1 "tcp://172.16.1.12:443"}, int 1, unsigned long 2147483648) line 225 + 24 bytes
CConfManage::CreateConference() line 2617 + 103 bytes
CMainFrame::OnCreate(unsigned int 1, unsigned int 1, unsigned int 1, unsigned int 1) line 1879
CMainFrame::ProcessWindowMessage(HWND__ * 0x00021040, unsigned int 1, unsigned int 0, long 1204320, long & -858993460, unsigned long 0) line 138 + 37 bytes
ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::WindowProc(HWND__ * 0x01ef9250, unsigned int 1, unsigned int 0, long 1204320) line 2110 + 37 bytes
USER32! 77d18734()
USER32! 77d2bdf1()
USER32! 77d28ea0()
USER32! 77d2ce7c()
NTDLL! 7c92e473()
USER32! 77d2e442()
USER32! 77d2e4dc()
WTL::CFrameWindowImplBase<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::Create(HWND__ * 0x00000000, ATL::_U_RECT {...}, const char * 0x001266e0, unsigned long 114229248, unsigned long 262400, ATL::_U_MENUorID {...}, unsigned short 50350, void * 0x00000000) line 456 + 91 bytes
WTL::CFrameWindowImpl<CMainFrame,ATL::CWindow,ATL::CWinTraits<114229248,262400> >::Create(HWND__ * 0x00000000, ATL::_U_RECT {...}, const char * 0x001266e0, unsigned long 114229248, unsigned long 262400, HMENU__ * 0x01d40e79, void * 0x00000000) line 1196
WTL::CFrameWindowImpl<CMainFrame,ATL::CWindow,ATL::CWinTraits<114229248,262400> >::CreateEx(HWND__ * 0x00000000, ATL::_U_RECT {...}, unsigned long 0, unsigned long 0, void * 0x00000000) line 1221 + 42 bytes
Run(char * 0x00141f37, int 1) line 195 + 35 bytes
LaunchConf(HINSTANCE__ * 0x00400000, char * 0x00141f37, int 1) line 318 + 13 bytes
WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00141f37, int 1) line 85 + 20 bytes
WinMainCRTStartup() line 330 + 54 bytes
KERNEL32! 7c817077()

CRtConnectorThreadProxy::AsycConnect {

 ......

 RtResult rv = RT_ERROR_OUT_OF_MEMORY;
 CEventAsycConnect *pEvent = new CEventAsycConnect(
  this, this, aAddrPeer, aTimeout, aAddrLocal);
 if (pEvent) {
  rv = m_pThreadNetwork->GetEventQueue()->PostEvent(pEvent);
 }

.......

}

 

* network thread

STACK TRACE:

CRtConnectorTcpT<CRtConnectorWrapper,CRtTransportTcp,CRtSocketStream>::Connect_i(CRtTransportTcp * 0x01efbdc0, const CRtInetAddr & {...}) line 202
CRtConnectorTcpT<CRtConnectorWrapper,CRtTransportTcp,CRtSocketStream>::Connect(const CRtInetAddr & {...}, CRtInetAddr * 0x00000000) line 82 + 22 bytes
CRtConnectorWrapper::AsycConnect(IRtAcceptorConnectorSink * 0x01efbc80, const CRtInetAddr & {...}, CRtTimeValue * 0x01efd46c, CRtInetAddr * 0x00000000) line 109 + 26 bytes
CConnConnectorT<CRtConnRlbTcpClient>::AsycConnect(IRtAcceptorConnectorSink * 0x01efd0c4, const CRtInetAddr & {...}, CRtTimeValue * 0x01efd46c, CRtInetAddr * 0x00000000) line 71 + 84 bytes
CEventAsycConnect::OnEventFire() line 187 + 74 bytes
CRtEventQueueBase::ProcessOneEvent(IRtEvent * 0x01efd440) line 229 + 12 bytes
CRtEventQueueBase::ProcessEvents(const std::list<IRtEvent *,std::allocator<IRtEvent *> > & {...}) line 217
CRtReactorBase::ProcessHandleEvent(void * 0xffffffff, long 256, int 0, int 1, int 0) line 324 + 18 bytes
CRtReactorWin32Message::Win32SocketWndProc(HWND__ * 0x000310c6, unsigned int 1058, unsigned int 4294967295, long 256) line 115
USER32! 77d18734()
USER32! 77d18816()
USER32! 77d189cd()
USER32! 77d196c7()
CRtReactorWin32Message::RunEventLoop() line 262 + 15 bytes
CRtThreadReactor::OnThreadRun() line 67 + 19 bytes
CRtThread::ThreadProc(void * 0x01ef8788) line 151 + 13 bytes
_threadstartex(void * 0x01ef8838) line 227 + 13 bytes
KERNEL32! 7c80b729()

CODE:

CRtConnectorTcpT<CRtConnectorWrapper,CRtTransportTcp,CRtSocketStream>::Connect_i {

 ......

  /// we regiester CONNECT_MASK prior to connect() to avoid lossing OnConnect()
  RtResult rv = m_pReactor->RegisterHandler(this, IRtEventHandler::CONNECT_MASK);            // Q:why register handler ?
  if (RT_FAILED(rv))
   return -1;

  nRet = ::connect((RT_SOCKET)sockPeer.GetHandle(),              // 此处向远方发connect请求
        reinterpret_cast<const struct sockaddr *>(aAddr.GetPtr()),
        aAddr.GetSize());

 ......

}

 

注1:ping的操作通过network thread完成,UI thread通过向network thread发送事件(PostEvent(Async Connect Event))

注2:::connect()执行后,tcpview.exe里出现相关连接,wireshark出现sync/ack包

 

5. 跟踪ChatMainDlg::OnBtnSend():Chat窗口发送数据

* main thread

STACK TRACE:

CRtTransportThreadProxy::SendData(CRtMessageBlock & {...}, int 0, int 0, IRtTransport::DataPriority DP_MEDIUM, int 0) line 127
CRtTransportThreadProxy::SendData(CRtMessageBlock & {...}, RtRudpReliability RUDP_RELIABLE_ORDERED, int -1, int 0, int 0, IRtTransport::DataPriority DP_MEDIUM, unsigned char 0) line 141 + 31 bytes
CRtIMConnection::SendData(CRtMessageBlock & {...}, int 0, RtRudpReliability RUDP_RELIABLE_ORDERED, unsigned char 0, int -1) line 942 + 51 bytes
CConfConnection::SendBufData(CRtMessageBlock & {...}) line 249 + 39 bytes
CConfConnection::SendData_i() line 263 + 15 bytes
CConfConnection::SendData(CRtMessageBlock & {...}, DATA_Priority DATA_PRIORITY_HIGH, unsigned long 2) line 211
CConfPort::SendData(CRtMessageBlock & {...}, DATA_Priority DATA_PRIORITY_HIGH, unsigned long 2) line 80 + 33 bytes
CConfPort::SendData(CInfoSvrPduBase * 0x0013384c, DATA_Priority DATA_PRIORITY_HIGH, unsigned long 2) line 60 + 23 bytes
CConference::SendData(CInfoSvrPduBase * 0x0013384c, DATA_Priority DATA_PRIORITY_HIGH, unsigned long 2) line 1243 + 48 bytes
CConfSession::SessSenddData(const CInfoSID & {...}, DATA_Priority DATA_PRIORITY_HIGH, unsigned long 2, unsigned long 52, unsigned char * const 0x01ed2be8) line 116 + 23 bytes
CConfSession::SendData_i(const CInfoSID & {...}, DATA_Priority DATA_PRIORITY_HIGH, unsigned long 2, unsigned long 52, unsigned char * 0x01f3bec8) line 296 + 33 bytes
CConfSession::SendData(const CInfoSID & {...}, DATA_Priority DATA_PRIORITY_HIGH, unsigned long 2, unsigned long 52, unsigned char * const 0x01f3bec8) line 281
CChatSession::SendChatData(unsigned long 52, unsigned char * const 0x01f3bec8, CInfoSID * 0x00000000) line 504 + 62 bytes
CChatMainDlg::SendData(int 1, WTL::CString & {...}, WTL::CString & {...}) line 1114
CChatMainDlg::SendMessageW(WTL::CString & {...}) line 522
CChatMainDlg::PressSend(int 0) line 498
CChatMainDlg::OnSendMsg(unsigned int 2026, unsigned int 0, long 0, int & 1) line 1364
CChatMainDlg::ProcessWindowMessage(HWND__ * 0x000206d0, unsigned int 2026, unsigned int 0, long 0, long & -858993460, unsigned long 0) line 152 + 40 bytes
ATL::CDialogImplBaseT<ATL::CWindow>::DialogProc(HWND__ * 0x01ee4970, unsigned int 2026, unsigned int 0, long 0) line 2279 + 37 bytes
USER32! 77d18734()
USER32! 77d23ce4()
USER32! 77d23b30()
USER32! 77d23d5c()
USER32! 77d18734()
USER32! 77d18816()
USER32! 77d189cd()
USER32! 77d196c7()
WTL::CMessageLoop::Run() line 468 + 15 bytes
Run(char * 0x00151f31, int 1) line 207 + 11 bytes
LaunchConf(HINSTANCE__ * 0x00400000, char * 0x00151f31, int 1) line 318 + 13 bytes
WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00151f31, int 1) line 85 + 20 bytes
WinMainCRTStartup() line 330 + 54 bytes
KERNEL32! 7c817077()

CODE:

CRtTransportThreadProxy::SendData{

    ......

    CRtEventSendData* sendDataEvent =
        new CRtEventSendData(this, inDestroyData ? &inData : inData.DuplicateChained(), inSendImmediately, inPriority, inNeedAck);
    return m_networkThread->GetEventQueue()->PostEvent(sendDataEvent);

                               ^ 向网络线程PostEvent(CRtEventSendData)

    ......

}

注:仍然是通过向network thread投递event来完成数据的传输。


* network thread

STACK TRACE:

CRtConnRlbTcp::SendData(CRtMessageBlock & {...}, int 0, int 1, IRtTransport::DataPriority DP_MEDIUM, int 0) line 95
CRtEventSendData::OnEventFire() line 299 + 76 bytes
CRtEventQueueBase::ProcessOneEvent(IRtEvent * 0x01f36440) line 229 + 12 bytes
CRtEventQueueBase::ProcessEvents(const std::list<IRtEvent *,std::allocator<IRtEvent *> > & {...}) line 217
CRtReactorBase::ProcessHandleEvent(void * 0xffffffff, long 256, int 0, int 1, int 0) line 324 + 18 bytes
CRtReactorWin32Message::Win32SocketWndProc(HWND__ * 0x0004014e, unsigned int 1058, unsigned int 4294967295, long 256) line 115
USER32! 77d18734()
USER32! 77d18816()
USER32! 77d189cd()
USER32! 77d196c7()
CRtReactorWin32Message::RunEventLoop() line 262 + 15 bytes
CRtThreadReactor::OnThreadRun() line 67 + 19 bytes
CRtThread::ThreadProc(void * 0x01ec8098) line 151 + 13 bytes
_threadstartex(void * 0x01ec8148) line 227 + 13 bytes
KERNEL32! 7c80b729()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值