MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / CreateSocket

Method CreateSocket

src/openrct2/network/Socket.cpp:828–859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

826
827 private:
828 SOCKET CreateSocket() const
829 {
830 auto sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
831 if (sock == INVALID_SOCKET)
832 {
833 throw SocketException("Unable to create socket.");
834 }
835
836 // Enable send and receiving of broadcast messages
837 if (!SetOption(sock, SOL_SOCKET, SO_BROADCAST, true))
838 {
839 LOG_VERBOSE("setsockopt(socket, SO_BROADCAST) failed: %d", LAST_SOCKET_ERROR());
840 }
841
842 // Turn off IPV6_V6ONLY so we can accept both v4 and v6 connections
843 if (!SetOption(sock, IPPROTO_IPV6, IPV6_V6ONLY, false))
844 {
845 LOG_VERBOSE("setsockopt(socket, IPV6_V6ONLY) failed: %d", LAST_SOCKET_ERROR());
846 }
847
848 if (!SetOption(sock, SOL_SOCKET, SO_REUSEADDR, true))
849 {
850 LOG_VERBOSE("setsockopt(socket, SO_REUSEADDR) failed: %d", LAST_SOCKET_ERROR());
851 }
852
853 if (!SetNonBlocking(sock, true))
854 {
855 throw SocketException("Failed to set non-blocking mode.");
856 }
857
858 return sock;
859 }
860
861 void CloseSocket()
862 {

Callers

nothing calls this directly

Calls 1

SocketExceptionClass · 0.85

Tested by

no test coverage detected