live555 任务调度处理函数使用

来源:互联网 发布:数据分发服务器 编辑:程序博客网 时间:2024/05/22 12:54

<pre name="code" class="html">
</pre>
live555 任务调度 采用几个函数进行设置


void setBackgroundHandling(int socketNum, int conditionSet ,BackgroundHandlerProc* handlerProc, void* clientData)

以RTSP 连接处理为例


RTSPServer::RTSPClientConnection::RTSPClientConnection(RTSPServer& ourServer, int clientSocket, struct sockaddr_in clientAddr)  : fOurServer(ourServer), fIsActive(True),    fClientInputSocket(clientSocket), fClientOutputSocket(clientSocket), fClientAddr(clientAddr),    fRecursionCount(0), fOurSessionCookie(NULL) {  // Add ourself to our 'client connections' table:  fOurServer.fClientConnections->Add((char const*)this, this);    // Arrange to handle incoming requests:  resetRequestBuffer();  envir().taskScheduler().setBackgroundHandling(fClientInputSocket, SOCKET_READABLE|SOCKET_EXCEPTION,(TaskScheduler::BackgroundHandlerProc*)&incomingRequestHandler, this);}


析构函数中 关闭socket 需要移除处理函数

void RTSPServer::RTSPClientConnection::closeSockets() {  // Turn off background handling on our input socket (and output socket, if different); then close it (or them):  if (fClientOutputSocket != fClientInputSocket) {    envir().taskScheduler().disableBackgroundHandling(fClientOutputSocket);    ::closeSocket(fClientOutputSocket);  }    envir().taskScheduler().disableBackgroundHandling(fClientInputSocket);  ::closeSocket(fClientInputSocket);    fClientInputSocket = fClientOutputSocket = -1;}


添加延迟任务


TaskToken scheduleDelayedTask(int64_t microseconds, TaskFunc* proc,void* clientData)


在我的RTSP客户端中使用的示例:


void CloseClientFun(void *data){   RTSPClient* pClient=(RTSPClient*)data;shutdownStream(pClient,0);}int CStreamItem::Close(){if (m_pRtspClient){m_pRtspClient->m_lpStreamCallBack=NULL;m_pRtspClient->m_pUserData=NULL;theApp.g_scheduler->scheduleDelayedTask(1, CloseClientFun, m_pRtspClient);m_pRtspClient=NULL;}return 0;}




0 0
原创粉丝点击