From 517f3c229c151ef3a4cfed98c7c17db19afaa34b Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 18 Nov 2019 16:34:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0kick=5Fsessions=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index e1278c9c..f1263e70 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -517,6 +517,28 @@ void installWebApi() { session->safeShutdown(); }); + + //批量断开tcp连接,比如说可以断开rtsp、rtmp播放器等 + //测试url http://127.0.0.1/index/api/kick_sessions?local_port=1935 + API_REGIST(api,kick_sessions,{ + CHECK_SECRET(); + uint16_t local_port = allArgs["local_port"].as(); + string &peer_ip = allArgs["peer_ip"]; + uint64_t count_hit = 0; + + SessionMap::Instance().for_each_session([&](const string &id,const TcpSession::Ptr &session){ + if(local_port != 0 && local_port != session->get_local_port()){ + return; + } + if(!peer_ip.empty() && peer_ip != session->get_peer_ip()){ + return; + } + session->safeShutdown(); + ++count_hit; + }); + val["count_hit"] = (Json::UInt64)count_hit; + }); + static auto addStreamProxy = [](const string &vhost, const string &app, const string &stream,