1
0
Fork 0

Codechange: use std::string_view for NetworkAddress

pull/14115/head
Rubidium 2025-04-26 11:47:00 +02:00 committed by rubidium42
parent e1db09a41f
commit 30f381acee
2 changed files with 7 additions and 7 deletions

View File

@ -78,7 +78,7 @@ void NetworkAddress::SetPort(uint16_t port)
* @param with_family Whether to add the familty to the address (e.g. IPv4).
* @return The format string for the address.
*/
static const char *GetAddressFormatString(uint16_t family, bool with_family)
static std::string_view GetAddressFormatString(uint16_t family, bool with_family)
{
switch (family) {
case AF_INET: return with_family ? "{}:{} (IPv4)" : "{}:{}";
@ -296,8 +296,8 @@ static SOCKET ListenLoopProc(addrinfo *runp)
SOCKET sock = socket(runp->ai_family, runp->ai_socktype, runp->ai_protocol);
if (sock == INVALID_SOCKET) {
const char *type = NetworkAddress::SocketTypeAsString(runp->ai_socktype);
const char *family = NetworkAddress::AddressFamilyAsString(runp->ai_family);
std::string_view type = NetworkAddress::SocketTypeAsString(runp->ai_socktype);
std::string_view family = NetworkAddress::AddressFamilyAsString(runp->ai_family);
Debug(net, 0, "Could not create {} {} socket: {}", type, family, NetworkError::GetLast().AsString());
return INVALID_SOCKET;
}
@ -365,7 +365,7 @@ void NetworkAddress::Listen(int socktype, SocketList *sockets)
* @return the string representation
* @note only works for SOCK_STREAM and SOCK_DGRAM
*/
/* static */ const char *NetworkAddress::SocketTypeAsString(int socktype)
/* static */ std::string_view NetworkAddress::SocketTypeAsString(int socktype)
{
switch (socktype) {
case SOCK_STREAM: return "tcp";
@ -380,7 +380,7 @@ void NetworkAddress::Listen(int socktype, SocketList *sockets)
* @return the string representation
* @note only works for AF_INET, AF_INET6 and AF_UNSPEC
*/
/* static */ const char *NetworkAddress::AddressFamilyAsString(int family)
/* static */ std::string_view NetworkAddress::AddressFamilyAsString(int family)
{
switch (family) {
case AF_UNSPEC: return "either IPv4 or IPv6";

View File

@ -162,8 +162,8 @@ public:
void Listen(int socktype, SocketList *sockets);
static const char *SocketTypeAsString(int socktype);
static const char *AddressFamilyAsString(int family);
static std::string_view SocketTypeAsString(int socktype);
static std::string_view AddressFamilyAsString(int family);
static NetworkAddress GetPeerAddress(SOCKET sock);
static NetworkAddress GetSockAddress(SOCKET sock);
static const std::string GetPeerName(SOCKET sock);