mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 20:27:34 +08:00
提高webrtc代码健壮性
This commit is contained in:
parent
869a707c04
commit
3c4285a056
@ -50,26 +50,24 @@ EventPoller::Ptr WebRtcSession::getPoller(const Buffer::Ptr &buffer) {
|
||||
}
|
||||
|
||||
void WebRtcSession::onRecv(const Buffer::Ptr &buffer) {
|
||||
auto buf = buffer->data();
|
||||
auto len = buffer->size();
|
||||
try {
|
||||
onRecv_l(buffer);
|
||||
} catch (std::exception &ex) {
|
||||
shutdown(SockException(Err_shutdown, ex.what()));
|
||||
}
|
||||
}
|
||||
|
||||
if (!_transport) {
|
||||
auto user_name = getUserName(buffer);
|
||||
if (user_name.empty()) {
|
||||
//逻辑分支不太可能走到这里
|
||||
WarnL << user_name;
|
||||
return;
|
||||
}
|
||||
_transport = WebRtcTransportImp::getRtcTransport(user_name, true);
|
||||
if (!_transport) {
|
||||
//逻辑分支不太可能走到这里
|
||||
WarnL << user_name;
|
||||
return;
|
||||
}
|
||||
void WebRtcSession::onRecv_l(const Buffer::Ptr &buffer) {
|
||||
if (_find_transport) {
|
||||
//只允许寻找一次transport
|
||||
_find_transport = false;
|
||||
_transport = WebRtcTransportImp::getRtcTransport(getUserName(buffer), true);
|
||||
CHECK(_transport && _transport->getPoller()->isCurrentThread());
|
||||
_transport->setSession(shared_from_this());
|
||||
}
|
||||
_ticker.resetTime();
|
||||
_transport->inputSockData(buf, len, &_peer_addr);
|
||||
CHECK(_transport);
|
||||
_transport->inputSockData(buffer->data(), buffer->size(), &_peer_addr);
|
||||
}
|
||||
|
||||
void WebRtcSession::onError(const SockException &err) {
|
||||
|
@ -30,6 +30,10 @@ public:
|
||||
void onManager() override;
|
||||
|
||||
private:
|
||||
void onRecv_l(const Buffer::Ptr &);
|
||||
|
||||
private:
|
||||
bool _find_transport = true;
|
||||
Ticker _ticker;
|
||||
struct sockaddr _peer_addr;
|
||||
std::shared_ptr<WebRtcTransportImp> _transport;
|
||||
|
@ -1019,6 +1019,9 @@ void WebRtcTransportImp::unregisterSelf() {
|
||||
}
|
||||
|
||||
WebRtcTransportImp::Ptr WebRtcTransportImp::getRtcTransport(const string &key, bool unref_self) {
|
||||
if (key.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
lock_guard<mutex> lck(s_rtc_mtx);
|
||||
auto it = s_rtc_map.find(key);
|
||||
if (it == s_rtc_map.end()) {
|
||||
|
Loading…
Reference in New Issue
Block a user