Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINT] Added setting CLOSING state when closing a socket #2643

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1990,12 +1990,14 @@ int srt::CUDTUnited::close(CUDTSocket* s)

HLOGC(smlog.Debug, log << s->core().CONID() << "CLOSING (removing listener immediately)");
s->core().notListening();
s->m_Status = SRTS_CLOSING;

// broadcast all "accept" waiting
CSync::lock_notify_all(s->m_AcceptCond, s->m_AcceptLock);
}
else
{
s->m_Status = SRTS_CLOSING;
// Note: this call may be done on a socket that hasn't finished
// sending all packets scheduled for sending, which means, this call
// may block INDEFINITELY. As long as it's acceptable to block the
Expand Down
14 changes: 10 additions & 4 deletions test/test_reuseaddr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,9 @@ void shutdownListener(SRTSOCKET bindsock)
EXPECT_NE(srt_setsockopt(bindsock, 0, SRTO_RCVSYN, &yes, sizeof yes), SRT_ERROR); // for async connect
EXPECT_NE(srt_close(bindsock), SRT_ERROR);

std::chrono::milliseconds check_period (250);
std::chrono::milliseconds check_period (100);
int credit = 400; // 10 seconds
auto then = std::chrono::steady_clock::now();

std::cout << "[T/S] waiting for cleanup of @" << bindsock << " up to 10s" << std::endl;
while (srt_getsockstate(bindsock) != SRTS_NONEXIST)
Expand All @@ -438,10 +439,15 @@ void shutdownListener(SRTSOCKET bindsock)
--credit;
if (!credit)
break;

//std::cerr << ".";
}
//std::cerr << std::endl;
auto now = std::chrono::steady_clock::now();
auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(now - then);

// Keep as single string because this tends to be mixed from 2 threads.
std::ostringstream sout;
sout << "[T/S] @" << bindsock << " dissolved after "
<< (dur.count() / 1000.0) << "s" << std::endl;
std::cout << sout.str() << std::flush;

EXPECT_NE(credit, 0);
}
Expand Down