diff --git a/Include/Aurora/IO/Net/INetSrvSockets.hpp b/Include/Aurora/IO/Net/INetSrvSockets.hpp index 94df1374..8b50440e 100644 --- a/Include/Aurora/IO/Net/INetSrvSockets.hpp +++ b/Include/Aurora/IO/Net/INetSrvSockets.hpp @@ -13,18 +13,18 @@ namespace Aurora::IO::Net struct NetSocketConnectByHost { - AuOptionalEx netHostname; - AuOptionalEx uPort; - AuOptionalEx protocol; + NetHostname netHostname; + AuUInt16 uPort; + ETransportProtocol protocol; }; struct NetSocketConnect { // connect by protocol, address:port - AuOptionalEx endpoint; + AuOptionalEx byEndpoint; // or connect by [string/ip family, ip address], port - NetSocketConnectByHost byHost; + AuOptionalEx byHost; // AuSPtr pDriver; @@ -34,8 +34,7 @@ namespace Aurora::IO::Net struct NetSocketConnectMany { ETransportProtocol protocol {}; - AuList ips; - AuUInt16 uPort {}; + AuList> ips; AuSPtr pDriver; AuUInt32 uMaxConnectTimeMs {}; }; diff --git a/Source/IO/Net/AuNetSocket.NT.cpp b/Source/IO/Net/AuNetSocket.NT.cpp index fb297d29..d7cf9497 100644 --- a/Source/IO/Net/AuNetSocket.NT.cpp +++ b/Source/IO/Net/AuNetSocket.NT.cpp @@ -83,7 +83,7 @@ namespace Aurora::IO::Net if (this->bHasRemoteMany_ && this->connectMany_.ips.size()) { - this->remoteEndpoint_ = this->connectMany_.ips[0]; + this->remoteEndpoint_ = this->connectMany_.ips[0].first; if (this->remoteEndpoint_.transportProtocol == ETransportProtocol::kEnumInvalid) { this->remoteEndpoint_.transportProtocol = this->connectMany_.protocol; diff --git a/Source/IO/Net/AuNetSocket.Unix.cpp b/Source/IO/Net/AuNetSocket.Unix.cpp index e7601e54..1a0e46fd 100644 --- a/Source/IO/Net/AuNetSocket.Unix.cpp +++ b/Source/IO/Net/AuNetSocket.Unix.cpp @@ -81,7 +81,7 @@ namespace Aurora::IO::Net if (this->bHasRemoteMany_ && this->connectMany_.ips.size()) { - this->remoteEndpoint_ = this->connectMany_.ips[0]; + this->remoteEndpoint_ = this->connectMany_.ips[0].first; if (this->remoteEndpoint_.transportProtocol == ETransportProtocol::kEnumInvalid) { this->remoteEndpoint_.transportProtocol = this->connectMany_.protocol; diff --git a/Source/IO/Net/AuNetSocket.cpp b/Source/IO/Net/AuNetSocket.cpp index 39ccab1f..4a17779c 100644 --- a/Source/IO/Net/AuNetSocket.cpp +++ b/Source/IO/Net/AuNetSocket.cpp @@ -101,7 +101,6 @@ namespace Aurora::IO::Net this->resolveLater = host.hostname; this->remoteEndpoint_.uPort = uPort; this->remoteEndpoint_.transportProtocol = eProtocol; - this->connectMany_.uPort = uPort; this->connectMany_.protocol = eProtocol; } @@ -173,12 +172,17 @@ namespace Aurora::IO::Net { pThat->bResolving_ = false; - pThat->connectMany_.uPort = pThat->remoteEndpoint_.uPort; - pThat->connectMany_.ips.insert(pThat->connectMany_.ips.end(), ips->begin(), ips->end()); + if (pThat->remoteEndpoint_.transportProtocol == ETransportProtocol::kEnumInvalid) { pThat->remoteEndpoint_.transportProtocol = this->connectMany_.protocol; } + + for (auto &ip : *ips) + { + pThat->connectMany_.ips.push_back(AuMakePair(ip, pThat->remoteEndpoint_.uPort)); + } + pThat->bHasRemoteMany_ = true; pThat->RenewSocket(); pThat->ConnectNext(); @@ -198,12 +202,12 @@ namespace Aurora::IO::Net return false; } - auto topLevelEntry = this->connectMany_.ips[0]; + auto [topLevelEntryIp, topLevelEntryPort] = this->connectMany_.ips[0]; this->connectMany_.ips.erase(this->connectMany_.ips.begin()); NetEndpoint endpoint; - endpoint.uPort = this->connectMany_.uPort; - endpoint.ip = topLevelEntry; + endpoint.uPort = topLevelEntryPort; + endpoint.ip = topLevelEntryIp; endpoint.transportProtocol = this->connectMany_.protocol; return this->Connect(endpoint); } diff --git a/Source/IO/Net/AuNetSrvSockets.cpp b/Source/IO/Net/AuNetSrvSockets.cpp index a6e3d566..1559556a 100644 --- a/Source/IO/Net/AuNetSrvSockets.cpp +++ b/Source/IO/Net/AuNetSrvSockets.cpp @@ -25,6 +25,8 @@ namespace Aurora::IO::Net AuSPtr NetSrvSockets::Connect(const NetSocketConnect &netConnect) { + AuSPtr pSocket; + auto pWorker = this->pParent_->TryScheduleEx(); if (!pWorker) { @@ -32,11 +34,9 @@ namespace Aurora::IO::Net return {}; } - AuSPtr pSocket; - - if (netConnect.endpoint) + if (netConnect.byEndpoint) { - if (netConnect.endpoint.Value().transportProtocol != ETransportProtocol::eProtocolTCP) + if (netConnect.byEndpoint.Value().transportProtocol != ETransportProtocol::eProtocolTCP) { SysPushErrorNet("Invalid transport protocol. Hint: Use ConnectManyEx for UDP."); return {}; @@ -45,33 +45,23 @@ namespace Aurora::IO::Net pSocket = AuMakeShared(this->pParent_, pWorker.get(), netConnect.pDriver, - netConnect.endpoint.value()); + netConnect.byEndpoint.value()); } else { - if (!netConnect.byHost.netHostname) + auto &connectOptions = netConnect.byHost.Value(); + + if (connectOptions.netHostname.type != EHostnameType::eHostByDns) { SysPushErrorArg("Missing hostname or endpoint"); return {}; } - if (!netConnect.byHost.protocol) - { - SysPushErrorArg("Missing protocol"); - return {}; - } - - if (!netConnect.byHost.uPort) - { - SysPushErrorArg("Missing port"); - return {}; - } - pSocket = AuMakeShared(this->pParent_, pWorker.get(), netConnect.pDriver, - AuMakePair(netConnect.byHost.netHostname.value(), netConnect.byHost.uPort.value()), - netConnect.byHost.protocol.value()); + AuMakePair(connectOptions.netHostname, connectOptions.uPort), + connectOptions.protocol); } if (!pSocket)