mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
Refine: 优化tcp/udp服务器异常管理断开机制
This commit is contained in:
parent
7e6467615c
commit
afdc5e4267
@ -1 +1 @@
|
||||
Subproject commit 60eb96ded0493fb368dd907997211b6beffb6777
|
||||
Subproject commit f4cae4bbffe1e58392a0c7201f6d501a48141289
|
@ -75,12 +75,7 @@ ssize_t HttpSession::onRecvHeader(const char *header,size_t len) {
|
||||
|
||||
//默认后面数据不是content而是header
|
||||
ssize_t content_len = 0;
|
||||
auto &fun = it->second;
|
||||
try {
|
||||
(this->*fun)(content_len);
|
||||
}catch (exception &ex){
|
||||
shutdown(SockException(Err_shutdown,ex.what()));
|
||||
}
|
||||
(this->*(it->second))(content_len);
|
||||
|
||||
//清空解析器节省内存
|
||||
_parser.Clear();
|
||||
|
@ -60,12 +60,8 @@ void RtmpSession::onManager() {
|
||||
|
||||
void RtmpSession::onRecv(const Buffer::Ptr &buf) {
|
||||
_ticker.resetTime();
|
||||
try {
|
||||
_total_bytes += buf->size();
|
||||
onParseRtmp(buf->data(), buf->size());
|
||||
} catch (exception &ex) {
|
||||
shutdown(SockException(Err_shutdown, ex.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void RtmpSession::onCmd_connect(AMFDecoder &dec) {
|
||||
|
@ -45,17 +45,11 @@ RtpSession::~RtpSession() {
|
||||
}
|
||||
|
||||
void RtpSession::onRecv(const Buffer::Ptr &data) {
|
||||
try {
|
||||
if (_is_udp) {
|
||||
onRtpPacket(data->data(), data->size());
|
||||
return;
|
||||
}
|
||||
RtpSplitter::input(data->data(), data->size());
|
||||
} catch (SockException &ex) {
|
||||
shutdown(ex);
|
||||
} catch (std::exception &ex) {
|
||||
shutdown(SockException(Err_other, ex.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void RtpSession::onError(const SockException &err) {
|
||||
|
@ -131,7 +131,7 @@ void RtspSession::onWholeRtspPacket(Parser &parser) {
|
||||
_media_info._schema = RTSP_SCHEMA;
|
||||
}
|
||||
|
||||
typedef void (RtspSession::*rtsp_request_handler)(const Parser &parser);
|
||||
using rtsp_request_handler = void (RtspSession::*)(const Parser &parser);
|
||||
static unordered_map<string, rtsp_request_handler> s_cmd_functions;
|
||||
static onceToken token([]() {
|
||||
s_cmd_functions.emplace("OPTIONS", &RtspSession::handleReq_Options);
|
||||
@ -146,25 +146,15 @@ void RtspSession::onWholeRtspPacket(Parser &parser) {
|
||||
s_cmd_functions.emplace("POST", &RtspSession::handleReq_Post);
|
||||
s_cmd_functions.emplace("SET_PARAMETER", &RtspSession::handleReq_SET_PARAMETER);
|
||||
s_cmd_functions.emplace("GET_PARAMETER", &RtspSession::handleReq_SET_PARAMETER);
|
||||
}, []() {});
|
||||
});
|
||||
|
||||
auto it = s_cmd_functions.find(method);
|
||||
if (it == s_cmd_functions.end()) {
|
||||
sendRtspResponse("403 Forbidden");
|
||||
shutdown(SockException(Err_shutdown,StrPrinter << "403 Forbidden:" << method));
|
||||
return;
|
||||
throw SockException(Err_shutdown, StrPrinter << "403 Forbidden:" << method);
|
||||
}
|
||||
|
||||
auto &fun = it->second;
|
||||
try {
|
||||
(this->*fun)(parser);
|
||||
}catch (SockException &ex){
|
||||
if(ex){
|
||||
shutdown(ex);
|
||||
}
|
||||
}catch (exception &ex){
|
||||
shutdown(SockException(Err_shutdown,ex.what()));
|
||||
}
|
||||
(this->*(it->second))(parser);
|
||||
parser.Clear();
|
||||
}
|
||||
|
||||
@ -979,7 +969,13 @@ void RtspSession::startListenPeerUdpData(int track_idx) {
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
strongSelf->onRcvPeerUdpData(interleaved, buf, addr);
|
||||
} catch (SockException &ex) {
|
||||
strongSelf->shutdown(ex);
|
||||
} catch (std::exception &ex) {
|
||||
strongSelf->shutdown(SockException(Err_other, ex.what()));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
};
|
||||
|
@ -51,14 +51,6 @@ WebRtcSession::~WebRtcSession() {
|
||||
}
|
||||
|
||||
void WebRtcSession::onRecv(const Buffer::Ptr &buffer) {
|
||||
try {
|
||||
onRecv_l(buffer);
|
||||
} catch (std::exception &ex) {
|
||||
shutdown(SockException(Err_shutdown, ex.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcSession::onRecv_l(const Buffer::Ptr &buffer) {
|
||||
if (_find_transport) {
|
||||
//只允许寻找一次transport
|
||||
_find_transport = false;
|
||||
|
@ -30,9 +30,6 @@ public:
|
||||
|
||||
static EventPoller::Ptr queryPoller(const Buffer::Ptr &buffer);
|
||||
|
||||
private:
|
||||
void onRecv_l(const Buffer::Ptr &);
|
||||
|
||||
private:
|
||||
std::string _identifier;
|
||||
bool _find_transport = true;
|
||||
|
Loading…
Reference in New Issue
Block a user