TraversalClient: Make use of std::string_view with ConnectToClient()

Same behavior, but allows the use of non-allocating string types with
the interface.
This commit is contained in:
Lioncash 2021-01-19 14:26:04 -05:00
parent cb4ca7837a
commit b425250a7b
2 changed files with 4 additions and 3 deletions

View File

@ -73,7 +73,7 @@ static ENetAddress MakeENetAddress(const TraversalInetAddress& address)
return eaddr;
}
void TraversalClient::ConnectToClient(const std::string& host)
void TraversalClient::ConnectToClient(std::string_view host)
{
if (host.size() > sizeof(TraversalHostId))
{
@ -82,7 +82,7 @@ void TraversalClient::ConnectToClient(const std::string& host)
}
TraversalPacket packet = {};
packet.type = TraversalPacketType::ConnectPlease;
memcpy(packet.connectPlease.hostId.data(), host.c_str(), host.size());
memcpy(packet.connectPlease.hostId.data(), host.data(), host.size());
m_ConnectRequestId = SendTraversalPacket(packet);
m_PendingConnect = true;
}

View File

@ -6,6 +6,7 @@
#include <list>
#include <memory>
#include <string>
#include <string_view>
#include <enet/enet.h>
@ -51,7 +52,7 @@ public:
bool IsConnected() const { return m_State == State::Connected; }
void Reset();
void ConnectToClient(const std::string& host);
void ConnectToClient(std::string_view host);
void ReconnectToServer();
void Update();
void HandleResends();