int RTSPSession::EventHandler() { bool exit = false; char buf[MAX_BUF_SIZE]; int ret = 0; //int length = MAX_BUF_SIZE; while (false == exit) { ::memset(buf, 0, sizeof(char) * MAX_BUF_SIZE); int numbytes = socket_->Receive(buf, MAX_BUF_SIZE); if (numbytes <= 0) { //RTSPDEBUG("Disconnected from %s:%d", socket_->GetRemoteAddr(), socket_->GetRemotePort()); RTSPDEBUG("Disconnected!"); ret = -1; exit = true; break; } ParseRTSPRequestString(buf, numbytes); if ( MAX_BUF_SIZE - 1 > numbytes) { ret = 0; exit = true; break; } } return ret; }
int rtsp::rtsp_msg(connection * n, char * data, int len){ RtspClientConnection * clientConnection = (RtspClientConnection*)n->get_context(); std::string cmd; std::string urlPreSuffix; std::string urlSuffix; std::string strSessionId; std::string cseq; std::string requst(data, len); int ret = ParseRTSPRequestString(requst, cmd, urlPreSuffix, urlSuffix, cseq, strSessionId); if(ret < 0){ return clientConnection->handleCmd_bad(); } debug_log("[%u]parseRTSPRequestString:{%s}\n", pthread_self(), requst.c_str()); bool requsetInsesseion = !strSessionId.empty(); RtspClientSession * clientSession = NULL; clientConnection->SetSeq(cseq); if (requsetInsesseion){ clientSession = clientConnection->lookupRtspClientSession(strSessionId); if(!clientSession){ return clientConnection->handleCmd_sessionNotFound(); } } if (cmd == "OPTIONS"){ clientConnection->handle_options(); } else if (cmd == "DESCRIBE"){ clientConnection->handle_describle(urlPreSuffix, urlSuffix, requst); } else if (cmd == "SETUP") { if(!requsetInsesseion){ clientSession = clientConnection->createNewRtspClientSession(); } clientSession->handle_setup(clientConnection, urlPreSuffix, urlSuffix, requst); } else if (cmd == "PLAY" || cmd == "PAUSE" || cmd == "GET_PARAMETER" || cmd == "SET_PARAMETER" || cmd == "TEARDOWN"){ clientSession->handle_insession(clientConnection, cmd, urlPreSuffix, urlSuffix, requst); } else if(cmd == "REGISTER" || cmd == "REGISTER_REMOTE"){ } else{ clientConnection->handleCmd_notSupported(); } return 0; }