RTSPServer对一个新的链接创建一个ClientConnection;在RTSPServer::incomingConnectionHandler函数中用(void)createNewClientConnection(clientSocket, clientAddr);创建新的RTSPClientConnection;
下面主要分析:RTSPClientConnection类
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);
}
incomingRequestHandler类主要处理客户端发送的消息,他的定义如下:
void RTSPServer::RTSPClientConnection::incomingRequestHandler(void* instance, int /*mask*/)
{
RTSPClientConnection* session = (RTSPClientConnection*)instance;
session->incomingRequestHandler1();
}
可见对客户端的消息的处理,主要是用RTSPClientConnection类来传递;
void RTSPServer::RTSPClientConnection::incomingRequestHandler1()
{
struct sockaddr_in dummy; // 'from' address, meaningless in this case
int bytesRead = readSocket(envir(), fClientInputSocket, &fRequestBuffer[fRequestBytesAlreadySeen], fRequestBufferBytesLeft, dummy);
handleRequestBytes(bytesRead);//处理发送的请求
}