Skip to content

Commit

Permalink
[apps] Receive the connection event on the client (caller) socket (#597)
Browse files Browse the repository at this point in the history
* stransmit now checks the write events on socket
* srt_epoll_wait rw fds default initialization with invalid socket
* Check if src and target are not null
* [apps] Remove target socket from OUT polling when connected
  • Loading branch information
maxsharabayko authored and rndi committed Mar 11, 2019
1 parent a2d900e commit a0391c3
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ int main( int argc, char** argv )
}

// IN because we care for state transitions only
int events = SRT_EPOLL_IN | SRT_EPOLL_ERR;
// OUT - to check the connection state changes
int events = SRT_EPOLL_IN | SRT_EPOLL_OUT | SRT_EPOLL_ERR;
switch(tar->uri.type())
{
case UriParser::SRT:
Expand All @@ -393,11 +394,12 @@ int main( int argc, char** argv )
}

int srtrfdslen = 2;
SRTSOCKET srtrfds[2];
int srtwfdslen = 2;
SRTSOCKET srtrwfds[4] = {SRT_INVALID_SOCK, SRT_INVALID_SOCK , SRT_INVALID_SOCK , SRT_INVALID_SOCK };
int sysrfdslen = 2;
SYSSOCKET sysrfds[2];
if (srt_epoll_wait(pollid,
&srtrfds[0], &srtrfdslen, 0, 0,
&srtrwfds[0], &srtrfdslen, &srtrwfds[2], &srtwfdslen,
100,
&sysrfds[0], &sysrfdslen, 0, 0) >= 0)
{
Expand All @@ -410,15 +412,18 @@ int main( int argc, char** argv )
}

bool doabort = false;
for (int i = 0; i < srtrfdslen; i++)
for (size_t i = 0; i < sizeof(srtrwfds) / sizeof(SRTSOCKET); i++)
{
SRTSOCKET s = srtrwfds[i];
if (s == SRT_INVALID_SOCK)
continue;

bool issource = false;
SRTSOCKET s = srtrfds[i];
if (src->GetSRTSocket() == s)
if (src && src->GetSRTSocket() == s)
{
issource = true;
}
else if (tar->GetSRTSocket() != s)
else if (tar && tar->GetSRTSocket() != s)
{
cerr << "Unexpected socket poll: " << s;
doabort = true;
Expand Down Expand Up @@ -530,6 +535,18 @@ int main( int argc, char** argv )
if (!quiet)
cerr << "SRT target connected" << endl;
tarConnected = true;
if (tar->uri.type() == UriParser::SRT)
{
const int events = SRT_EPOLL_IN | SRT_EPOLL_ERR;
// Disable OUT event polling when connected
if (srt_epoll_update_usock(pollid,
tar->GetSRTSocket(), &events))
{
cerr << "Failed to add SRT destination to poll, "
<< tar->GetSRTSocket() << endl;
return 1;
}
}
}
}

Expand Down

0 comments on commit a0391c3

Please sign in to comment.