MCPcopy Create free account
hub / github.com/GarageGames/Torque2D / openConnectTo

Method openConnectTo

engine/source/platform/platformNet.cpp:737–858  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

735}
736
737NetSocket Net::openConnectTo(const char *addressString)
738{
739#ifdef TORQUE_ALLOW_JOURNALING
740 if (Game->isJournalReading())
741 {
742 U32 ret;
743 Game->journalRead(&ret);
744 return NetSocket::fromHandle(ret);
745 }
746#endif
747 NetAddress address;
748 NetSocket handleFd = NetSocket::INVALID;
749 Net::Error error = NoError;
750
751 error = Net::stringToAddress(addressString, &address, false);
752
753 if (error == NoError && address.type != NetAddress::IPAddress && address.type != NetAddress::IPV6Address)
754 {
755 error = Net::WrongProtocolType;
756 }
757
758 // Open socket
759 if (error == NoError || error == NeedHostLookup)
760 {
761 handleFd = openSocket();
762 }
763
764 // Attempt to connect or queue a lookup
765 if (error == NoError && address.type == NetAddress::IPAddress)
766 {
767 sockaddr_in ipAddr;
768 NetAddressToIPSocket(&address, &ipAddr);
769 SOCKET socketFd = PlatformNetState::smReservedSocketList.activate(handleFd, AF_INET, false, true);
770 if (socketFd != InvalidSocketHandle)
771 {
772 setBlocking(handleFd, false);
773 if (::connect(socketFd, (struct sockaddr *)&ipAddr, sizeof(ipAddr)) == -1)
774 {
775 Net::Error err = PlatformNetState::getLastError();
776 if (err != Net::WouldBlock)
777 {
778 Con::errorf("Error connecting to %s: %u",
779 addressString, err);
780 closeSocket(handleFd);
781 handleFd = NetSocket::INVALID;
782 }
783 }
784 }
785 else
786 {
787 PlatformNetState::smReservedSocketList.remove(handleFd);
788 handleFd = NetSocket::INVALID;
789 }
790
791 if (handleFd != NetSocket::INVALID)
792 {
793 // add this socket to our list of polled sockets
794 addPolledSocket(handleFd, socketFd, PolledSocket::ConnectionPending);

Callers

nothing calls this directly

Calls 14

getLastErrorFunction · 0.85
errorfFunction · 0.85
addPolledSocketFunction · 0.85
extractAddressPartsFunction · 0.85
isJournalReadingMethod · 0.80
journalReadMethod · 0.80
queueLookupMethod · 0.80
isJournalWritingMethod · 0.80
journalWriteMethod · 0.80
getHandleMethod · 0.80
NetAddressToIPSocketFunction · 0.70
NetAddressToIPSocket6Function · 0.70

Tested by

no test coverage detected