From: Marcin Siodelski Date: Fri, 10 Jan 2014 14:45:44 +0000 (+0100) Subject: [3252] Use error handler macro for IfaceMgr::openSocket4. X-Git-Tag: bind10-1.2.0beta1-release~143^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7a2eaf0dd3a55c06b61ac24d32da592673014e9;p=thirdparty%2Fkea.git [3252] Use error handler macro for IfaceMgr::openSocket4. --- diff --git a/src/lib/dhcp/iface_mgr.cc b/src/lib/dhcp/iface_mgr.cc index dec183119f..0cd32482b3 100644 --- a/src/lib/dhcp/iface_mgr.cc +++ b/src/lib/dhcp/iface_mgr.cc @@ -396,7 +396,6 @@ IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast, continue; } - int sock = -1; // If selected interface is broadcast capable set appropriate // options on the socket so as it can receive and send broadcast // messages. @@ -406,22 +405,24 @@ IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast, // bind to INADDR_ANY address but we can do it only once. Thus, // if one socket has been bound we can't do it any further. if (!bind_to_device && bcast_num > 0) { - handleSocketConfigError("SO_BINDTODEVICE socket option is" - " not supported on this OS;" - " therefore, DHCP server can only" - " listen broadcast traffic on a" - " single interface", - error_handler); + ifacemgr_error(SocketConfigError, error_handler, + "SO_BINDTODEVICE socket option is" + " not supported on this OS;" + " therefore, DHCP server can only" + " listen broadcast traffic on a" + " single interface"); continue; } else { try { // We haven't open any broadcast sockets yet, so we can // open at least one more. - sock = openSocket(iface->getName(), *addr, port, - true, true); + openSocket(iface->getName(), *addr, port, true, true); } catch (const Exception& ex) { - handleSocketConfigError(ex.what(), error_handler); + ifacemgr_error(SocketConfigError, error_handler, + "failed to open socket on interface " + << iface->getName() << ", reason: " + << ex.what()); continue; } @@ -436,22 +437,17 @@ IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast, } else { try { // Not broadcast capable, do not set broadcast flags. - sock = openSocket(iface->getName(), *addr, port, - false, false); + openSocket(iface->getName(), *addr, port, false, false); } catch (const Exception& ex) { - handleSocketConfigError(ex.what(), error_handler); + ifacemgr_error(SocketConfigError, error_handler, + "failed to open socket on interface " + << iface->getName() << ", reason: " + << ex.what()); continue; } } - if (sock < 0) { - const char* errstr = strerror(errno); - handleSocketConfigError(std::string("failed to open IPv4 socket," - " reason:") + errstr, - error_handler); - } else { - ++count; - } + ++count; } } @@ -551,7 +547,7 @@ IfaceMgr::openSockets6(const uint16_t port, iface->delSocket(sock); ifacemgr_error(SocketConfigError, error_handler, "Failed to open multicast socket on" - " interface " << iface->getFullName() + " interface " << iface->getName() << ", reason: " << ex.what()); continue; } @@ -562,20 +558,6 @@ IfaceMgr::openSockets6(const uint16_t port, return (count > 0); } -void -IfaceMgr::handleSocketConfigError(const std::string& errmsg, - IfaceMgrErrorMsgCallback handler) { - // If error handler is installed, we don't want to throw an exception, but - // rather call this handler. - if (handler != NULL) { - handler(errmsg); - - } else { - isc_throw(SocketConfigError, errmsg); - - } -} - void IfaceMgr::printIfaces(std::ostream& out /*= std::cout*/) { for (IfaceCollection::const_iterator iface=ifaces_.begin(); diff --git a/src/lib/dhcp/iface_mgr.h b/src/lib/dhcp/iface_mgr.h index f7f0fb5391..2b5557bc7a 100644 --- a/src/lib/dhcp/iface_mgr.h +++ b/src/lib/dhcp/iface_mgr.h @@ -955,23 +955,6 @@ private: getLocalAddress(const isc::asiolink::IOAddress& remote_addr, const uint16_t port); - /// @brief Handles an error which occurs during configuration of a socket. - /// - /// If the handler callback is specified (non-NULL), this handler is - /// called and the specified error message is passed to it. If the - /// handler is not specified, the @c isc::dhcpSocketConfigError exception - /// is thrown with the specified message. - /// - /// This function should be called to handle errors which occur during - /// socket opening, binding or configuration (e.g. setting socket options - /// etc). - /// - /// @param errmsg An error message to be passed to a handlder function or - /// to the @c isc::dhcp::SocketConfigError exception. - /// @param handler An error handler function or NULL. - void handleSocketConfigError(const std::string& errmsg, - IfaceMgrErrorMsgCallback handler); - /// @brief Checks if there is at least one socket of the specified family /// open. ///