Make Muninn OBS receiver reload-safe
This commit is contained in:
parent
60cbe45624
commit
caf92d9dee
6 changed files with 135 additions and 15 deletions
32
native/obs_stem_source/muninn_udp_socket.h
Normal file
32
native/obs_stem_source/muninn_udp_socket.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
|
||||
namespace muninn_udp_socket {
|
||||
|
||||
inline SOCKET create(bool exclusive_listener = false)
|
||||
{
|
||||
const SOCKET socket = WSASocketW(
|
||||
AF_INET,
|
||||
SOCK_DGRAM,
|
||||
IPPROTO_UDP,
|
||||
nullptr,
|
||||
0,
|
||||
WSA_FLAG_NO_HANDLE_INHERIT);
|
||||
if (socket == INVALID_SOCKET) {
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
if (exclusive_listener) {
|
||||
const BOOL exclusive = TRUE;
|
||||
if (setsockopt(socket, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
|
||||
reinterpret_cast<const char *>(&exclusive), sizeof(exclusive)) != 0) {
|
||||
closesocket(socket);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
|
||||
} // namespace muninn_udp_socket
|
||||
#endif
|
||||
Loading…
Reference in a new issue