From 5074a4d444735644093e36fe9aaa9c7faf7b5856 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 9 Apr 2021 11:21:45 +0800 Subject: [PATCH] Threads-Hybrid: Use ST wait and IO for RECV/SEND thread. --- trunk/src/app/srs_app_listener.cpp | 11 ++++------- trunk/src/app/srs_app_threads.cpp | 20 ++++---------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/trunk/src/app/srs_app_listener.cpp b/trunk/src/app/srs_app_listener.cpp index 8a2b270d14..a4f76aa670 100755 --- a/trunk/src/app/srs_app_listener.cpp +++ b/trunk/src/app/srs_app_listener.cpp @@ -331,10 +331,8 @@ int SrsUdpMuxSocket::recvfrom(srs_utime_t timeout) int SrsUdpMuxSocket::raw_recvfrom() { - int osfd = srs_netfd_fileno(lfd); - fromlen = sizeof(from); - nread = ::recvfrom(osfd, buf, nb_buf, 0, (sockaddr*)&from, (socklen_t*)&fromlen); + nread = srs_recvfrom(lfd, buf, nb_buf, (sockaddr*)&from, &fromlen, SRS_UTIME_NO_TIMEOUT); if (nread <= 0) { return nread; } @@ -389,8 +387,8 @@ srs_error_t SrsUdpMuxSocket::sendto(void* data, int size, srs_utime_t timeout) if (nb_write <= 0) { if (nb_write < 0 && errno == ETIME) { return srs_error_new(ERROR_SOCKET_TIMEOUT, "sendto timeout %d ms", srsu2msi(timeout)); - } - + } + return srs_error_new(ERROR_SOCKET_WRITE, "sendto"); } @@ -406,8 +404,7 @@ srs_error_t SrsUdpMuxSocket::sendto(void* data, int size, srs_utime_t timeout) int SrsUdpMuxSocket::raw_sendto(void* data, int size) { - int osfd = srs_netfd_fileno(lfd); - return ::sendto(osfd, data, size, 0, (sockaddr*)&from, (socklen_t)fromlen); + return srs_sendto(lfd, data, size, (sockaddr*)&from, fromlen, SRS_UTIME_NO_TIMEOUT); } srs_netfd_t SrsUdpMuxSocket::stfd() diff --git a/trunk/src/app/srs_app_threads.cpp b/trunk/src/app/srs_app_threads.cpp index 01869be51f..4b8c8c5b2e 100644 --- a/trunk/src/app/srs_app_threads.cpp +++ b/trunk/src/app/srs_app_threads.cpp @@ -1903,9 +1903,6 @@ srs_error_t SrsAsyncRecvManager::do_start() { srs_error_t err = srs_success; - // TODO: FIXME: Config it? - srs_utime_t interval = 10 * SRS_UTIME_MILLISECONDS; - // We must deep copy listeners if changed. vector listeners; @@ -1956,11 +1953,8 @@ srs_error_t SrsAsyncRecvManager::do_start() continue; } - // TODO: FIXME: Maybe we should use cond wait? - timespec tv = {0}; - tv.tv_sec = interval / SRS_UTIME_SECONDS; - tv.tv_nsec = (interval % SRS_UTIME_SECONDS) * 1000; - nanosleep(&tv, NULL); + // OK to use ST wait. + srs_usleep(10 * SRS_UTIME_MILLISECONDS); } return err; @@ -2100,9 +2094,6 @@ srs_error_t SrsAsyncSendManager::do_start() { srs_error_t err = srs_success; - // TODO: FIXME: Config it? - srs_utime_t interval = 10 * SRS_UTIME_MILLISECONDS; - while (true) { vector flying_sending_packets; sending_packets_->swap(flying_sending_packets); @@ -2123,11 +2114,8 @@ srs_error_t SrsAsyncSendManager::do_start() continue; } - // TODO: FIXME: Maybe we should use cond wait? - timespec tv = {0}; - tv.tv_sec = interval / SRS_UTIME_SECONDS; - tv.tv_nsec = (interval % SRS_UTIME_SECONDS) * 1000; - nanosleep(&tv, NULL); + // OK to use ST wait. + srs_usleep(10 * SRS_UTIME_MILLISECONDS); } return err;