Skip to content

Commit

Permalink
[test] Bonding: fixed closing the listener socket. (#2538)
Browse files Browse the repository at this point in the history
The listener socket was left open after exiting the function.
  • Loading branch information
ethouris authored Nov 14, 2022
1 parent b90b64d commit fa8c58a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions test/test_bonding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TEST(Bonding, SRTConnectGroup)
srt_cleanup();
}

#define ASSERT_SRT_SUCCESS(callform) ASSERT_NE(callform, -1) << "SRT ERROR: " << srt_getlasterror_str()

void listening_thread(bool should_read)
{
Expand All @@ -68,33 +69,33 @@ void listening_thread(bool should_read)
ASSERT_EQ(inet_pton(AF_INET, "127.0.0.1", &bind_sa.sin_addr), 1);
bind_sa.sin_port = htons(4200);

ASSERT_NE(srt_bind(server_sock, (sockaddr*)&bind_sa, sizeof bind_sa), -1);
ASSERT_SRT_SUCCESS(srt_bind(server_sock, (sockaddr*)&bind_sa, sizeof bind_sa));
const int yes = 1;
srt_setsockflag(server_sock, SRTO_GROUPCONNECT, &yes, sizeof yes);
ASSERT_SRT_SUCCESS(srt_setsockflag(server_sock, SRTO_GROUPCONNECT, &yes, sizeof yes));

const int no = 1;
srt_setsockflag(server_sock, SRTO_RCVSYN, &no, sizeof no);
ASSERT_SRT_SUCCESS(srt_setsockflag(server_sock, SRTO_RCVSYN, &no, sizeof no));

const int eid = srt_epoll_create();
const int listen_event = SRT_EPOLL_IN | SRT_EPOLL_ERR;
srt_epoll_add_usock(eid, server_sock, &listen_event);
ASSERT_SRT_SUCCESS(srt_epoll_add_usock(eid, server_sock, &listen_event));

ASSERT_NE(srt_listen(server_sock, 5), -1);
ASSERT_SRT_SUCCESS(srt_listen(server_sock, 5));
std::cout << "Listen: wait for acceptability\n";
int fds[2];
int fds_len = 2;
int ers[2];
int ers_len = 2;
int wr = srt_epoll_wait(eid, fds, &fds_len, ers, &ers_len, 5000,
0, 0, 0, 0);
ASSERT_SRT_SUCCESS(srt_epoll_wait(eid, fds, &fds_len, ers, &ers_len, 5000,
0, 0, 0, 0));

ASSERT_NE(wr, -1);
std::cout << "Listen: reported " << fds_len << " acceptable and " << ers_len << " errors\n";
ASSERT_GT(fds_len, 0);
ASSERT_EQ(fds[0], server_sock);

srt::sockaddr_any scl;
int acp = srt_accept(server_sock, (scl.get()), (&scl.len));
ASSERT_SRT_SUCCESS(acp);
ASSERT_NE(acp & SRTGROUP_MASK, 0);

if (should_read)
Expand All @@ -116,6 +117,7 @@ void listening_thread(bool should_read)
}

srt_close(acp);
srt_close(server_sock);

std::cout << "Listen: wait 7 seconds\n";
std::this_thread::sleep_for(std::chrono::seconds(7));
Expand Down

0 comments on commit fa8c58a

Please sign in to comment.