Commit 826e3002d38fdb0e4746984429e0390003f4ff99
1 parent
f81c44d9
断连后,5分钟未能建立新连接,退出
Showing
1 changed file
with
18 additions
and
0 deletions
src/decoder/gb28181/rtp2/RTPReceiver2.cpp
@@ -16,6 +16,13 @@ const int MAX_RTP_BUFFER_SIZE = 1024*1024*10; | @@ -16,6 +16,13 @@ const int MAX_RTP_BUFFER_SIZE = 1024*1024*10; | ||
16 | #define Server_cache_max_size 4194304 // 1M = 1 * 1024 * 1024 = 1048576 字节 | 16 | #define Server_cache_max_size 4194304 // 1M = 1 * 1024 * 1024 = 1048576 字节 |
17 | #define Server_rtp_max_size 1800 | 17 | #define Server_rtp_max_size 1800 |
18 | 18 | ||
19 | +static long long get_cur_time_second(){ | ||
20 | + chrono::time_point<chrono::system_clock, chrono::seconds> tpMicro | ||
21 | + = chrono::time_point_cast<chrono::seconds>(chrono::system_clock::now()); | ||
22 | + | ||
23 | + return tpMicro.time_since_epoch().count(); | ||
24 | +} | ||
25 | + | ||
19 | 26 | ||
20 | RTPReceiver2::RTPReceiver2() | 27 | RTPReceiver2::RTPReceiver2() |
21 | { | 28 | { |
@@ -209,6 +216,8 @@ int RTPReceiver2::tcp_server() { | @@ -209,6 +216,8 @@ int RTPReceiver2::tcp_server() { | ||
209 | 216 | ||
210 | bool bFilter = false; | 217 | bool bFilter = false; |
211 | 218 | ||
219 | + long long last_time = get_cur_time_second(); | ||
220 | + | ||
212 | while (!m_bRtpExit) | 221 | while (!m_bRtpExit) |
213 | { | 222 | { |
214 | // LOG_INFO("阻塞监听新连接..."); | 223 | // LOG_INFO("阻塞监听新连接..."); |
@@ -221,11 +230,20 @@ int RTPReceiver2::tcp_server() { | @@ -221,11 +230,20 @@ int RTPReceiver2::tcp_server() { | ||
221 | LOG_WARN("accept connection warn"); | 230 | LOG_WARN("accept connection warn"); |
222 | bFilter = true; | 231 | bFilter = true; |
223 | } | 232 | } |
233 | + | ||
234 | + long long cur_time = get_cur_time_second(); | ||
235 | + if (cur_time - last_time > 300) { | ||
236 | + // 5分钟未能建立新连接,退出 | ||
237 | + m_bRtpExit = true; | ||
238 | + break; | ||
239 | + } | ||
224 | 240 | ||
225 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); | 241 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
226 | continue; | 242 | continue; |
227 | } | 243 | } |
228 | // 阻塞接收请求 end | 244 | // 阻塞接收请求 end |
245 | + | ||
246 | + last_time = get_cur_time_second(); | ||
229 | LOG_INFO("发现新连接:clientFd={}", clientFd); | 247 | LOG_INFO("发现新连接:clientFd={}", clientFd); |
230 | bFilter = false; | 248 | bFilter = false; |
231 | 249 |