namespace isc {
namespace dhcp {
+extern const isc::log::MessageID DHCP_ADD_EXTERNAL_SOCKET = "DHCP_ADD_EXTERNAL_SOCKET";
+extern const isc::log::MessageID DHCP_DELETE_ALL_EXTERNAL_SOCKETS = "DHCP_DELETE_ALL_EXTERNAL_SOCKETS";
+extern const isc::log::MessageID DHCP_DELETE_EXTERNAL_SOCKET = "DHCP_DELETE_EXTERNAL_SOCKET";
} // namespace dhcp
} // namespace isc
namespace {
const char* values[] = {
+ "DHCP_ADD_EXTERNAL_SOCKET", "Attempted to register external socket %1 from different thread %2",
+ "DHCP_DELETE_ALL_EXTERNAL_SOCKETS", "Attempted to unregister external sockets from different thread %1",
+ "DHCP_DELETE_EXTERNAL_SOCKET", "Attempted to unregister external socket %1 from different thread %2",
NULL
};
$NAMESPACE isc::dhcp
+% DHCP_ADD_EXTERNAL_SOCKET Attempted to register external socket %1 from different thread %2
+This error message indicates that a different thread than the main thread has
+registered an external socket. This is a programming error and should be fixed.
+Only the main thread is allowed to perform operations on the external sockets.
+The file descritptor and the respective thread id are included in the message.
+
+% DHCP_DELETE_ALL_EXTERNAL_SOCKETS Attempted to unregister external sockets from different thread %1
+This error message indicates that a different thread than the main thread has
+deleted all external sockets. This is a programming error and should be fixed.
+Only the main thread is allowed to perform operations on the external sockets.
+The respective thread id is included in the message.
+
+% DHCP_DELETE_EXTERNAL_SOCKET Attempted to unregister external socket %1 from different thread %2
+This error message indicates that a different thread than the main thread has
+unregistered an external socket. This is a programming error and should be fixed.
+Only the main thread is allowed to perform operations on the external sockets.
+The file descritptor and the respective thread id are included in the message.
#include <asiolink/udp_endpoint.h>
#include <dhcp/dhcp4.h>
#include <dhcp/dhcp6.h>
+#include <dhcp/dhcp_log.h>
+#include <dhcp/dhcp_messages.h>
#include <dhcp/iface_mgr.h>
#include <dhcp/iface_mgr_error_handler.h>
#include <dhcp/pkt_filter_inet.h>
isc_throw(BadValue, "Attempted to install callback for invalid socket "
<< socketfd);
}
- // @todo: remove comment when exclusively allow external sockets actions on main thread.
- //if (std::this_thread::get_id() != id_) {
- // isc_throw(InvalidOperation, "Attempted to register external socket from different thread "
- // << std::this_thread::get_id());
- //}
+ if (std::this_thread::get_id() != id_) {
+ LOG_ERROR(dhcp_logger, DHCP_ADD_EXTERNAL_SOCKET)
+ .arg(socketfd)
+ .arg(std::this_thread::get_id());
+ }
std::lock_guard<std::mutex> lock(callbacks_mutex_);
for (SocketCallbackInfo& s : callbacks_) {
// There's such a socket description there already.
void
IfaceMgr::deleteExternalSocketInternal(int socketfd) {
- // @todo: remove comment when exclusively allow external sockets actions on main thread.
- //if (std::this_thread::get_id() != id_) {
- // isc_throw(InvalidOperation, "Attempted to unregister external socket from different thread "
- // << std::this_thread::get_id());
- //}
+ if (std::this_thread::get_id() != id_) {
+ LOG_ERROR(dhcp_logger, DHCP_DELETE_EXTERNAL_SOCKET)
+ .arg(socketfd)
+ .arg(std::this_thread::get_id());
+ }
for (SocketCallbackInfoContainer::iterator s = callbacks_.begin();
s != callbacks_.end(); ++s) {
if (s->socket_ == socketfd) {
void
IfaceMgr::deleteAllExternalSockets() {
- // @todo: remove comment when exclusively allow external sockets actions on main thread.
- //if (std::this_thread::get_id() != id_) {
- // isc_throw(InvalidOperation, "Attempted to unregister external sockets from different thread "
- // << std::this_thread::get_id());
- //}
+ if (std::this_thread::get_id() != id_) {
+ LOG_ERROR(dhcp_logger, DHCP_DELETE_ALL_EXTERNAL_SOCKETS)
+ .arg(std::this_thread::get_id());
+ }
std::lock_guard<std::mutex> lock(callbacks_mutex_);
callbacks_.clear();
}