live555學習之一RTSPServer的建立監聽並監聽客戶端
阿新 • • 發佈:2019-01-05
伺服器建立一個socket作為server端的套接字
1.RTSPServer::setUpOurSocket
1.1.呼叫 GroupsockHelper 的 setupStreamSocket建立一個socket連線,並繫結,
ourSocket = setupStreamSocket(env, ourPort);1.2. 設定傳送緩衝區為50K
if (!increaseSendBufferTo(env, ourSocket, 50*1024))1.3. 監聽埠 其最大連線數為LISTEN_BACKLOG_SIZE 20
if (listen(ourSocket, LISTEN_BACKLOG_SIZE) < 0)1.4. 返回建立的socket
呼叫建構函式
2.new RTSPServer
2.1. 記錄成員資訊 埠號 記錄socket
fRTSPServerPort(ourPort), fRTSPServerSocket(ourSocket), fHTTPServerSocket(-1), fHTTPServerPort(0), fServerMediaSessions(HashTable::create(STRING_HASH_KEYS)), fClientConnections(HashTable::create(ONE_WORD_HASH_KEYS)), fClientConnectionsForHTTPTunneling(NULL), // will get created if needed fClientSessions(HashTable::create(STRING_HASH_KEYS)), fPendingRegisterRequests(HashTable::create(ONE_WORD_HASH_KEYS)), fRegisterRequestCounter(0), fAuthDB(authDatabase), fReclamationTestSeconds(reclamationTestSeconds), fAllowStreamingRTPOverTCP(True) { ignoreSigPipeOnSocket(ourSocket); // so that clients on the same host that are killed don't also kill us
2.2 註冊一個成員函函式用於接收客戶端的連線
void RTSPServer::incomingConnectionHandlerRTSP(void* instance, int /*mask*/) { RTSPServer* server = (RTSPServer*)instance; server->incomingConnectionHandlerRTSP1(); } void RTSPServer::incomingConnectionHandlerRTSP1() { incomingConnectionHandler(fRTSPServerSocket); } void RTSPServer::incomingConnectionHandler(int serverSocket) {
2.2.1accept返回客戶端的socket描述符clientSocket int clientSocket = accept(serverSocket, (struct sockaddr*)&clientAddr, &clientAddrLen);
2.2.2設定和客戶端的連線模式為非阻塞的模式
makeSocketNonBlocking2.2.3.設定客戶端socket描述符的傳送快取為50*1024
increaseSendBufferTo(envir(), clientSocket, 50*1024);2.2.4.建立一個處理連線函式
createNewClientConnectionRTSPClientConnection
2.2.4.1 將該連結新增進入fClientConnections的連線表中
fOurServer.fClientConnections->Add((char const*)this, this);2.2.4.2 註冊一個處理事件通訊的函式(自己的程式可以用執行緒替代)
setBackgroundHandling(&incomingRequestHandler())參考: