Skip to content

Commit 5074a4d

Browse files
committed
Threads-Hybrid: Use ST wait and IO for RECV/SEND thread.
1 parent c8f2ff0 commit 5074a4d

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

trunk/src/app/srs_app_listener.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,8 @@ int SrsUdpMuxSocket::recvfrom(srs_utime_t timeout)
331331

332332
int SrsUdpMuxSocket::raw_recvfrom()
333333
{
334-
int osfd = srs_netfd_fileno(lfd);
335-
336334
fromlen = sizeof(from);
337-
nread = ::recvfrom(osfd, buf, nb_buf, 0, (sockaddr*)&from, (socklen_t*)&fromlen);
335+
nread = srs_recvfrom(lfd, buf, nb_buf, (sockaddr*)&from, &fromlen, SRS_UTIME_NO_TIMEOUT);
338336
if (nread <= 0) {
339337
return nread;
340338
}
@@ -389,8 +387,8 @@ srs_error_t SrsUdpMuxSocket::sendto(void* data, int size, srs_utime_t timeout)
389387
if (nb_write <= 0) {
390388
if (nb_write < 0 && errno == ETIME) {
391389
return srs_error_new(ERROR_SOCKET_TIMEOUT, "sendto timeout %d ms", srsu2msi(timeout));
392-
}
393-
390+
}
391+
394392
return srs_error_new(ERROR_SOCKET_WRITE, "sendto");
395393
}
396394

@@ -406,8 +404,7 @@ srs_error_t SrsUdpMuxSocket::sendto(void* data, int size, srs_utime_t timeout)
406404

407405
int SrsUdpMuxSocket::raw_sendto(void* data, int size)
408406
{
409-
int osfd = srs_netfd_fileno(lfd);
410-
return ::sendto(osfd, data, size, 0, (sockaddr*)&from, (socklen_t)fromlen);
407+
return srs_sendto(lfd, data, size, (sockaddr*)&from, fromlen, SRS_UTIME_NO_TIMEOUT);
411408
}
412409

413410
srs_netfd_t SrsUdpMuxSocket::stfd()

trunk/src/app/srs_app_threads.cpp

+4-16
Original file line numberDiff line numberDiff line change
@@ -1903,9 +1903,6 @@ srs_error_t SrsAsyncRecvManager::do_start()
19031903
{
19041904
srs_error_t err = srs_success;
19051905

1906-
// TODO: FIXME: Config it?
1907-
srs_utime_t interval = 10 * SRS_UTIME_MILLISECONDS;
1908-
19091906
// We must deep copy listeners if changed.
19101907
vector<SrsThreadUdpListener*> listeners;
19111908

@@ -1956,11 +1953,8 @@ srs_error_t SrsAsyncRecvManager::do_start()
19561953
continue;
19571954
}
19581955

1959-
// TODO: FIXME: Maybe we should use cond wait?
1960-
timespec tv = {0};
1961-
tv.tv_sec = interval / SRS_UTIME_SECONDS;
1962-
tv.tv_nsec = (interval % SRS_UTIME_SECONDS) * 1000;
1963-
nanosleep(&tv, NULL);
1956+
// OK to use ST wait.
1957+
srs_usleep(10 * SRS_UTIME_MILLISECONDS);
19641958
}
19651959

19661960
return err;
@@ -2100,9 +2094,6 @@ srs_error_t SrsAsyncSendManager::do_start()
21002094
{
21012095
srs_error_t err = srs_success;
21022096

2103-
// TODO: FIXME: Config it?
2104-
srs_utime_t interval = 10 * SRS_UTIME_MILLISECONDS;
2105-
21062097
while (true) {
21072098
vector<SrsAsyncUdpPacket*> flying_sending_packets;
21082099
sending_packets_->swap(flying_sending_packets);
@@ -2123,11 +2114,8 @@ srs_error_t SrsAsyncSendManager::do_start()
21232114
continue;
21242115
}
21252116

2126-
// TODO: FIXME: Maybe we should use cond wait?
2127-
timespec tv = {0};
2128-
tv.tv_sec = interval / SRS_UTIME_SECONDS;
2129-
tv.tv_nsec = (interval % SRS_UTIME_SECONDS) * 1000;
2130-
nanosleep(&tv, NULL);
2117+
// OK to use ST wait.
2118+
srs_usleep(10 * SRS_UTIME_MILLISECONDS);
21312119
}
21322120

21332121
return err;

0 commit comments

Comments
 (0)