parent
ded605910f
commit
3c8442d8ce
@ -18,23 +18,44 @@ namespace Aurora::IO::Net
|
||||
ETransportProtocol protocol;
|
||||
};
|
||||
|
||||
struct NetSocketConnect
|
||||
struct NetSocketConnectBase
|
||||
{
|
||||
inline NetSocketConnectBase() = default;
|
||||
|
||||
inline NetSocketConnectBase(IPAddress ip, AuUInt16 uPort) : byEndpoint(NetEndpoint { ip, uPort })
|
||||
{ }
|
||||
|
||||
inline NetSocketConnectBase(NetSocketConnectByHost byHost) : byHost(byHost)
|
||||
{ }
|
||||
|
||||
// connect by protocol, address:port
|
||||
AuOptionalEx<NetEndpoint> byEndpoint;
|
||||
|
||||
// or connect by [string/ip family, ip address], port
|
||||
AuOptionalEx<NetSocketConnectByHost> byHost;
|
||||
};
|
||||
|
||||
struct NetSocketConnect : NetSocketConnectBase
|
||||
{
|
||||
inline NetSocketConnect() :
|
||||
NetSocketConnectBase()
|
||||
{ }
|
||||
|
||||
inline NetSocketConnect(IPAddress ip, AuUInt16 uPort) :
|
||||
NetSocketConnectBase(ip, uPort)
|
||||
{ }
|
||||
|
||||
inline NetSocketConnect(NetSocketConnectByHost byHost) :
|
||||
NetSocketConnectBase(byHost)
|
||||
{ }
|
||||
|
||||
//
|
||||
AuSPtr<ISocketDriver> pDriver;
|
||||
AuUInt32 uMaxConnectTimeMs {};
|
||||
};
|
||||
|
||||
struct NetSocketConnectMany
|
||||
{
|
||||
ETransportProtocol protocol {};
|
||||
AuList<AuPair<IPAddress, AuUInt16>> ips;
|
||||
AuList<NetSocketConnectBase> names;
|
||||
AuSPtr<ISocketDriver> pDriver;
|
||||
AuUInt32 uMaxConnectTimeMs {};
|
||||
};
|
||||
|
@ -81,12 +81,17 @@ namespace Aurora::IO::Net
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->bHasRemoteMany_ && this->connectMany_.ips.size())
|
||||
if (this->bHasRemoteMany_ && this->connectMany_.names.size())
|
||||
{
|
||||
this->remoteEndpoint_ = this->connectMany_.ips[0].first;
|
||||
if (this->remoteEndpoint_.transportProtocol == ETransportProtocol::kEnumInvalid)
|
||||
if (this->connectMany_.names[0].byEndpoint)
|
||||
{
|
||||
this->remoteEndpoint_.transportProtocol = this->connectMany_.protocol;
|
||||
this->remoteEndpoint_ = this->connectMany_.names[0].byEndpoint.value();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto val = this->connectMany_.names[0].byHost.value();
|
||||
this->remoteEndpoint_.ip = val.netHostname.address;
|
||||
this->remoteEndpoint_.transportProtocol = val.protocol;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,10 +81,15 @@ namespace Aurora::IO::Net
|
||||
|
||||
if (this->bHasRemoteMany_ && this->connectMany_.ips.size())
|
||||
{
|
||||
this->remoteEndpoint_ = this->connectMany_.ips[0].first;
|
||||
if (this->remoteEndpoint_.transportProtocol == ETransportProtocol::kEnumInvalid)
|
||||
if (this->connectMany_.names[0].byEndpoint)
|
||||
{
|
||||
this->remoteEndpoint_.transportProtocol = this->connectMany_.protocol;
|
||||
this->remoteEndpoint_ = this->connectMany_.names[0].byEndpoint.value();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto val = this->connectMany_.names[0].byHost.value();
|
||||
this->remoteEndpoint_.ip = val.netHostname.address;
|
||||
this->remoteEndpoint_.transportProtocol = val.protocol;
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,7 +137,6 @@ namespace Aurora::IO::Net
|
||||
|
||||
void Socket::FinishConstructAsync()
|
||||
{
|
||||
|
||||
if (this->resolveLater.size() || this->bResolving_)
|
||||
{
|
||||
if (!this->TryStartResolve())
|
||||
@ -147,7 +151,6 @@ namespace Aurora::IO::Net
|
||||
RenewSocket();
|
||||
}
|
||||
|
||||
|
||||
bool Socket::PrepareConnectOperations()
|
||||
{
|
||||
return this->MakeNonblocking();
|
||||
|
@ -101,7 +101,6 @@ namespace Aurora::IO::Net
|
||||
this->resolveLater = host.hostname;
|
||||
this->remoteEndpoint_.uPort = uPort;
|
||||
this->remoteEndpoint_.transportProtocol = eProtocol;
|
||||
this->connectMany_.protocol = eProtocol;
|
||||
}
|
||||
|
||||
this->osHandleOwner_ = AuIO::IOHandleShared();
|
||||
@ -167,22 +166,19 @@ namespace Aurora::IO::Net
|
||||
|
||||
auto pResolver = this->pInterface_->GetResolveService()->SimpleAllResolve(address,
|
||||
AuMakeSharedThrow<AuAsync::PromiseCallbackFunctional<AuList<AuNet::IPAddress>,
|
||||
AuNet::NetError>>(
|
||||
AuNet::NetError>>(
|
||||
[=](const AuSPtr<AuList<AuNet::IPAddress>> &ips)
|
||||
{
|
||||
|
||||
pThat->bResolving_ = false;
|
||||
|
||||
if (pThat->remoteEndpoint_.transportProtocol == ETransportProtocol::kEnumInvalid)
|
||||
{
|
||||
pThat->remoteEndpoint_.transportProtocol = this->connectMany_.protocol;
|
||||
}
|
||||
|
||||
AuList<NetSocketConnectBase> names;
|
||||
for (auto &ip : *ips)
|
||||
{
|
||||
pThat->connectMany_.ips.push_back(AuMakePair(ip, pThat->remoteEndpoint_.uPort));
|
||||
names.push_back(NetSocketConnectBase(ip, pThat->remoteEndpoint_.uPort));
|
||||
}
|
||||
|
||||
pThat->connectMany_.names = names;
|
||||
|
||||
pThat->bHasRemoteMany_ = true;
|
||||
pThat->RenewSocket();
|
||||
pThat->ConnectNext();
|
||||
@ -197,18 +193,30 @@ namespace Aurora::IO::Net
|
||||
|
||||
bool SocketBase::ConnectNext()
|
||||
{
|
||||
if (this->connectMany_.ips.empty())
|
||||
if (this->connectMany_.names.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto [topLevelEntryIp, topLevelEntryPort] = this->connectMany_.ips[0];
|
||||
this->connectMany_.ips.erase(this->connectMany_.ips.begin());
|
||||
auto base = this->connectMany_.names[0];
|
||||
this->connectMany_.names.erase(this->connectMany_.names.begin());
|
||||
|
||||
NetEndpoint endpoint;
|
||||
endpoint.uPort = topLevelEntryPort;
|
||||
endpoint.ip = topLevelEntryIp;
|
||||
endpoint.transportProtocol = this->connectMany_.protocol;
|
||||
if (base.byEndpoint)
|
||||
{
|
||||
endpoint = base.byEndpoint.value();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto val = base.byHost.value();
|
||||
if (val.netHostname.type == EHostnameType::eHostByDns)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
endpoint.uPort = val.uPort;
|
||||
endpoint.ip = val.netHostname.address;
|
||||
endpoint.transportProtocol = val.protocol;
|
||||
}
|
||||
return this->Connect(endpoint);
|
||||
}
|
||||
|
||||
|
@ -99,11 +99,7 @@ namespace Aurora::IO::Net
|
||||
|
||||
AuSPtr<ISocket> NetSrvSockets::ConnectMany(const NetSocketConnectMany &netConnectMany)
|
||||
{
|
||||
if (netConnectMany.protocol != ETransportProtocol::eProtocolTCP)
|
||||
{
|
||||
SysPushErrorNet("Invalid transport protocol. Hint: Use ConnectManyEx for UDP.");
|
||||
return {};
|
||||
}
|
||||
// TODO: restore no udp check
|
||||
|
||||
auto pWorker = this->pParent_->TryScheduleEx();
|
||||
if (!pWorker)
|
||||
|
Loading…
Reference in New Issue
Block a user