mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 15:10:46 +03:00
std.socket: Refactor all *Address.toString implementations to a single base one
This commit is contained in:
parent
ad2d04668a
commit
65c7f6b80f
1 changed files with 16 additions and 26 deletions
42
std/socket.d
42
std/socket.d
|
@ -1002,9 +1002,6 @@ abstract class Address
|
||||||
/// Returns actual size of underlying $(D sockaddr) structure.
|
/// Returns actual size of underlying $(D sockaddr) structure.
|
||||||
int nameLen() const;
|
int nameLen() const;
|
||||||
|
|
||||||
/// Human readable string representing this address.
|
|
||||||
override string toString() const;
|
|
||||||
|
|
||||||
/// Family of this address.
|
/// Family of this address.
|
||||||
AddressFamily addressFamily() const
|
AddressFamily addressFamily() const
|
||||||
{
|
{
|
||||||
|
@ -1109,6 +1106,22 @@ abstract class Address
|
||||||
{
|
{
|
||||||
return toServiceString(false);
|
return toServiceString(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Human readable string representing this address.
|
||||||
|
override string toString() const
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string host = toAddrString();
|
||||||
|
string port = toPortString();
|
||||||
|
if (host.indexOf(':') >= 0)
|
||||||
|
return "[" ~ host ~ "]:" ~ port;
|
||||||
|
else
|
||||||
|
return host ~ ":" ~ port;
|
||||||
|
}
|
||||||
|
catch (SocketException)
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1137,11 +1150,6 @@ public:
|
||||||
return sa.sizeof;
|
return sa.sizeof;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override string toString() const
|
|
||||||
{
|
|
||||||
return "Unknown";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1185,12 +1193,6 @@ public:
|
||||||
{
|
{
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override string toString() const
|
|
||||||
{
|
|
||||||
return "Unknown";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1326,12 +1328,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Human readable string representing the IPv4 address and port in the form $(I a.b.c.d:e).
|
|
||||||
override string toString() const
|
|
||||||
{
|
|
||||||
return toAddrString() ~ ":" ~ toPortString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse an IPv4 address string in the dotted-decimal form $(I a.b.c.d)
|
* Parse an IPv4 address string in the dotted-decimal form $(I a.b.c.d)
|
||||||
* and return the number.
|
* and return the number.
|
||||||
|
@ -1486,12 +1482,6 @@ public:
|
||||||
sin6.sin6_port = htons(port);
|
sin6.sin6_port = htons(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Human readable string representing the IPv6 address and port.
|
|
||||||
override string toString() const
|
|
||||||
{
|
|
||||||
return "[" ~ toAddrString() ~ "]:" ~ toPortString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse an IPv6 address string as described in RFC 2373, and return the
|
* Parse an IPv6 address string as described in RFC 2373, and return the
|
||||||
* address.
|
* address.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue