net.IpNetDriverUseReceiveThread
net.IpNetDriverUseReceiveThread
#Overview
name: net.IpNetDriverUseReceiveThread
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If true, the IpNetDriver will call the socket\'s RecvFrom function on a separate thread (not the game thread)
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of net.IpNetDriverUseReceiveThread is to control whether the IpNetDriver will call the socket’s RecvFrom function on a separate thread instead of the game thread.
This setting variable is primarily used in the networking system of Unreal Engine, specifically within the IpNetDriver component. It is part of the Online Subsystem Utils plugin, which is responsible for handling network-related functionality.
The value of this variable is set through a console variable (CVar) system. It’s defined as a TAutoConsoleVariable with a default value of 0 (false).
This variable interacts closely with the socket subsystem and the receive thread functionality of the IpNetDriver. It’s also associated with other networking-related variables such as CVarNetIpNetDriverReceiveThreadQueueMaxPackets and CVarNetUseRecvMulti.
Developers must be aware that enabling this variable (setting it to a non-zero value) will create a separate thread for receiving network packets, which can potentially improve performance by offloading this task from the game thread. However, this should only be done if the socket subsystem supports it, which is checked using SocketSubsystem->IsSocketWaitSupported().
Best practices when using this variable include:
- Ensure that the socket subsystem supports threaded receive operations before enabling it.
- Consider the potential impact on performance and thread synchronization when enabling this feature.
- Test thoroughly in various network conditions to ensure stability and improved performance.
Regarding the associated variable CVarNetIpNetDriverUseReceiveThread:
This is the actual console variable object that controls the net.IpNetDriverUseReceiveThread setting. It’s an instance of TAutoConsoleVariable
The purpose of CVarNetIpNetDriverUseReceiveThread is to provide a programmatic interface for getting and setting the value of net.IpNetDriverUseReceiveThread within the C++ code.
This variable is used in the IpNetDriver’s initialization process to determine whether to create a receive thread. It’s typically accessed using the GetValueOnAnyThread() method, which retrieves the current value of the console variable.
Developers should be aware that changes to this variable at runtime will only take effect the next time the IpNetDriver is initialized. It’s not designed for frequent toggling during gameplay.
Best practices for using CVarNetIpNetDriverUseReceiveThread include:
- Use GetValueOnAnyThread() to read the value, as it’s thread-safe.
- Consider exposing this setting in game options if you want to allow users to toggle it.
- Be cautious about changing this value during an active game session, as it may not take effect immediately and could potentially cause network instability if changed unexpectedly.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpNetDriver.cpp:56
Scope: file
Source code excerpt:
TAutoConsoleVariable<int32> CVarNetIpNetDriverUseReceiveThread(
TEXT("net.IpNetDriverUseReceiveThread"),
0,
TEXT("If true, the IpNetDriver will call the socket's RecvFrom function on a separate thread (not the game thread)"));
TAutoConsoleVariable<int32> CVarNetIpNetDriverReceiveThreadQueueMaxPackets(
TEXT("net.IpNetDriverReceiveThreadQueueMaxPackets"),
1024,
#Associated Variable and Callsites
This variable is associated with another variable named CVarNetIpNetDriverUseReceiveThread
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpNetDriver.cpp:55
Scope: file
Source code excerpt:
TEXT(" default: 10 s"));
TAutoConsoleVariable<int32> CVarNetIpNetDriverUseReceiveThread(
TEXT("net.IpNetDriverUseReceiveThread"),
0,
TEXT("If true, the IpNetDriver will call the socket's RecvFrom function on a separate thread (not the game thread)"));
TAutoConsoleVariable<int32> CVarNetIpNetDriverReceiveThreadQueueMaxPackets(
TEXT("net.IpNetDriverReceiveThreadQueueMaxPackets"),
#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpNetDriver.cpp:932
Scope (from outer to inner):
file
function bool UIpNetDriver::InitBase
Source code excerpt:
// If the cvar is set and the socket subsystem supports it, create the receive thread.
if (CVarNetIpNetDriverUseReceiveThread.GetValueOnAnyThread() != 0 && SocketSubsystem->IsSocketWaitSupported())
{
SocketReceiveThreadRunnable = MakeUnique<FReceiveThreadRunnable>(this);
SocketReceiveThread.Reset(FRunnableThread::Create(SocketReceiveThreadRunnable.Get(), *FString::Printf(TEXT("IpNetDriver Receive Thread"), *NetDriverName.ToString())));
}
SetSocketAndLocalAddress(Resolver->GetFirstSocket());
bool bRecvMultiEnabled = CVarNetUseRecvMulti.GetValueOnAnyThread() != 0;
bool bRecvThreadEnabled = CVarNetIpNetDriverUseReceiveThread.GetValueOnAnyThread() != 0;
if (bRecvMultiEnabled && !bRecvThreadEnabled)
{
bool bSupportsRecvMulti = SocketSubsystem->IsSocketRecvMultiSupported();
if (bSupportsRecvMulti)