#include <config.h>
#include <netconf/fd_watcher.h>
+#include <netconf/netconf_log.h>
#include <boost/function.hpp>
#include <sys/select.h>
// sr_fd_event_process is C code.
sr_fd_change_t* change_set = 0;
size_t cnt = 0;
- // ignore return because we don't know what to do on error.
- sr_fd_event_process(fd, SR_FD_INPUT_READY, &change_set, &cnt);
+ int ret = sr_fd_event_process(fd, SR_FD_INPUT_READY,
+ &change_set, &cnt);
+ if (ret != SR_ERR_OK) {
+ // We don't know what to do on error...
+ // which BTW should never happen.
+ LOG_WARN(netconf_logger, NETCONF_FD_WATCHER_ERROR)
+ .arg(string(sr_strerror(ret)));
+ }
for (size_t i = 0; i < cnt; ++i) {
if (change_set[i].action == SR_FD_START_WATCHING) {
watcher->addFd(change_set[i].fd,
/// The alternative is to leave sysrepo to create its own thread to
/// handle suscriptions with an independent and likely incompatible
/// event loop and of course locking issues.
+/// Reference:
+/// http://www.sysrepo.org/static/doc/html/subscribtions.html#callbacks
+///
/// To simplify callbacks this class is implemented as a singleton.
class FdWatcher : public boost::noncopyable {
public:
int init(const asiolink::IOServicePtr& io_service);
/// @brief Clear the fd watcher.
+ ///
+ /// Uses the terminate watch socket to wake up and terminate the thread
+ /// if it exists.
void clear();
/// @brief Add a file descriptor to watch.
///
+ /// The file descriptor is given by sysrepo for reading and/or writing.
+ ///
/// @param fd The file descriptor to add.
/// @param reading Boolean flag: true to watch for reading.
/// @param writing Boolean flag: true to watch for writing.
/// @brief Delete a file descriptor to watch.
///
+ /// The file descriptor is given by sysrepo for reading and/or writing.
+ ///
/// @param fd The file descriptor to delete.
/// @param reading Boolean flag: true to watch for reading.
/// @param writing Boolean flag: true to watch for writing.
/// @brief Post handler.
///
/// The thread posts this handler on the IO service when there
- /// should be a file descriptor available for IO.
+ /// should be a file descriptor available for IO. This handler
+ /// will be called by the process run loop in the main thread.
static void postHandler();
/// @brief Thread body.
///
/// The thread body: select() on file descriptors, when one is
- /// available posts fdAvailable and returns.
+ /// available posts fdAvailable and returns. As the file descriptors
+ /// include the terminate watch socket the thread can be triggered
+ /// from Kea too (vs only by sysrepo).
static void threadBody();
/// @brief Shared pointer to the IOService object where to post callbacks.
/// @brief Terminate watch socket.
///
- /// Used to wake up the thread.
+ /// Used to wake up and terminate the thread from Kea.
isc::util::WatchSocket watch_terminate_;
/// @brief Polling thread.
This is a fatal error message issued when the Netconf application
encounters an unrecoverable error from within the event loop.
+% NETCONF_FD_WATCHER_ERROR sysrepo file descriptor watcher event process returned an error: %1
+This is a warning message when the sysrepo event process routine of the file
+descriptor watcher returns an error. This error is displayed and ignored.
+
% NETCONF_RUN_EXIT application is exiting the event loop
This is a debug message issued when the Netconf application exits its
event loop.