mirror of
https://github.com/matrix-construct/construct
synced 2024-10-03 22:28:52 +02:00
ircd::net: Improve remote construction; hostport/ipport related.
This commit is contained in:
parent
b801993309
commit
76e16e4d80
4 changed files with 18 additions and 21 deletions
|
@ -26,6 +26,8 @@ namespace ircd::net
|
|||
{
|
||||
struct hostport;
|
||||
|
||||
uint16_t port(const hostport &);
|
||||
|
||||
const auto &host(const hostport &);
|
||||
auto &host(hostport &);
|
||||
|
||||
|
@ -83,3 +85,11 @@ ircd::net::host(const hostport &hp)
|
|||
{
|
||||
return hp.host;
|
||||
}
|
||||
|
||||
inline uint16_t
|
||||
ircd::net::port(const hostport &hp)
|
||||
{
|
||||
return hp.portnum? hp.portnum:
|
||||
hp.port? lex_cast<uint16_t>(hp.port):
|
||||
0;
|
||||
}
|
||||
|
|
|
@ -96,6 +96,7 @@ ircd::net::ipport::ipport(const uint32_t &ip,
|
|||
const uint16_t &p)
|
||||
{
|
||||
std::get<TYPE>(*this) = false;
|
||||
host6(*this) = 0;
|
||||
host4(*this) = ip;
|
||||
port(*this) = p;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,11 @@ struct ircd::net::remote
|
|||
:ipport{ipp}
|
||||
{}
|
||||
|
||||
remote(const hostport &hp);
|
||||
explicit remote(const hostport &hostport)
|
||||
:ipport{uint32_t(0), net::port(hostport)}
|
||||
,hostname{net::host(hostport)}
|
||||
{}
|
||||
|
||||
remote() = default;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &, const remote &);
|
||||
|
|
22
ircd/net.cc
22
ircd/net.cc
|
@ -2254,22 +2254,6 @@ ircd::net::string(const mutable_buffer &buf,
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// remote
|
||||
//
|
||||
|
||||
ircd::net::remote::remote(const hostport &hostport)
|
||||
:ipport
|
||||
{
|
||||
resolve(hostport)
|
||||
}
|
||||
,hostname
|
||||
{
|
||||
hostport.host
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// net/ipport.h
|
||||
|
@ -2421,9 +2405,7 @@ ircd::net::string(const mutable_buffer &buf,
|
|||
{
|
||||
fmt::sprintf
|
||||
{
|
||||
buf, "%s:%s",
|
||||
hp.host,
|
||||
hp.portnum? lex_cast(hp.portnum) : hp.port
|
||||
buf, "%s:%u", host(hp), port(hp)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2444,7 +2426,7 @@ ircd::net::string(const ip::address &addr)
|
|||
std::string
|
||||
ircd::net::string(const ip::tcp::endpoint &ep)
|
||||
{
|
||||
std::string ret(256, char{});
|
||||
std::string ret(128, char{});
|
||||
const auto addr{string(net::addr(ep))};
|
||||
const auto data{const_cast<char *>(ret.data())};
|
||||
ret.resize(snprintf(data, ret.size(), "%s:%u", addr.c_str(), port(ep)));
|
||||
|
|
Loading…
Reference in a new issue