30 for(
const auto & listener : listener_list )
32 int fd = G::is_windows() ? -1 : parseFd( listener ) ;
35 m_fds.push_back( fd ) ;
37 else if( isAddress(listener,port) )
39 m_fixed.push_back( address(listener,port) ) ;
43 std::size_t n = if_.
addresses( m_dynamic , basename(listener) , port , af(listener) ) ;
44 if( n == 0U && isBad(listener) )
46 (n?m_used:m_empties).push_back( listener ) ;
50 addWildcards( port ) ;
53int GNet::Listeners::af(
const std::string & s )
63std::string GNet::Listeners::basename(
const std::string & s )
67 s.substr( 0U , s.length()-5U ) :
71int GNet::Listeners::parseFd(
const std::string & listener )
73 if( listener.size() > 3U && listener.find(
"fd#") == 0U &&
G::Str::isUInt(listener.substr(3U)) )
76 if( fd < 0 )
throw InvalidFd( listener ) ;
82void GNet::Listeners::addWildcards(
unsigned int port )
85 m_fixed.emplace_back( Address::Family::ipv4 , port ) ;
88 m_fixed.emplace_back( Address::Family::ipv6 , port ) ;
91bool GNet::Listeners::isAddress(
const std::string & s ,
unsigned int port )
96GNet::Address GNet::Listeners::address(
const std::string & s ,
unsigned int port )
101bool GNet::Listeners::empty()
const
103 return m_fds.empty() && m_fixed.empty() && m_dynamic.empty() ;
121bool GNet::Listeners::isBad(
const std::string & s )
127 return s.empty() || ( s.find(
'/') != std::string::npos && s.find(
"/dev/") != 0U ) ;
132 return !m_bad.empty() ;
142 return !m_empties.empty() ;
147 return std::string(m_empties.size()==1U?
" \"":
"s \"").append(
G::Str::join(
"\", \"",m_empties)).append(1U,
'"') ;
The GNet::Address class encapsulates a TCP/UDP transport address.
static bool validStrings(std::string_view ip, std::string_view port_string, std::string *reason=nullptr)
Returns true if the combined network-address string and port string is valid.
static Address parse(std::string_view display_string)
Factory function for any address family.
A class for getting a list of network interfaces and their addresses.
std::vector< Address > addresses(const std::string &name, unsigned int port, int af=AF_UNSPEC) const
Returns addresses bound to the given interface.
static bool active()
Returns true if the implementation can raise InterfacesHandler events.
bool defunct() const
Returns true if no inputs and static.
bool hasEmpties() const
Returns true if some named interfaces have no addresses.
std::string logEmpties() const
Returns a log-line snippet for hasEmpties().
const std::vector< int > & fds() const
Exposes the list of fd inputs.
Listeners(const Interfaces &, const G::StringArray &listener_spec_list, unsigned int port)
Constructor.
bool idle() const
Returns true if no inputs but some interfaces might come up.
bool noUpdates() const
Returns true if some inputs are interfaces but GNet::Interfaces is not active().
const std::vector< Address > & fixed() const
Exposes the list of address inputs.
const std::vector< Address > & dynamic() const
Exposes the list of interface addresses.
std::string badName() const
Returns the first invalid input.
bool hasBad() const
Returns true if one or more inputs are invalid.
static bool supports(Address::Family)
Returns true if stream sockets can be created with the given the address family.
static bool isUInt(std::string_view s) noexcept
Returns true if the string can be converted into an unsigned integer without throwing an exception.
static bool tailMatch(std::string_view in, std::string_view ending) noexcept
Returns true if the string has the given ending (or the given ending is empty).
static int toInt(std::string_view s)
Converts string 's' to an int.
static std::string join(std::string_view sep, const StringArray &strings)
Concatenates an array of strings with separators.
static std::string fromUInt(unsigned int ui)
Converts unsigned int 'ui' to a string.
std::vector< std::string > StringArray
A std::vector of std::strings.