MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / openPort

Method openPort

Engine/source/platform/platformNet.cpp:903–1043  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

901}
902
903bool Net::openPort(S32 port, bool doBind)
904{
905 if (PlatformNetState::udpSocket != NetSocket::INVALID)
906 {
907 closeSocket(PlatformNetState::udpSocket);
908 PlatformNetState::udpSocket = NetSocket::INVALID;
909 }
910 if (PlatformNetState::udp6Socket != NetSocket::INVALID)
911 {
912 closeSocket(PlatformNetState::udp6Socket);
913 PlatformNetState::udp6Socket = NetSocket::INVALID;
914 }
915
916 // Update prefs
917 Net::smMulticastEnabled = Con::getBoolVariable("pref::Net::Multicast6Enabled", true);
918 Net::smIpv4Enabled = Con::getBoolVariable("pref::Net::IPV4Enabled", true);
919 Net::smIpv6Enabled = Con::getBoolVariable("pref::Net::IPV6Enabled", false);
920
921 // we turn off VDP in non-release builds because VDP does not support broadcast packets
922 // which are required for LAN queries (PC->Xbox connectivity). The wire protocol still
923 // uses the VDP packet structure, though.
924 S32 protocol = PlatformNetState::getDefaultGameProtocol();
925
926 SOCKET socketFd = InvalidSocketHandle;
927 NetAddress address;
928 NetAddress listenAddress;
929 char listenAddressStr[256];
930
931 if (Net::smIpv4Enabled)
932 {
933 if (Net::getListenAddress(NetAddress::IPAddress, &address) == Net::NoError)
934 {
935 address.port = port;
936 socketFd = ::socket(AF_INET, SOCK_DGRAM, protocol);
937
938 if (socketFd != InvalidSocketHandle)
939 {
940 PlatformNetState::udpSocket = PlatformNetState::smReservedSocketList.reserve(socketFd);
941 Net::Error error = NoError;
942 if (doBind)
943 {
944 error = bindAddress(address, PlatformNetState::udpSocket, true);
945 }
946
947 if (error == NoError)
948 error = setBufferSize(PlatformNetState::udpSocket, 32768 * 8);
949
950#ifndef TORQUE_DISABLE_PC_CONNECTIVITY
951 if (error == NoError)
952 error = setBroadcast(PlatformNetState::udpSocket, true);
953#endif
954
955 if (error == NoError)
956 error = setBlocking(PlatformNetState::udpSocket, false);
957
958 if (error == NoError)
959 {
960 error = PlatformNetState::getSocketAddress(socketFd, AF_INET, &listenAddress);

Callers

nothing calls this directly

Calls 7

getBoolVariableFunction · 0.85
getDefaultGameProtocolFunction · 0.85
getSocketAddressFunction · 0.85
printfFunction · 0.85
getLastErrorFunction · 0.85
errorfFunction · 0.50
reserveMethod · 0.45

Tested by

no test coverage detected