Skip to content

Commit

Permalink
Fixed group epoll readiness
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Nov 20, 2020
1 parent efc82e1 commit 230e311
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions xtransmit/srt_socket_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void socket::srt_group::create_listeners(const vector<UriParser>& src_uri)

if (!m_blocking_mode)
{
const int modes = SRT_EPOLL_OUT | SRT_EPOLL_ERR;
const int modes = SRT_EPOLL_IN | SRT_EPOLL_ERR;
if (SRT_ERROR == srt_epoll_add_usock(m_epoll_connect, s, &modes))
throw socket::exception(srt_getlasterror_str());

Expand Down Expand Up @@ -241,22 +241,23 @@ shared_srt_group socket::srt_group::accept()
// Wait for REAL connected state if nonblocking mode
if (!m_blocking_mode)
{
// Socket readiness for connection is checked by polling on WRITE allowed sockets.
std::this_thread::sleep_for(3s);
// Socket readiness for connection is checked by polling on READ allowed sockets in case of listeners.
// In the group connection mode we wait for the first accepted connection.
constexpr int timeout_ms = -1;
int len = 2;
SRTSOCKET ready[2];
if (srt_epoll_wait(m_epoll_connect, 0, 0, ready, &len, timeout_ms, 0, 0, 0, 0) == SRT_ERROR)
if (srt_epoll_wait(m_epoll_connect, ready, &len, 0, 0, timeout_ms, 0, 0, 0, 0) == SRT_ERROR)
raise_exception("accept::epoll_wait");

spdlog::trace(LOG_SRT_GROUP "Epoll read-ready sock 0x{:X}, 0x{:X}", ready[0], ready[1]);
spdlog::trace(LOG_SRT_GROUP "Epoll read-ready sock 0x{:X}, 0x{:X}", ready[0], len > 1 ? ready[1] : 0);

sockaddr_in scl;
int sclen = sizeof scl;
const SRTSOCKET lstnr_sock = ready[0];
accepted_sock = srt_accept(lstnr_sock, (sockaddr*)&scl, &sclen);
if (accepted_sock == SRT_INVALID_SOCK)
raise_exception("accept", lstnr_sock);
raise_exception("accept", ready[1]);
}
else
{
Expand All @@ -265,6 +266,7 @@ shared_srt_group socket::srt_group::accept()
raise_exception("accept_bond failed with {}", srt_getlasterror_str());
}

spdlog::info(LOG_SRT_GROUP "Accepted connection sock 0x{:X}", accepted_sock);
const int res = configure_post(accepted_sock);
if (res == SRT_ERROR)
raise_exception("accept::configure_post");
Expand Down Expand Up @@ -323,6 +325,7 @@ shared_srt_group socket::srt_group::connect()
raise_exception("srt_group::connect_member");
}

// In case of a caller a connection event triggers write-readiness.
int len = 2;
SRTSOCKET ready[2];
if (srt_epoll_wait(m_epoll_connect, 0, 0, ready, &len, -1, 0, 0, 0, 0) != -1)
Expand Down
2 changes: 1 addition & 1 deletion xtransmit/xtransmit-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ string create_srt_logfa_description()

// Each group on a new line
stringstream ss;
ss << "SRT log functional areas: [";
ss << "SRT log functional areas: \n[";
int en10 = 0;
for (auto entry : revmap)
{
Expand Down

0 comments on commit 230e311

Please sign in to comment.