E-MailRelay
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
GNet::Interfaces Class Reference

A class for getting a list of network interfaces and their addresses. More...

#include <ginterfaces.h>

+ Inheritance diagram for GNet::Interfaces:
+ Collaboration diagram for GNet::Interfaces:

Classes

struct  Item
 Used by GNet::Interfaces to describe an interface address binding. More...
 

Public Types

using const_iterator = std::vector< Item >::const_iterator
 
- Public Types inherited from GNet::EventHandler
enum class  Reason {
  failed , closed , down , reset ,
  abort , other
}
 

Public Member Functions

 Interfaces (EventState)
 Constructor resulting in an empty list. More...
 
 Interfaces (EventState, InterfacesHandler &)
 Constructor resulting in an empty list with an attached event handler. More...
 
 ~Interfaces () override
 Destructor.
 
void load ()
 Loads or reloads the list. More...
 
bool loaded () const
 Returns true if load()ed. More...
 
G::StringArray names (bool all=false) const
 Returns the interface names, optionally including interfaces that are not up. More...
 
const_iterator begin () const
 Returns a begin iterator. More...
 
const_iterator end () const
 Returns a one-off-the-end iterator. More...
 
std::vector< Addressaddresses (const std::string &name, unsigned int port, int af=AF_UNSPEC) const
 Returns addresses bound to the given interface. More...
 
std::size_t addresses (std::vector< Address > &out, const std::string &name, unsigned int port, int af=AF_UNSPEC) const
 An overload that appends to the given list and returns the number added. More...
 
 Interfaces (const Interfaces &)=delete
 
 Interfaces (Interfaces &&)=delete
 
Interfaces operator= (const Interfaces &)=delete
 
Interfaces operator= (Interfaces &&)=delete
 
- Public Member Functions inherited from GNet::EventHandler
 EventHandler ()
 Constructor.
 
virtual ~EventHandler ()
 Destructor. More...
 
virtual void readEvent ()
 Called for a read event. More...
 
virtual void writeEvent ()
 Called for a write event. More...
 
virtual void otherEvent (Reason)
 Called for a socket-exception event, or a socket-close event on windows. More...
 
void setDescriptor (Descriptor) noexcept
 File descriptor setter. Used by the event loop. More...
 
Descriptor descriptor () const noexcept
 File descriptor getter. Used by the event loop. More...
 
 EventHandler (const EventHandler &)=delete
 
 EventHandler (EventHandler &&)=delete
 
EventHandleroperator= (const EventHandler &)=delete
 
EventHandleroperator= (EventHandler &&)=delete
 
- Public Member Functions inherited from GNet::FutureEventHandler
virtual ~FutureEventHandler ()=default
 Destructor.
 
virtual void onFutureEvent ()=0
 Callback function that delivers the future event.
 

Static Public Member Functions

static bool supported ()
 Returns false if a stubbed-out implementation. More...
 
static bool active ()
 Returns true if the implementation can raise InterfacesHandler events. More...
 
- Static Public Member Functions inherited from GNet::EventHandler
static std::string str (Reason)
 Returns a printable description of the other-event reason. More...
 

Detailed Description

A class for getting a list of network interfaces and their addresses.

An InterfacesHandler interface can be supplied to the constructor in order to get dynamic updates.

Definition at line 47 of file ginterfaces.h.

Member Typedef Documentation

◆ const_iterator

using GNet::Interfaces::const_iterator = std::vector<Item>::const_iterator

Definition at line 64 of file ginterfaces.h.

Constructor & Destructor Documentation

◆ Interfaces() [1/2]

GNet::Interfaces::Interfaces ( EventState  es)
explicit

Constructor resulting in an empty list.

Use load() to initialise.

Definition at line 28 of file ginterfaces_common.cpp.

◆ Interfaces() [2/2]

GNet::Interfaces::Interfaces ( EventState  es,
InterfacesHandler handler 
)

Constructor resulting in an empty list with an attached event handler.

Use load() or addresses() to initialise the list and activate the event listener.

Definition at line 34 of file ginterfaces_common.cpp.

Member Function Documentation

◆ active()

bool GNet::Interfaces::active ( )
static

Returns true if the implementation can raise InterfacesHandler events.

Definition at line 44 of file ginterfaces_none.cpp.

◆ addresses() [1/2]

std::vector< GNet::Address > GNet::Interfaces::addresses ( const std::string &  name,
unsigned int  port,
int  af = AF_UNSPEC 
) const

Returns addresses bound to the given interface.

Does a lazy load().

Definition at line 65 of file ginterfaces_common.cpp.

◆ addresses() [2/2]

std::size_t GNet::Interfaces::addresses ( std::vector< Address > &  out,
const std::string &  name,
unsigned int  port,
int  af = AF_UNSPEC 
) const

An overload that appends to the given list and returns the number added.

Definition at line 73 of file ginterfaces_common.cpp.

◆ begin()

GNet::Interfaces::const_iterator GNet::Interfaces::begin ( ) const

Returns a begin iterator.

Definition at line 111 of file ginterfaces_common.cpp.

◆ end()

GNet::Interfaces::const_iterator GNet::Interfaces::end ( ) const

Returns a one-off-the-end iterator.

Definition at line 116 of file ginterfaces_common.cpp.

◆ load()

void GNet::Interfaces::load ( )

Loads or reloads the list.

Definition at line 43 of file ginterfaces_common.cpp.

◆ loaded()

bool GNet::Interfaces::loaded ( ) const

Returns true if load()ed.

Definition at line 59 of file ginterfaces_common.cpp.

◆ names()

G::StringArray GNet::Interfaces::names ( bool  all = false) const

Returns the interface names, optionally including interfaces that are not up.

Definition at line 97 of file ginterfaces_common.cpp.

◆ supported()

bool GNet::Interfaces::supported ( )
static

Returns false if a stubbed-out implementation.

Definition at line 53 of file ginterfaces_common.cpp.


The documentation for this class was generated from the following files: