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

Method openPort

Engine/source/platform/platformNet.cpp:951–1091  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

949}
950
951bool Net::openPort(S32 port, bool doBind)
952{
953 if (PlatformNetState::udpSocket != NetSocket::INVALID)
954 {
955 closeSocket(PlatformNetState::udpSocket);
956 PlatformNetState::udpSocket = NetSocket::INVALID;
957 }
958 if (PlatformNetState::udp6Socket != NetSocket::INVALID)
959 {
960 closeSocket(PlatformNetState::udp6Socket);
961 PlatformNetState::udp6Socket = NetSocket::INVALID;
962 }
963
964 // Update prefs
965 Net::smMulticastEnabled = Con::getBoolVariable("pref::Net::Multicast6Enabled", true);
966 Net::smIpv4Enabled = Con::getBoolVariable("pref::Net::IPV4Enabled", true);
967 Net::smIpv6Enabled = Con::getBoolVariable("pref::Net::IPV6Enabled", false);
968
969 // we turn off VDP in non-release builds because VDP does not support broadcast packets
970 // which are required for LAN queries (PC->Xbox connectivity). The wire protocol still
971 // uses the VDP packet structure, though.
972 S32 protocol = PlatformNetState::getDefaultGameProtocol();
973
974 SOCKET socketFd = InvalidSocketHandle;
975 NetAddress address;
976 NetAddress listenAddress;
977 char listenAddressStr[256];
978
979 if (Net::smIpv4Enabled)
980 {
981 if (Net::getListenAddress(NetAddress::IPAddress, &address) == Net::NoError)
982 {
983 address.port = port;
984 socketFd = ::socket(AF_INET, SOCK_DGRAM, protocol);
985
986 if (socketFd != InvalidSocketHandle)
987 {
988 PlatformNetState::udpSocket = PlatformNetState::smReservedSocketList.reserve(socketFd);
989 Net::Error error = NoError;
990 if (doBind)
991 {
992 error = bindAddress(address, PlatformNetState::udpSocket, true);
993 }
994
995 if (error == NoError)
996 error = setBufferSize(PlatformNetState::udpSocket, 32768 * 8);
997
998#ifndef TORQUE_DISABLE_PC_CONNECTIVITY
999 if (error == NoError)
1000 error = setBroadcast(PlatformNetState::udpSocket, true);
1001#endif
1002
1003 if (error == NoError)
1004 error = setBlocking(PlatformNetState::udpSocket, false);
1005
1006 if (error == NoError)
1007 {
1008 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
errorfFunction · 0.85
getLastErrorFunction · 0.70
reserveMethod · 0.45

Tested by

no test coverage detected