Skip to content

Commit 542ded5

Browse files
committed
imporvements for mac and steam socks
1 parent e774fee commit 542ded5

4 files changed

Lines changed: 22 additions & 14 deletions

File tree

sources/libcore/concurrent/concurrent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,10 +778,12 @@ namespace cage
778778
__except (EXCEPTION_EXECUTE_HANDLER)
779779
{}
780780
#pragma warning(pop)
781-
#endif
782781

783-
#ifdef CAGE_SYSTEM_LINUX
782+
#elif defined(CAGE_SYSTEM_LINUX)
784783
prctl(PR_SET_NAME, name.c_str(), 0, 0, 0);
784+
785+
#elif defined(CAGE_SYSTEM_MAC)
786+
pthread_setname_np(name.c_str());
785787
#endif
786788
}
787789

sources/libcore/errors/crashHandlerMac.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ extern "C"
146146
kern_return_t catch_mach_exception_raise(mach_port_t exception_port, mach_port_t thread, mach_port_t task, exception_type_t exception, exception_data_t code, mach_msg_type_number_t code_count)
147147
{
148148
using namespace cage;
149-
thread_suspend(thread);
150149
privat::crashHandlerSafeWrite(Stringizer() + "mach exception: " + excToStr(exception) + " (" + exception + ")\n");
151150
if (code_count > 0)
152151
privat::crashHandlerSafeWrite(Stringizer() + "code[0]: " + code[0] + "\n");
@@ -155,7 +154,7 @@ extern "C"
155154
writeThreadInfo(thread);
156155
const auto regs = writeRegisters(thread);
157156
printStack(regs.first, regs.second, thread);
158-
thread_resume(thread);
157+
privat::crashHandlerSafeWrite("mach exception handler done\n");
159158
// let the system continue propagating the exception
160159
return KERN_FAILURE;
161160
}

sources/libcore/errors/crashHandlerSignals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace cage
4242
void crashHandlerPrintStack()
4343
{
4444
// backtrace (best-effort; not strictly async-signal-safe)
45-
static constexpr int MaxFrames = 256;
45+
static constexpr int MaxFrames = 100;
4646
void *frames[MaxFrames];
4747
int n = backtrace(frames, MaxFrames);
4848
if (n <= 0)

sources/libcore/network/steam.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,12 @@ namespace cage
135135
{
136136
InitializerSockets()
137137
{
138+
SteamNetworkingSockets_SetServiceThreadInitCallback(+[]() { currentThreadName("steam sockets"); });
139+
SteamNetworkingErrMsg msg;
140+
if (!GameNetworkingSockets_Init(nullptr, msg))
138141
{
139-
SteamNetworkingSockets_SetServiceThreadInitCallback(+[]() { currentThreadName("steam sockets"); });
140-
SteamNetworkingErrMsg msg;
141-
if (!GameNetworkingSockets_Init(nullptr, msg))
142-
{
143-
CAGE_LOG_THROW(msg);
144-
CAGE_THROW_ERROR(Exception, "failed to initialize steam sockets networking library");
145-
}
142+
CAGE_LOG_THROW(msg);
143+
CAGE_THROW_ERROR(Exception, "failed to initialize steam sockets networking library");
146144
}
147145
}
148146
~InitializerSockets() { GameNetworkingSockets_Kill(); }
@@ -156,6 +154,11 @@ namespace cage
156154
sockets = SteamNetworkingSockets();
157155
utils = SteamNetworkingUtils();
158156
}
157+
if (!sockets || !utils)
158+
{
159+
CAGE_LOG(SeverityEnum::Note, "steamsocks", Stringizer() + "sockets: " + sockets + ", utils: " + utils);
160+
CAGE_THROW_ERROR(Exception, "steam sockets api pointer is invalid");
161+
}
159162
CAGE_ASSERT(sockets);
160163
CAGE_ASSERT(utils);
161164

@@ -164,8 +167,12 @@ namespace cage
164167
InitializerConfiguration()
165168
{
166169
utils->SetDebugOutputFunction((ESteamNetworkingSocketsDebugOutputType)(sint32)confDebugLogLevel, &debugOutputHandler);
167-
utils->SetGlobalConfigValueFloat(k_ESteamNetworkingConfig_FakePacketLoss_Send, confSimulatedPacketLoss * 100);
168-
utils->SetGlobalConfigValueInt32(k_ESteamNetworkingConfig_FakePacketLag_Send, (sint32)confSimulatedPacketDelay);
170+
const float packetLoss = confSimulatedPacketLoss * 100;
171+
const sint32 packetDelay = (sint32)confSimulatedPacketDelay;
172+
if (packetLoss != 0 || packetDelay != 0)
173+
CAGE_LOG(SeverityEnum::Warning, "steamsocks", Stringizer() + "setting packet loss: " + packetLoss + " %, packet delay: " + packetDelay + " ms");
174+
utils->SetGlobalConfigValueFloat(k_ESteamNetworkingConfig_FakePacketLoss_Send, packetLoss);
175+
utils->SetGlobalConfigValueInt32(k_ESteamNetworkingConfig_FakePacketLag_Send, packetDelay);
169176
utils->SetGlobalConfigValueInt32(k_ESteamNetworkingConfig_IPLocalHost_AllowWithoutAuth, 1);
170177
}
171178
};

0 commit comments

Comments
 (0)