E-MailRelay

glisteners.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file glisteners.h
19///
20
21#ifndef G_LISTENERS_H
22#define G_LISTENERS_H
23
24#include "gdef.h"
25#include "ginterfaces.h"
26#include "gaddress.h"
27#include "gstringarray.h"
28#include "gexception.h"
29#include <vector>
30#include <string>
31
32 namespace GNet
33{
34 class Listeners ;
35}
36
37//| \class GNet::Listeners
38/// Represents a set of listening inputs which can be file-descriptor,
39/// interface or network address.
40///
41 class GNet::Listeners
42{
43 public:
44 G_EXCEPTION( InvalidFd , tx("invalid listening file descriptor number") )
45
46 Listeners( const Interfaces & , const G::StringArray & listener_spec_list , unsigned int port ) ;
47 ///< Constructor. The specification strings can be like "fd#3"
48 ///< for a file descriptor, "127.0.0.1" for a fixed address,
49 ///< or "ppp0-ipv4" for an interface. If the specification
50 ///< list is empty then the two fixed wildcard addresses
51 ///< are added.
52
53 bool defunct() const ;
54 ///< Returns true if no inputs and static.
55
56 bool idle() const ;
57 ///< Returns true if no inputs but some interfaces might come up.
58
59 bool hasBad() const ;
60 ///< Returns true if one or more inputs are invalid.
61
62 std::string badName() const ;
63 ///< Returns the first invalid input.
64
65 bool hasEmpties() const ;
66 ///< Returns true if some named interfaces have no addresses.
67
68 std::string logEmpties() const ;
69 ///< Returns a log-line snippet for hasEmpties().
70
71 bool noUpdates() const ;
72 ///< Returns true if some inputs are interfaces but
73 ///< GNet::Interfaces is not active().
74
75 const std::vector<int> & fds() const ;
76 ///< Exposes the list of fd inputs.
77
78 const std::vector<Address> & fixed() const ;
79 ///< Exposes the list of address inputs.
80
81 const std::vector<Address> & dynamic() const ;
82 ///< Exposes the list of interface addresses.
83
84 private:
85 bool empty() const ;
86 void addWildcards( unsigned int ) ;
87 static int parseFd( const std::string & ) ;
88 static bool isAddress( const std::string & , unsigned int ) ;
89 static Address address( const std::string & , unsigned int ) ;
90 static int af( const std::string & ) ;
91 static std::string basename( const std::string & ) ;
92 static bool isBad( const std::string & ) ;
93
94 private:
95 std::string m_bad ;
96 G::StringArray m_empties ;
97 G::StringArray m_used ;
98 std::vector<Address> m_fixed ;
99 std::vector<Address> m_dynamic ;
100 std::vector<int> m_fds ;
101} ;
102
103#endif
GNet::Address
The GNet::Address class encapsulates a TCP/UDP transport address.
Definition: gaddress.h:63
GNet::Interfaces
A class for getting a list of network interfaces and their addresses.
Definition: ginterfaces.h:48
GNet::Listeners
Represents a set of listening inputs which can be file-descriptor, interface or network address.
Definition: glisteners.h:42
GNet::Listeners::defunct
bool defunct() const
Returns true if no inputs and static.
Definition: glisteners.cpp:106
GNet::Listeners::hasEmpties
bool hasEmpties() const
Returns true if some named interfaces have no addresses.
Definition: glisteners.cpp:140
GNet::Listeners::logEmpties
std::string logEmpties() const
Returns a log-line snippet for hasEmpties().
Definition: glisteners.cpp:145
GNet::Listeners::fds
const std::vector< int > & fds() const
Exposes the list of fd inputs.
Definition: glisteners.cpp:150
GNet::Listeners::Listeners
Listeners(const Interfaces &, const G::StringArray &listener_spec_list, unsigned int port)
Constructor.
Definition: glisteners.cpp:27
GNet::Listeners::idle
bool idle() const
Returns true if no inputs but some interfaces might come up.
Definition: glisteners.cpp:111
GNet::Listeners::noUpdates
bool noUpdates() const
Returns true if some inputs are interfaces but GNet::Interfaces is not active().
Definition: glisteners.cpp:116
GNet::Listeners::fixed
const std::vector< Address > & fixed() const
Exposes the list of address inputs.
Definition: glisteners.cpp:155
GNet::Listeners::dynamic
const std::vector< Address > & dynamic() const
Exposes the list of interface addresses.
Definition: glisteners.cpp:160
GNet::Listeners::badName
std::string badName() const
Returns the first invalid input.
Definition: glisteners.cpp:135
GNet::Listeners::hasBad
bool hasBad() const
Returns true if one or more inputs are invalid.
Definition: glisteners.cpp:130
gaddress.h
gexception.h
ginterfaces.h
gstringarray.h
GNet
Network classes.
Definition: gdef.h:1243
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstringarray.h:30
G::tx
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().
Definition: ggettext.h:84