Skip to content

Commit

Permalink
Test file transmission: find free port
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Jul 22, 2021
1 parent 19cbec1 commit 4447d9c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion test/test_file_transmission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ TEST(Transmission, FileUpload)
sa_lsn.sin_addr.s_addr = INADDR_ANY;
sa_lsn.sin_port = htons(5555);

// Find unused a port not used by any other service.
// Otherwise srt_connect may actually connect.
int bind_res = -1;
for (int port = 5000; port <= 5555; ++port)
{
sa_lsn.sin_port = htons(port);
bind_res = srt_bind(sock_lsn, (sockaddr*)&sa_lsn, sizeof sa_lsn);
if (bind_res == 0)
{
std::cout << "Running test on port " << port << "\n";
break;
}

ASSERT_TRUE(bind_res == SRT_EINVOP) << "Bind failed not due to an occupied port. Result " << bind_res;

}

ASSERT_GE(bind_res, 0);

srt_bind(sock_lsn, (sockaddr*)&sa_lsn, sizeof sa_lsn);

int optval = 0;
Expand Down Expand Up @@ -110,7 +129,7 @@ TEST(Transmission, FileUpload)

sockaddr_in sa = sockaddr_in();
sa.sin_family = AF_INET;
sa.sin_port = htons(5555);
sa.sin_port = sa_lsn.sin_port;
ASSERT_EQ(inet_pton(AF_INET, "127.0.0.1", &sa.sin_addr), 1);

srt_connect(sock_clr, (sockaddr*)&sa, sizeof(sa));
Expand Down

0 comments on commit 4447d9c

Please sign in to comment.