Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 13 additions & 3 deletions docs/API/API-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,24 @@ exiting the application that uses the SRT library. This cleanup function will st
be called from the C++ global destructor, if not called by the application, although
relying on this behavior is strongly discouraged.

**IMPORTANT NOTES**:

1. This function must be called from within `main()`, preferably at the end.
Calling it from any C++ global destructor is pointless, as SRT does it by
itself. But relying on it is strongly discouraged - at best only if you are
completely certain that all resources in the application are maintained in the
strict creation-destruction order, including threads. If this condition isn't
satisfied, then the behavior of the cleanup outside of `main()` is undefined.

2. The startup/cleanup calls have an instance counter. This means that if you
call [`srt_startup`](#srt_startup) multiple times, you need to call the
`srt_cleanup` function exactly the same number of times.

| Returns | |
|:----------------------------- |:--------------------------------------------------------------- |
| 0 | A possibility to return other values is reserved for future use |
| <img width=240px height=1px/> | <img width=710px height=1px/> |

**IMPORTANT**: Note that the startup/cleanup calls have an instance counter.
This means that if you call [`srt_startup`](#srt_startup) multiple times, you need to call the
`srt_cleanup` function exactly the same number of times.


[:arrow_up: &nbsp; Back to List of Functions & Structures](#srt-api-functions)
Expand Down
44 changes: 37 additions & 7 deletions scripts/win-installer/build-win-installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
param(
[string]$Version = "",
[switch]$NoBuild = $false,
[switch]$NoPause = $false
[switch]$NoPause = $false,
[string]$OnlyPlatform = ""
)
Write-Output "Building the SRT static libraries installer for Windows"

Expand Down Expand Up @@ -113,6 +114,9 @@ function ssl-lib($pf, $conf, $lib) { return "$(ssl-libdir $pf $conf)\$($LIBFILE.
Write-Output "Searching OpenSSL libraries ..."
$Missing = 0
foreach ($Platform in $SSL.Keys) {
if ($OnlyPlatform -ne "" -and $Platform -ne $OnlyPlatform) {
continue
}
if (-not (Test-Path -PathType Container $(ssl-include $Platform))) {
Write-Output "**** Missing $(ssl-include $Platform)"
$Missing = $Missing + 1
Expand Down Expand Up @@ -173,19 +177,32 @@ Write-Output "NSIS: $NSIS"
#-----------------------------------------------------------------------------

if (-not $NoBuild) {
Write-Output "BUILD ENABLED - configuring build"
if ($OnlyPlatform -ne "") {
Write-Output "LIMIT TO PLATFORM: $OnlyPlatform"
}
foreach ($Platform in $ARCH.Keys) {
if ($OnlyPlatform -ne "" -and $Platform -ne $OnlyPlatform) {
Write-Output "Skipping platform $Platform."
continue
}
Write-Output "Preparing platform $Platform."
# Build directory. Cleanup to force a fresh cmake config.
$BuildDir = "$TmpDir\build.$Platform"
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $BuildDir
[void](New-Item -Path $BuildDir -ItemType Directory -Force)

# Run CMake.
Write-Output "Configuring build for platform $Platform ..."
& $CMake -S $RepoDir -B $BuildDir -A $Platform `
-DENABLE_STDCXX_SYNC=ON `
-DOPENSSL_INCLUDE_DIR="$(ssl-include $Platform)" `
-DOPENSSL_ROOT_DIR="$(ssl-libdir $Platform Release)"

$params = @("-S", "$RepoDir",
"-B", "$BuildDir",
"-A", "$Platform",
"-DENABLE_STDCXX_SYNC=ON",
"-DOPENSSL_INCLUDE_DIR=$(ssl-include $Platform)",
"-DOPENSSL_ROOT_DIR=$(ssl-libdir $Platform Release)"
)
Write-Output "Running: cmake $params"
& $CMake $params
# Patch version string in version.h
Get-Content "$BuildDir\version.h" |
ForEach-Object {
Expand All @@ -197,7 +214,17 @@ if (-not $NoBuild) {
# Compile SRT.
Write-Output "Building for platform $Platform ..."
foreach ($Conf in $LIBDIR.Keys) {
& $MSBuild "$BuildDir\SRT.sln" /nologo /maxcpucount /property:Configuration=$Conf /property:Platform=$Platform /target:srt_static
# The solution file format depends on the CMake version.
# Try new XML solution file format first.
$SolFile = "$BuildDir\SRT.slnx"
if (-not (Test-Path $SolFile)) {
# Try legacy solution file format.
$SolFile = "$BuildDir\SRT.sln"
}
if (-not (Test-Path $SolFile)) {
Exit-Script "Solution file $BuildDir\SRT.sln[x] not found, check CMake output"
}
& $MSBuild $SolFile /nologo /maxcpucount /property:Configuration=$Conf /property:Platform=$Platform /target:srt_static
}
}
}
Expand All @@ -207,6 +234,9 @@ Write-Output "Checking compiled libraries ..."
$Missing = 0
foreach ($Conf in $LIBDIR.Keys) {
foreach ($Platform in $SSL.Keys) {
if ($OnlyPlatform -ne "" -and $Platform -ne $OnlyPlatform) {
continue
}
$Path = "$TmpDir\build.$Platform\$Conf\srt_static.lib"
if (-not (Test-Path $Path)) {
Write-Output "**** Missing $Path"
Expand Down
4 changes: 3 additions & 1 deletion srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ srt::CUDTUnited::~CUDTUnited()
enterCS(m_InitLock);
stopGarbageCollector();
leaveCS(m_InitLock);
closeAllSockets();

// DO NOT call closeAllSockets() here; instead rely on that
// all sockets have been closed when exiting the GC.
releaseMutex(m_GlobControlLock);
releaseMutex(m_IDLock);
releaseMutex(m_InitLock);
Expand Down
21 changes: 15 additions & 6 deletions srtcore/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ void srt::CRcvQueue::init(int qsize, size_t payload, int version, int hsize, CCh
}
}

void* srt::CRcvQueue::worker(void* param)
void* srt::CRcvQueue::worker(void* param) ATR_NOEXCEPT
{
CRcvQueue* self = (CRcvQueue*)param;
sockaddr_any sa(self->getIPversion());
Expand Down Expand Up @@ -1328,7 +1328,11 @@ void* srt::CRcvQueue::worker(void* param)
<< "CChannel reported ERROR DURING TRANSMISSION - IPE. INTERRUPTING worker anyway.");
}
cst = CONN_REJECT;
break;

// DO NOT interrupt though - the worker thread must run until all
// sockets are removed from the multiplexer. Alternatively you can forcefully
// remove all sockets from the receive U list.
continue;
}
// OTHERWISE: this is an "AGAIN" situation. No data was read, but the process should continue.

Expand All @@ -1350,10 +1354,7 @@ void* srt::CRcvQueue::worker(void* param)
{
HLOGC(qrlog.Debug,
log << CUDTUnited::CONID(u->m_SocketID) << " SOCKET broken, REMOVING FROM RCV QUEUE/MAP.");
// the socket must be removed from Hash table first, then RcvUList
self->m_pHash->remove(u->m_SocketID);
self->m_pRcvUList->remove(u);
u->m_pRNode->m_bOnList = false;
self->removeFromLists(u);
}

ul = self->m_pRcvUList->m_pUList;
Expand Down Expand Up @@ -1842,6 +1843,14 @@ void srt::CRcvQueue::storePktClone(int32_t id, const CPacket& pkt)
}
}

void srt::CRcvQueue::removeFromLists(CUDT* u)
{
// the socket must be removed from Hash table first, then RcvUList
m_pHash->remove(u->m_SocketID);
m_pRcvUList->remove(u);
u->m_pRNode->m_bOnList = false;
}

void srt::CMultiplexer::resetAtFork()
{
if (m_pRcvQueue != NULL)
Expand Down
4 changes: 3 additions & 1 deletion srtcore/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,11 @@ class CRcvQueue

int getIPversion() { return m_iIPversion; }

void removeFromLists(CUDT* u);

void stop();
private:
static void* worker(void* param);
static void* worker(void* param) ATR_NOEXCEPT;
sync::CThread m_WorkerThread;
// Subroutines of worker
EReadStatus worker_RetrieveUnit(int32_t& id, CUnit*& unit, sockaddr_any& sa);
Expand Down
2 changes: 1 addition & 1 deletion test/test_bonding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ TEST(Bonding, Options)

#if SRT_ENABLE_ENCRYPTION

uint32_t kms = -1;
int32_t kms = -1;

EXPECT_NE(srt_getsockflag(grp, SRTO_KMSTATE, &kms, &optsize), SRT_ERROR);
EXPECT_EQ(optsize, (int) sizeof kms);
Expand Down
Loading