libkea_dhcp_ddns_la_SOURCES += ncr_io.cc ncr_io.h
libkea_dhcp_ddns_la_SOURCES += ncr_msg.cc ncr_msg.h
libkea_dhcp_ddns_la_SOURCES += ncr_udp.cc ncr_udp.h
-libkea_dhcp_ddns_la_SOURCES += watch_socket.cc watch_socket.h
nodist_libkea_dhcp_ddns_la_SOURCES = dhcp_ddns_messages.cc dhcp_ddns_messages.h
send_callback_->setDataSource(server_endpoint_);
- watch_socket_.reset(new WatchSocket());
+ watch_socket_.reset(new util::WatchSocket());
}
void
-// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
#include <asiolink/udp_endpoint.h>
#include <asiolink/udp_socket.h>
#include <dhcp_ddns/ncr_io.h>
-#include <dhcp_ddns/watch_socket.h>
#include <util/buffer.h>
+#include <util/watch_socket.h>
#include <boost/shared_array.hpp>
bool reuse_address_;
/// @brief Pointer to WatchSocket instance supplying the "select-fd".
- WatchSocketPtr watch_socket_;
+ util::WatchSocketPtr watch_socket_;
};
} // namespace isc::dhcp_ddns
libdhcp_ddns_unittests_SOURCES += ncr_unittests.cc
libdhcp_ddns_unittests_SOURCES += ncr_udp_unittests.cc
libdhcp_ddns_unittests_SOURCES += test_utils.cc test_utils.h
-libdhcp_ddns_unittests_SOURCES += watch_socket_unittests.cc
libdhcp_ddns_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
int select_fd = sender.getSelectFd();
// Verify select_fd is valid and currently shows no ready to read.
- ASSERT_NE(dhcp_ddns::WatchSocket::SOCKET_NOT_VALID, select_fd);
+ ASSERT_NE(util::WatchSocket::SOCKET_NOT_VALID, select_fd);
// Make sure select_fd does evaluates to not ready via select and
// that ioReady() method agrees.
close(sender.getSelectFd());
// Send should fail as we interferred by closing the select-fd.
- ASSERT_THROW(sender.sendRequest(ncr), WatchSocketError);
+ ASSERT_THROW(sender.sendRequest(ncr), util::WatchSocketError);
// Verify we didn't invoke the handler.
EXPECT_EQ(0, ncr_handler.pass_count_);
// Interfere by reading part of the marker from the select-fd.
uint32_t buf = 0;
ASSERT_EQ((read (select_fd, &buf, 1)), 1);
- ASSERT_NE(WatchSocket::MARKER, buf);
+ ASSERT_NE(util::WatchSocket::MARKER, buf);
// Run one handler. This should execute the send completion handler
// after sending the message. Duing completion handling clearing the
D2ClientMgr::D2ClientMgr() : d2_client_config_(new D2ClientConfig()),
name_change_sender_(), private_io_service_(),
- registered_select_fd_(dhcp_ddns::WatchSocket::SOCKET_NOT_VALID) {
+ registered_select_fd_(util::WatchSocket::SOCKET_NOT_VALID) {
// Default constructor initializes with a disabled configuration.
}
void
D2ClientMgr::stopSender() {
/// Unregister sender's select-fd.
- if (registered_select_fd_ != dhcp_ddns::WatchSocket::SOCKET_NOT_VALID) {
+ if (registered_select_fd_ != util::WatchSocket::SOCKET_NOT_VALID) {
IfaceMgr::instance().deleteExternalSocket(registered_select_fd_);
- registered_select_fd_ = dhcp_ddns::WatchSocket::SOCKET_NOT_VALID;
+ registered_select_fd_ = util::WatchSocket::SOCKET_NOT_VALID;
}
// If its not null, call stop.
/// @brief Fetches the select-fd that is currently registered.
///
/// @return The currently registered select-fd or
- /// dhcp_ddns::WatchSocket::SOCKET_NOT_VALID.
+ /// util::WatchSocket::SOCKET_NOT_VALID.
///
/// @note This is only exposed for testing purposes.
int getRegisteredSelectFd();
libkea_util_la_SOURCES += signal_set.cc signal_set.h
libkea_util_la_SOURCES += stopwatch.cc stopwatch.h
libkea_util_la_SOURCES += stopwatch_impl.cc stopwatch_impl.h
+libkea_util_la_SOURCES += watch_socket.cc watch_socket.h
libkea_util_la_SOURCES += encode/base16_from_binary.h
libkea_util_la_SOURCES += encode/base32hex.h encode/base64.h
libkea_util_la_SOURCES += encode/base32hex_from_binary.h
run_unittests_SOURCES += range_utilities_unittest.cc
run_unittests_SOURCES += signal_set_unittest.cc
run_unittests_SOURCES += stopwatch_unittest.cc
+run_unittests_SOURCES += watch_socket_unittests.cc
+
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <config.h>
-#include <dhcp_ddns/watch_socket.h>
-#include <test_utils.h>
+#include <util/watch_socket.h>
#include <gtest/gtest.h>
using namespace std;
using namespace isc;
-using namespace isc::dhcp_ddns;
+using namespace isc::util;
namespace {
+/// @brief Returns the result of select() given an fd to check for read status.
+///
+/// @param fd_to_check The file descriptor to test
+///
+/// @return Returns less than one on an error, 0 if the fd is not ready to
+/// read, > 0 if it is ready to read.
+int selectCheck(int fd_to_check) {
+ fd_set read_fds;
+ int maxfd = 0;
+
+ FD_ZERO(&read_fds);
+
+ // Add this socket to listening set
+ FD_SET(fd_to_check, &read_fds);
+ maxfd = fd_to_check;
+
+ struct timeval select_timeout;
+ select_timeout.tv_sec = 0;
+ select_timeout.tv_usec = 0;
+
+ return (select(maxfd + 1, &read_fds, NULL, NULL, &select_timeout));
+}
+
/// @brief Tests the basic functionality of WatchSocket.
TEST(WatchSocketTest, basics) {
WatchSocketPtr watch;
-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
/// @file watch_socket.cc
-#include <dhcp_ddns/dhcp_ddns_log.h>
-#include <dhcp_ddns/watch_socket.h>
+//#include <dhcp_ddns/dhcp_ddns_log.h>
+#include <util/watch_socket.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/select.h>
namespace isc {
-namespace dhcp_ddns {
+namespace util {
const int WatchSocket::SOCKET_NOT_VALID;
// destructors that throw.
if (source_ != SOCKET_NOT_VALID) {
if (close(source_)) {
- const char* errstr = strerror(errno);
+/* const char* errstr = strerror(errno);
LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_WATCH_SOURCE_CLOSE_ERROR)
- .arg(errstr);
+ .arg(errstr); */
}
source_ = SOCKET_NOT_VALID;
if (sink_ != SOCKET_NOT_VALID) {
if (close(sink_)) {
- const char* errstr = strerror(errno);
+/* const char* errstr = strerror(errno);
LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_WATCH_SINK_CLOSE_ERROR)
- .arg(errstr);
+ .arg(errstr); */
}
sink_ = SOCKET_NOT_VALID;
return (sink_);
}
-} // namespace isc::dhcp_ddns
+} // namespace isc::util
} // namespace isc
-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
#include <stdint.h>
namespace isc {
-namespace dhcp_ddns {
+namespace util {
/// @brief Exception thrown if an error occurs during IO source open.
class WatchSocketError : public isc::Exception {
/// @brief Defines a smart pointer to an instance of a WatchSocket.
typedef boost::shared_ptr<WatchSocket> WatchSocketPtr;
-} // namespace isc::dhcp_ddns
+} // namespace isc::util
} // namespace isc
#endif