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