<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;
}