Kea  2.3.4-git
iface_mgr_error_handler.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define IFACEMGR_ERROR(ex_type, handler, iface, stream)
 A macro which handles an error in IfaceMgr. More...
 

Macro Definition Documentation

◆ IFACEMGR_ERROR

#define IFACEMGR_ERROR (   ex_type,
  handler,
  iface,
  stream 
)
Value:
{ \
std::ostringstream ieoss__; \
ieoss__ << stream; \
std::string const error(ieoss__.str()); \
if (iface) { \
iface->addError(error); \
} \
if (handler) { \
handler(error); \
} else { \
isc_throw(ex_type, error); \
} \
} \

A macro which handles an error in IfaceMgr.

There are certain cases when IfaceMgr may hit an error which shouldn't result in interruption of the function processing. A typical case is the function which opens sockets on available interfaces for a DHCP server. If this function fails to open a socket on a specific interface (for example, there is another socket already open on this interface and bound to the same address and port), it is desired that the server logs a warning but will try to open sockets on other interfaces. In order to log an error, the IfaceMgr will use the error handler function provided by the server and pass an error string to it. When the handler function returns, the IfaceMgr will proceed to open other sockets. It is allowed that the error handler function is not installed (is NULL). In these cases it is expected that the exception is thrown instead. A possible solution would be to enclose this conditional behavior in a function. However, despite the hate for macros, the macro seems to be a bit better solution in this case as it allows to conveniently pass an error string in a stream (not as a string).

Parameters
ex_typeException to be thrown if error_handler is NULL.
handlerError handler function to be called or NULL to indicate that exception should be thrown instead.
ifacePointer to the interface for which the error is logged. Can be null.
streamstream object holding an error string.

Definition at line 34 of file iface_mgr_error_handler.h.

Referenced by isc::dhcp::IfaceMgr::openSockets4(), and isc::dhcp::IfaceMgr::openSockets6().